编码 mp4 视频以支持搜索

安卓开发

我的 Android 应用程序使用 MediaCodec 和 MediaMuxer 创建 MP4。我使用 MediaPlayer 播放视频。在播放视频时,无法使用 Android 的 MediaPlayer 寻找视频中的任何位置。更具体地说,seekTo 函数将不起作用。使用其他应用程序播放视频和搜索有点粗略。有些应用程序似乎可以工作,而其他应用程序则不能。

我已经用我在相机上录制的视频以及我在互联网上找到的各种视频替换了我的 mp4,但它们都没有问题。库存相机应用程序可以生成 MP4 并让您搜索的事实清楚地表明编解码器的设置方式存在问题。这让我相信问题很可能出在用于创建视频的格式设置中。我尝试修改了许多设置,但没有成功,包括配置文件(同时使用基线和主要)、配置文件级别、I 帧间隔 (GOP) 以及比特率和视频大小。我还确保每帧的呈现时间与帧速率完全匹配。这是我为不支持搜索的视频和支持搜索的视频(相机视频)获得的信息。

一个简短的测试文件可以在这里下载。如果您在 QuickTime 或 VLC 中播放,则搜索有效:

https://drive.google.com/file/d/15QiDPYdPd_tVQTkqXuP0v2L7eKoMbWQo/view?usp=sharing

不支持搜索的视频:

**General**
Complete name : test.mp4
Format :    MPEG-4
Format profile :    Base Media
File size : 9.46 MiB
Duration :  19 s 488 ms
Overall bit rate :  4 071 kb/s
Encoded date :  UTC 2021-07-05 12:32:22
Tagged date :   UTC 2021-07-05 12:32:22
com_android_version :   11
    
**Video**
ID :    2
Format :    AVC
Format/Info :   Advanced Video Codec
Format profile :    Baseline
Format level :  5
Format settings, CABAC :    No
Format settings, Reference frames : 1 frame
Format settings, GOP :  M=1, N=30
Codec ID :  avc1
Duration :  17 s 900 ms
Source duration :   17 s 900 ms
Bit rate :  4 289 kb/s
Width : 1 440 pixels
Height :    2 614 pixels
Display aspect ratio :  0.551
Frame rate mode :   Constant
Frame rate :    30.000 FPS
Standard :  NTSC
Color space :   YUV
Chroma subsampling :    4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) :    0.038
Stream size :   9.15 MiB (97%)
Source stream size :    9.15 MiB (97%)
Title : VideoHandle
Language :  English
Encoded date :  UTC 2021-07-05 12:32:22
Tagged date :   UTC 2021-07-05 12:32:22
Color range :   Limited
Color primaries :   BT.601 PAL
Transfer characteristics :  BT.709
transfer_characteristics_Original : BT.601
Matrix coefficients :   BT.601
mdhd_Duration : 17900
Codec configuration box :   avcC
    
**Audio**
ID :    1
Format :    AAC LC
Format/Info :   Advanced Audio Codec
Codec ID :  mp4a-40-2
Duration :  19 s 488 ms
Bit rate mode : Constant
Bit rate :  128 kb/s
Channel(s) :    1 channel
Channel layout :    C
Sampling rate : 32.0 kHz
Frame rate :    31.250 FPS (1024 SPF)
Compression mode :  Lossy
Stream size :   305 KiB (3%)
Title : SoundHandle
Language :  English
Encoded date :  UTC 2021-07-05 12:32:22
Tagged date :   UTC 2021-07-05 12:32:22

支持搜索的视频:

**General**
Complete name : camera-1.mp4
Format :    MPEG-4
Format profile :    Base Media
File size : 44.4 MiB
Duration :  21 s 823 ms
Overall bit rate :  17.1 Mb/s
Encoded date :  UTC 2021-07-05 06:19:27
Tagged date :   UTC 2021-07-05 06:19:27
com_android_version :   11

**Video**
ID :    2
Format :    AVC
Format/Info :   Advanced Video Codec
Format profile :    High
Format level :  4
Format settings, CABAC :    Yes
Format settings, Reference frames : 1 frame
Format settings, GOP :  M=1, N=30
Codec ID :  avc1
Duration :  21 s 823 ms
Bit rate :  17.0 Mb/s
Width : 1 920 pixels
Height :    1 080 pixels
Display aspect ratio :  16:9
Frame rate mode :   Variable
Frame rate :    30.000 FPS
Minimum frame rate :    29.890 FPS
Maximum frame rate :    30.120 FPS
Standard :  NTSC
Color space :   YUV
Chroma subsampling :    4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) :    0.273
Stream size :   44.2 MiB (99%)
Title : VideoHandle
Language :  English
Encoded date :  UTC 2021-07-05 06:19:27
Tagged date :   UTC 2021-07-05 06:19:27
Color range :   Full
Color primaries :   BT.601 PAL
colour_primaries_Original : BT.601 NTSC
Transfer characteristics :  BT.709
transfer_characteristics_Original : BT.601
Matrix coefficients :   BT.601
mdhd_Duration : 21823
Codec configuration box :   avcC

**Audio**
ID :    1
Format :    AAC LC
Format/Info :   Advanced Audio Codec
Codec ID :  mp4a-40-2
Duration :  21 s 819 ms
Source duration :   21 s 717 ms
Bit rate mode : Constant
Bit rate :  96.0 kb/s
Channel(s) :    1 channel
Channel layout :    C
Sampling rate : 48.0 kHz
Frame rate :    46.875 FPS (1024 SPF)
Compression mode :  Lossy
Stream size :   255 KiB (1%)
Source stream size :    255 KiB (1%)
Title : SoundHandle
Language :  English
Encoded date :  UTC 2021-07-05 06:19:27
Tagged date :   UTC 2021-07-05 06:19:27
mdhd_Duration : 21819
马库斯舒曼

MP4 播放器需要知道同步样本(I 帧或 IDR 帧)的位置。同步样本位置通常用位于moov->trak->mdia->minf->stbl->stss.

在您的示例文件中,缺少“stss”框。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

旋转mp4视频而无需重新编码

ffmpeg:TS视频可以不重新编码直接转成MP4视频吗?

作为神经网络的输入,原始视频是否优于 mp4 编码视频?

使用avconv连接不同编码参数的.mp4视频,而又不损失质量?

如何通过仅使用ffmpeg编码连接点修剪mp4视频

使用相同编码的.flv和.mp4视频文件之间哪个更好?

如何从UIImagePickerController将iOS视频编码为.mp4,以便Android设备可以播放它们?

如何根据“编码日期”重命名未删除的mp4视频文件

通过PHP上传视频并编码为服务器上的MP4和/或WebM?

如何形成一个 gstreamer 管道来编码来自 tiff 文件的 mp4 视频?

AVI无法编码为MP4

libvlc可以将原始YUV或RGBA帧编码为视频文件(如mp4文件)吗?

如何使用Azure Media Services v3生成从.mp3(或其他仅音频)文件编码的.mp4的空白或空白视频层?

将非碎片化的 mp4 重新编码为碎片化的 mp4

编码多部分mp4文件

使用AVI将ffmpeg编码为mp4

用于制作 mp4 质量的 ffmpeg 并行编码

使用DivX设置使用ffmpeg编码为mp4

从mp4编码到HLS时FFMPEG故障

重新混合/编码/将MPG转换为MP4

如何停止将视频流中的最后一帧作为使用 ffmpeg 编码的 mp4 容器的一部分?

HTML5视频:ffmpeg编码的MP4不能在任何浏览器中播放(尽管在VLC中播放)

保存mp4视频opencv

使用FFMPEG的MP4视频旋转

concat mp4空白视频

android:修剪mp4视频

视频(MPG,MP4)的无损旋转?

用JavaScript创建MP4视频

在 Instagram 上传 MP4 视频