【问题标题】:Split MPEG-TS into MP4 files with gstreamer 1.12.2使用 gstreamer 1.12.2 将 MPEG-TS 拆分为 MP4 文件
【发布时间】:2017-08-02 08:18:18
【问题描述】:

我有一个 MPEG-TS 文件,其中包含两个视频/音频流对:

$ gst-discoverer-1.0 Recorder_Aug01_12-30-39.ts
Analyzing Recorder_Aug01_12-30-39.ts
Done discovering Recorder_Aug01_12-30-39.ts

Topology:
  container: MPEG-2 Transport Stream
    audio: MPEG-2 AAC
      audio: MPEG-4 AAC
    video: H.264 (High Profile)
    audio: MPEG-2 AAC
      audio: MPEG-4 AAC
    video: H.264 (High Profile)

Properties:
  Duration: 0:01:49.662738259
  Seekable: yes
  Tags: 
      audio codec: MPEG-2 AAC
      video codec: H.264

现在我想将第一个视频和音频流以及第二个视频/音频提取到两个单独的 MP4 容器中。

使用简单的管道并行显示两个视频流:

$ gst-launch-1.0 filesrc location=Recorder_Aug01_12-30-39.ts ! tsdemux name=ts \
    ts.video_0_0102 ! queue ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! autovideosink \
    ts.video_0_0100 ! queue ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! autovideosink

当我在一个流中引入mp4muxfilesink 元素时,它仍然有效,显示第一个视频流并将第二个视频保存到 MP4 容器文件中:

$ gst-launch-1.0 filesrc location=Recorder_Aug01_12-30-39.ts ! tsdemux name=ts \
    ts.video_0_0102 ! queue ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! ximagesink \
    ts.video_0_0100 ! queue ! h264parse ! mp4mux ! filesink location=2.mp4

现在我的问题是:一旦我尝试通过文件接收器保存两个流,它就会失败:

$ gst-launch-1.0 filesrc location=Recorder_Aug01_12-30-39.ts ! tsdemux name=ts \
    ts.video_0_0102 ! queue ! h264parse ! mp4mux ! filesink location=1.mp4 \
    ts.video_0_0100 ! queue ! h264parse ! mp4mux ! filesink location=2.mp4
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
ERROR: from element /GstPipeline:pipeline0/GstMP4Mux:mp4mux0: Could not multiplex stream.
Additional debug info:
gstqtmux.c(3486): gst_qt_mux_add_buffer (): /GstPipeline:pipeline0/GstMP4Mux:mp4mux0:
Buffer has no PTS.
Execution ended after 0:00:00.001992389
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

我想使用 gstreamer 来实现这一点,因为它稍后应该成为需要大量内省的更大处理工作流的一部分,因此无法选择使用 ffmpeg 或某些外部二进制文件。

【问题讨论】:

  • 您可以使用GST_DEBUG=3 运行您的管道以获得更多日志吗?

标签: video gstreamer mp4 mpeg


【解决方案1】:

GStreamer 缓冲区没有 PTS 故障模式

这可能无法完全解决使用 GStreamer 的问题,但这是我现在正在使用的解决方法。它涉及隔离出故障组件,即 gstreamer 管道中的“mp4mux”元素。

我发现即使是 Gstreamer 中的示例视频编码当前也失败了,例如与 Buffer 没有 PTS 故障模式:

gst-launch-1.0 videotestsrc num_buffers=300 ! videoconvert ! videoscale ! omxh264enc ! h264parse ! mp4mux ! filesink location=test.mp4

仅将 Gstreamer 用于 h264 编码。

移除 mp4mux 元素可以让我们成功创建 .h264 文件。如果您使用的是 Raspberry Pi omxh264 编码器元素,则特别方便。

gst-launch-1.0 videotestsrc num_buffers=300 ! videoconvert ! videoscale ! omxh264enc ! filesink location=test.h264

解决音视频混音问题

现在要将其转换为 MP4(最初的目标),我们可以使用漂亮的轻量级 Gpac MP4box。

sudo apt-get install gpac

MP4Box -isma -inter 250 -fps 30.0 -mpeg4 -hint -noprog -add test.h264 test.mp4

然后你可以添加你的音频

MP4Box -add audio.mp3 test.mp4

总结

  1. 在使用 Mp4Mux 元素时,GStreamer 目前出现故障,并出现无 PTS 故障模式。
  2. GStreamer 通用 h264 编码和管道非常棒,而且工作正常。
  3. 使用 GPac 将音频合并到 Mp4 文件中是一种可行的选择。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    相关资源
    最近更新 更多