使用 gstreamer 将 h264 视频转换为非分段 mp4 时,时间丢失
Timing is lost when converting h264 video to non segmented mp4 using gstreamer
我想从 matroska 源创建一个非分段的 .mp4 视频。我已经看到 this post 并创建了一个类似的管道。我的源仅包含 h264 视频而没有声音,所以我的管道如下所示:
gst-launch-1.0 filesrc location=x.mkv ! matroskademux ! h264parse ! mp4mux ! filesink location=x.mp4
然而 运行 gst-discoverer-1.0
结果给出的持续时间为 0:00:00.000000000。 vlc
也无法播放生成的 .mp4 文件,并且不能在 HTML5 <video>
元素中使用(这是此转换的最终目的)。
如果我通过将 fragment-duration=1000
添加到 mp4mux
元素来创建分段的 .mp4,那么 vlc
可以播放 .mp4,但这不是我想要的。 我需要一个总长度已知的 .mp4。我做错了什么?
附加信息:长度存在于 matroska 源代码中,如 gst-discoverer-1.0
所示,vlc
可以显示该源代码。我还可以使用 gstreamer 重播非分段的 .mp4(使用 gst-launch-1.0 filesrc location=x.mp4 ! qtdemux ! h264parse ! avdec_h264 ! videoconvert ! autovideosink
)。检查生成的 .dot
文件显示 qtdemux
的帧率为 10000/1,这看起来很奇怪。
解决方案是将 disable-passthrough=true
添加到 h264parse
元素,因此管道现在如下所示:
gst-launch-1.0 filesrc location=x.mkv ! \
matroskademux ! \
h264parse disable-passthrough=true ! \
mp4mux ! \
filesink location=x.mp4
现在生成的 .mp4 文件包含时间信息,可以很好地用 vlc 播放,也可以在包含 forward/backward 导航的 <video>
标签中播放。
我想从 matroska 源创建一个非分段的 .mp4 视频。我已经看到 this post 并创建了一个类似的管道。我的源仅包含 h264 视频而没有声音,所以我的管道如下所示:
gst-launch-1.0 filesrc location=x.mkv ! matroskademux ! h264parse ! mp4mux ! filesink location=x.mp4
然而 运行 gst-discoverer-1.0
结果给出的持续时间为 0:00:00.000000000。 vlc
也无法播放生成的 .mp4 文件,并且不能在 HTML5 <video>
元素中使用(这是此转换的最终目的)。
如果我通过将 fragment-duration=1000
添加到 mp4mux
元素来创建分段的 .mp4,那么 vlc
可以播放 .mp4,但这不是我想要的。 我需要一个总长度已知的 .mp4。我做错了什么?
附加信息:长度存在于 matroska 源代码中,如 gst-discoverer-1.0
所示,vlc
可以显示该源代码。我还可以使用 gstreamer 重播非分段的 .mp4(使用 gst-launch-1.0 filesrc location=x.mp4 ! qtdemux ! h264parse ! avdec_h264 ! videoconvert ! autovideosink
)。检查生成的 .dot
文件显示 qtdemux
的帧率为 10000/1,这看起来很奇怪。
解决方案是将 disable-passthrough=true
添加到 h264parse
元素,因此管道现在如下所示:
gst-launch-1.0 filesrc location=x.mkv ! \
matroskademux ! \
h264parse disable-passthrough=true ! \
mp4mux ! \
filesink location=x.mp4
现在生成的 .mp4 文件包含时间信息,可以很好地用 vlc 播放,也可以在包含 forward/backward 导航的 <video>
标签中播放。