使用gstreamer 1.12.2将MPEG-TS拆分为MP4文件 [英] Split MPEG-TS into MP4 files with gstreamer 1.12.2

查看:481
本文介绍了使用gstreamer 1.12.2将MPEG-TS拆分为MP4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a MPEG-TS file which contains two video/audio stream-pairs:

$ 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容器中.

Now I would like to extract the first video and audio streams and the second video/audio into two separate MP4 containers.

通过简单的管道同时显示两个视频流:

Showing both video streams in parallel works with a simple pipeline:

$ 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容器文件中:

When I introduce the mp4mux together with a filesink element on one stream it still work, the first video stream is shown and the second video is saved to a MP4 container file:

$ 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

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

Now for my problem: Once I try to have both streams saved through filesinks it fails:

$ 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或某些外部二进制文件是不可行的.

I would like to achieve this using gstreamer because it should later be part of a larger processing workflow that needs a lot of introspection, so using ffmpeg or some external binary is no an option.

推荐答案

GStreamer缓冲区没有PTS失败模式

使用GStreamer可能无法完全解决问题,但这是我现在正在使用的解决方法.它涉及隔离出失败的组件,该组件是gstreamer管道中的"mp4mux"元素.

GStreamer Buffer has no PTS Failure Mode

This may not completely solve the problem using GStreamer, but this is a workaround that I'm now using. It involves isolating out the failing component which is the 'mp4mux' element in the gstreamer pipeline.

我发现,即使Gstreamer中的示例视频编码目前也无法通过,例如带有Buffer的PTS没有失败模式:

I'm finding that even a sample video encoding in Gstreamer is currently failing e.g. with the Buffer has no PTS failure mode:

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

仅将Gstreamer用于h264编码.

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

Using Gstreamer for h264 Encoding only.

Removing the mp4mux element allows us to successfully create .h264 files. Particularly handy if you're using a Raspberry Pi omxh264 encoder element.

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

解决音频和视频混合的问题

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

Solving the problem of Mixing Audio and Video

Now to convert that into an MP4 (the initial goal) we can use the nice lightweight 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编码和pipline很棒,并且可以正常工作.
  3. 使用GPac将音频组合成Mp4文件是一种可行的选择.

这篇关于使用gstreamer 1.12.2将MPEG-TS拆分为MP4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆