You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用libav*封装H264数据包到MPEGTS容器时出错求助

H264编码数据包封装MPEGTS容器失败问题

编码部分基于FFmpeg官方encode_video示例实现,功能正常:生成的std::vector<AVPacket>序列直接写入.ts文件可被SMPlayer正常播放,ffprobe检测显示为原始H264视频格式。

但基于mux.c示例进行MPEGTS封装时失败,控制台报错:

[mpegts @ 0x55555736edc0] H.264 bitstream malformed, no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it ('-bsf:v h264_mp4toannexb' option with ffmpeg)

已在代码中添加h264_mp4toannexb比特流滤镜,但错误仍存在;若改用av_interleaved_write_frame写入,除相同错误外还触发段错误,GDB调用栈显示错误源于av_packet_ref等函数。

已尝试以下方案但均无效:

  • 在avformat_alloc_output_context2后添加muxCodecContextPtr_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
  • 写入前设置packet.flags |= AV_PKT_FLAG_KEY;
  • 手动写入起始码
  • 调整Mux_FillCodecContext中的参数

内容的提问来源于stack exchange,提问作者Lucen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 00:42:08