如何使用GStreamer的mp4mux元件为MP4文件嵌入SRT字幕
错误根因
你遇到的not-negotiated报错确实是格式不匹配导致的:mp4mux的字幕输入端口仅支持tx3g编码的字幕流,你当前流水线中subparse输出的text/x-raw,format=utf8格式无法直接被mp4mux识别。
修正后可运行的流水线
单视频+字幕版本
GST_DEBUG=3 gst-launch-1.0 filesrc location=sample-nosub-avc.mp4 ! qtdemux ! queue ! video/x-h264 ! h264parse ! mp4mux name=mux reserved-moov-update-period=1000 ! filesink location=output.mp4 filesrc location=english.srt ! subparse ! txtenc ! queue ! mux.subtitle_0
保留原视频音轨的完整版本
GST_DEBUG=3 gst-launch-1.0 filesrc location=sample-nosub-avc.mp4 ! qtdemux name=demux demux.video_0 ! queue ! video/x-h264 ! h264parse ! mp4mux name=mux reserved-moov-update-period=1000 ! filesink location=output.mp4 demux.audio_0 ! queue ! aacparse ! mux.audio_0 filesrc location=english.srt ! subparse ! txtenc ! queue ! mux.subtitle_0
修改点说明
- 新增
txtenc元件:将subparse输出的UTF8纯文本字幕转换为MP4兼容的tx3g编码格式,匹配mp4mux的输入要求 - 新增
h264parse/aacparse:规整音视频流的格式参数,避免流参数不匹配导致封装失败 - 给qtdemux命名单独拉取音轨,避免原视频的音频内容丢失
内容的提问来源于stack exchange,提问作者Stephen
相关产品推荐
相关产品推荐

