首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用GStreamer1.12.2将MPEG-TS拆分为MP4文件

用GStreamer1.12.2将MPEG-TS拆分为MP4文件
EN

Stack Overflow用户
提问于 2017-08-02 08:18:18
回答 1查看 2.8K关注 0票数 1

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

代码语言:javascript
复制
$ 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容器中。

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

代码语言:javascript
复制
$ 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

当我将mp4mux与一个流上的filesink元素一起引入时,它仍然工作,第一个视频流显示,第二个视频保存到MP4容器文件中:

代码语言:javascript
复制
$ 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

现在我的问题是:一旦我尝试通过文件墨水保存这两个流,它就失败了:

代码语言:javascript
复制
$ 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或一些外部二进制文件是不可能的。

EN

回答 1

Stack Overflow用户

发布于 2018-04-11 07:43:11

GStreamer缓冲区没有PTS故障模式

这可能不能完全解决使用GStreamer的问题,但这是我现在使用的解决方法。它包括隔离失败的组件,即gstreamer管道中的“mp4mux”元素。

我发现,即使是Gstreamer中的示例视频编码目前也失败了,例如缓冲区中没有PTS失败模式:

代码语言:javascript
复制
gst-launch-1.0 videotestsrc num_buffers=300 ! videoconvert ! videoscale ! omxh264enc ! h264parse ! mp4mux ! filesink location=test.mp4

只对h264编码使用Gstreamer。

删除mp4mux元素使我们能够成功地创建.h264文件。如果您使用的是Raspberry Pi omxh264编码器元素,那么特别方便。

代码语言:javascript
复制
gst-launch-1.0 videotestsrc num_buffers=300 ! videoconvert ! videoscale ! omxh264enc ! filesink location=test.h264

解决音视频混合问题

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

代码语言:javascript
复制
sudo apt-get install gpac

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

然后你可以添加你的音频

代码语言:javascript
复制
MP4Box -add audio.mp3 test.mp4

摘要

  1. 当使用GStreamer元素时,Mp4Mux当前显示为“无PTS故障模式”。
  2. GStreamer通用的h264编码和对线是很棒的,而且很有用。
  3. 使用GPac将音频组合成Mp4文件是一种可行的选择。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45455279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档