我试图将Android摄像头预览帧编码为h264,并将mux复制到mp4容器。FFmpeg摄像头编码h264 mp4复用原子avcC太小
我可以成功创建mp4文件。但MP4格式似乎损坏。
使用ffprobe
,我得到以下错误。
$ ffprobe o.mp4
[h264 @ 0x209fe50] non-existing PPS 0 referenced
[h264 @ 0x209fe50] decode_slice_header error
[h264 @ 0x209fe50] no frame!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x209ea60] decoding for stream 0 failed
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x209ea60] Could not find codec parameters for stream 0 (Video: h264 (avc1/0x31637661), none, 568x320, 505 kb/s): unspecified pixel format
然后我使用mp4info
工具来查看信息是否正确。我找到了这个。
$ mp4info o.mp4
mp4info version 2.0.0
o.mp4:
ReadProperties: atom 'avcC' is too small; overrun at property: configurationVersion (src/mp4atom.cpp,386)
mp4info: can't open o.mp4
通过文件的hexdump都内容,我得到这个
$ xxd o.mp4 |grep -A 5 -B 5 avcC
0039170: 6331 0000 0000 0000 0001 0000 0000 0000 c1..............
0039180: 0000 0000 0000 0000 0000 0238 0140 0048 [email protected]
0039190: 0000 0048 0000 0000 0000 0001 0000 0000 ...H............
00391a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00391b0: 0000 0000 0000 0000 0000 0000 0018 ffff ................
00391c0: 0000 0008 6176 6343 0000 0020 7374 7473 ....avcC... stts
00391d0: 0000 0000 0000 0002 0000 004f 0000 0ea6 ...........O....
00391e0: 0000 0001 0000 0000 0000 0058 7374 7373 ...........Xstss
00391f0: 0000 0000 0000 0012 0000 0001 0000 0005 ................
0039200: 0000 000a 0000 000f 0000 0014 0000 0019 ................
0039210: 0000 001e 0000 0023 0000 0028 0000 0029 .......#...(...)
如果我不添加全局头AVCodecContext
,
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {
// oc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
ffprobe
可以检测格式没有错误,也可以玩ffplay
。但avcC
原子仍然不正确。其他玩家不能玩。
为什么muxer没有写出正确的avcC
原子?
我该如何解决?