From c21f0592327647ef31180bd10695de31a0674af8 Mon Sep 17 00:00:00 2001 From: ForeverSc Date: Wed, 14 Aug 2024 01:26:09 +0800 Subject: [PATCH] docs: update 2.0 readme and example --- README.md | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++-- README_CN.md | 92 +++++++++++++++++++++++++++++++++++++++++++++++++-- index.html | 20 +++++++++++ 3 files changed, 201 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0191958..07aac03 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,93 @@ Simultaneously retrieves packet data on all streams at a certain time point and Parameters: - `time`: Required, in seconds. +```typescript +getMediaInfo(): Promise // 2.0 New +``` +Get the media information of a file, the output is referenced from `ffprobe` +```json +{ + "format_name": "mov,mp4,m4a,3gp,3g2,mj2", + "duration": 10.026667, + "bit_rate": "629116", + "start_time": 0, + "nb_streams": 4, + "streams": [ + { + "id": 1, + "index": 0, + "codec_type": 0, + "codec_type_string": "video", + "codec_name": "h264", + "codec_string": "avc1.4d400c", + "profile": "", + "pix_fmt": "", + "level": -99, + "width": 320, + "height": 176, + "channels": 0, + "sample_rate": 0, + "sample_fmt": "", + "bit_rate": "300570", + "extradata_size": 41, + "extradata": Uint8Array, + "r_frame_rate": "25/1", + "avg_frame_rate": "25/1", + "sample_aspect_ratio": "N/A", + "display_aspect_ratio": "N/A", + "start_time": 0, + "duration": 10, + "rotation": 0, + "nb_frames": "250", + "tags": { + "creation_time": "2012-03-13T08:58:06.000000Z", + "language": "und", + "vendor_id": "[0][0][0][0]", + "encoder": "JVT/AVC Coding" + } + }, + { + "id": 2, + "index": 1, + "codec_type": 1, + "codec_type_string": "audio", + "codec_name": "aac", + "codec_string": "mp4a.40.2", + "profile": "", + "pix_fmt": "", + "level": -99, + "width": 0, + "height": 0, + "channels": 2, + "sample_rate": 48000, + "sample_fmt": "", + "bit_rate": "160545", + "extradata_size": 2, + "extradata": Uint8Array, + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "sample_aspect_ratio": "N/A", + "display_aspect_ratio": "N/A", + "start_time": 0, + "duration": 10.026666666666666, + "rotation": 0, + "nb_frames": "470", + "tags": { + "creation_time": "2012-03-13T08:58:06.000000Z", + "language": "und", + "vendor_id": "[0][0][0][0]" + } + } + ] +} +``` + +```typescript +setLogLevel(level: AVLogLevel) // 2.0 New +``` +Parameters: +- `level`: Required, output log level, see `AVLogLevel` for details. + ```typescript destroy(): void ``` @@ -168,8 +255,10 @@ Destroys the instance and releases the worker. ## Custom Demuxer Currently, two versions of the demuxer are provided by default to support different formats: -- `dist/wasm-files/ffmpeg.js`: Full version (gzip: 941 kB), larger in size, supports mov, mp4, m4a, 3gp, 3g2, mj2, avi, flv, matroska, webm, m4v, mpeg, asf -- `dist/wasm-files/ffmpeg-mini.js`: Minimalist version (gzip: 115 kB), smaller in size, only supports mov, mp4, m4a, 3gp, 3g2, matroska, webm, m4v +- `dist/wasm-files/ffmpeg.js`: Full version (gzip: 996 kB), larger in size, supports mov, mp4, m4a, 3gp, 3g2, mj2, avi, flv, matroska, webm, m4v, mpeg, asf +- `dist/wasm-files/ffmpeg-mini.js`: Minimalist version (gzip: 456 kB), smaller in size, only supports mov, mp4, m4a, 3gp, 3g2, matroska, webm, m4v +> If you want to use a smaller size version, you can use version 1.0 of web-demuxer, the lite version is only 115KB +> Version 1.0 is written in C, focuses on WebCodecs, and is small in size, while version 2.0 uses C++ Embind, which provides richer media information output, is easier to maintain, and is large in size You can also implement a demuxer for specific formats through custom configuration: diff --git a/README_CN.md b/README_CN.md index cb98848..85a064b 100644 --- a/README_CN.md +++ b/README_CN.md @@ -162,6 +162,92 @@ getAVPackets(time: number): Promise 参数: - `time`: 必填,单位为s +```typescript +getMediaInfo(): Promise // 2.0新增 +``` +获取文件的媒体信息, 输出结果参考自`ffprobe` +```json +{ + "format_name": "mov,mp4,m4a,3gp,3g2,mj2", + "duration": 10.026667, + "bit_rate": "629116", + "start_time": 0, + "nb_streams": 4, + "streams": [ + { + "id": 1, + "index": 0, + "codec_type": 0, + "codec_type_string": "video", + "codec_name": "h264", + "codec_string": "avc1.4d400c", + "profile": "", + "pix_fmt": "", + "level": -99, + "width": 320, + "height": 176, + "channels": 0, + "sample_rate": 0, + "sample_fmt": "", + "bit_rate": "300570", + "extradata_size": 41, + "extradata": Uint8Array, + "r_frame_rate": "25/1", + "avg_frame_rate": "25/1", + "sample_aspect_ratio": "N/A", + "display_aspect_ratio": "N/A", + "start_time": 0, + "duration": 10, + "rotation": 0, + "nb_frames": "250", + "tags": { + "creation_time": "2012-03-13T08:58:06.000000Z", + "language": "und", + "vendor_id": "[0][0][0][0]", + "encoder": "JVT/AVC Coding" + } + }, + { + "id": 2, + "index": 1, + "codec_type": 1, + "codec_type_string": "audio", + "codec_name": "aac", + "codec_string": "mp4a.40.2", + "profile": "", + "pix_fmt": "", + "level": -99, + "width": 0, + "height": 0, + "channels": 2, + "sample_rate": 48000, + "sample_fmt": "", + "bit_rate": "160545", + "extradata_size": 2, + "extradata": Uint8Array, + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "sample_aspect_ratio": "N/A", + "display_aspect_ratio": "N/A", + "start_time": 0, + "duration": 10.026666666666666, + "rotation": 0, + "nb_frames": "470", + "tags": { + "creation_time": "2012-03-13T08:58:06.000000Z", + "language": "und", + "vendor_id": "[0][0][0][0]" + } + } + ] +} +``` +```typescript +setLogLevel(level: AVLogLevel) // 2.0新增 +``` +参数: +- `level`: 必填,输出日志等级, 详见`AVLogLevel` + ```typescript destroy(): void ``` @@ -169,8 +255,10 @@ destroy(): void ## 自定义Demuxer 目前默认提供两个版本的demuxer, 用于支持不同的格式: -- `dist/wasm-files/ffmpeg.js`: 完整版(gzip: 941 kB), 体积较大,支持mov,mp4,m4a,3gp,3g2,mj2,avi,flv,matroska,webm,m4v,mpegi,asf -- `dist/wasm-files/ffmpeg-mini.js`: 精简版本(gzip: 115 kB),体积小,仅支持mov,mp4,m4a,3gp,3g2,matroska,webm,m4v +- `dist/wasm-files/ffmpeg.js`: 完整版(gzip: 996 kB), 体积较大,支持mov,mp4,m4a,3gp,3g2,mj2,avi,flv,matroska,webm,m4v,mpegi,asf +- `dist/wasm-files/ffmpeg-mini.js`: 精简版本(gzip: 456 kB),体积小,仅支持mov,mp4,m4a,3gp,3g2,matroska,webm,m4v +> 如果你想使用体积更小的版本,可以使用1.0版本的web-demuxer,精简版本仅115KB +> 1.0版本使用C编写,聚焦WebCodecs,体积小,2.0版本使用C++ Embind,提供了更丰富的媒体信息输出,更易维护,体积大 你也可以通过自定义配置,实现指定格式的demxuer: diff --git a/index.html b/index.html index 31c0877..dff4626 100644 --- a/index.html +++ b/index.html @@ -23,6 +23,7 @@

Web-Demuxer

@@ -88,6 +89,18 @@

Play Video

+
+
+

Get Media Info

+

Select a video file and get media info, open devtools to see console output

+
+ +
+ + +
+
+

Get All Video Packets

@@ -209,6 +222,13 @@

Get All Video Packets

console.log('all video packets:', await getAllPackets(file)); }); + document.getElementById('example-get-media-info-btn').addEventListener('click', async () => { + const file = document.getElementById('example-get-media-info-file').files[0]; + await demuxer.load(file); + const mediaInfo = await demuxer.getMediaInfo(); + console.log('media info: ', mediaInfo); + }); + function wait(time) { return new Promise((resolve) => { setTimeout(resolve, time)