ffmpeg 0.10.3 h264_mp4toannexb 异常

在使用

ffmpeg -i test.mp4 -ss 0 -t 10 -acodec copy -vcodec copy -vbsf h264_mp4toannexb -y test.ts

命令的时候, 部分视频会出现异常:

Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec copy: Invalid argument
Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec copy: Invalid argument
Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec copy: Invalid argument
Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec copy: Invalid argument
Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec copy: Invalid argument
[mpegts @ 0x14eb0980] H.264 bitstream malformed, no startcode found, use the h264_mp4toannexb bitstream filter
av_interleaved_write_frame(): Invalid data found when processing input


需要调整

libavcodec/h264_mp4toannexb_bsf.c

解决。


调整为:

        /* retrieve length coded size */
        ctx->length_size = (*extradata++ & 0x3) + 1;
//@alex
//        if (ctx->length_size == 3)
//            return AVERROR(EINVAL);

以及:

    *poutbuf_size = 0;
    *poutbuf = NULL;
    do {
        ret= AVERROR(EINVAL);
        if (buf + ctx->length_size > buf_end)
            goto fail;

        if (ctx->length_size == 1) {
            nal_size = buf[0];
        } else if (ctx->length_size == 2) {
            nal_size = AV_RB16(buf);
//@alex			
//        } else
//            nal_size = AV_RB32(buf);
	} else {
		 for(nal_size = 0, unit_type = 0; unit_type < ctx->length_size; unit_type++)
			nal_size = (nal_size << 8) | buf[unit_type]; 		
	}


参考:

http://ffmpeg-users.933282.n4.nabble.com/MPEG-TS-trouble-td4491337.html

there is a bug in libavcodec/h264_mp4toannexb_bsf.c
when the ctx->length_size == 3 , the filter will report the error
"Invalid argument"

diff --git a/libavcodec/h264_mp4toannexb_bsf.c
b/libavcodec/h264_mp4toannexb_bsf.c
index 5085ecb..fa16f2a 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -82,8 +82,8 @@ static int
h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc,
 
         /* retrieve length coded size */
         ctx->length_size = (*extradata++ & 0x3) + 1;
-        if (ctx->length_size == 3)
-            return AVERROR(EINVAL);
+    //    if (ctx->length_size == 3)
+    //        return AVERROR(EINVAL);
 
         /* retrieve sps and pps unit(s) */
         unit_nb = *extradata++ & 0x1f; /* number of sps unit(s) */
@@ -146,8 +146,10 @@ pps:
             nal_size = buf[0];
         } else if (ctx->length_size == 2) {
             nal_size = AV_RB16(buf);
-        } else
-            nal_size = AV_RB32(buf);
+        } else {
+            for(nal_size = 0, unit_type = 0;
unit_type<ctx->length_size; unit_type++)
+                nal_size =  (nal_size << 8) | buf[unit_type];
+        }
 
         buf += ctx->length_size;
         unit_type = *buf & 0x1f;


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值