如何使用gstreamer进行转码和调整大小从mp4(h264 / aac)到mp4(h264 / mp3)?

时间:2015-01-20 02:31:47

标签: gstreamer mp4 h.264 aac gst-launch

我想使用gstreamer转码并调整mp4。(mp4-h264_1920x1080 / aac => mp4-h264_640x480 / mp3)。我写下了这个命令。

$ gst-launch-0.10 filesrc location=./gain_1.mp4 ! qtdemux name=demux demux.video_00 ! queue ! ffdec_h264 ! videoscale ! 'video/x-raw-yuv,width=640,height=480' ! x264enc ! queue ! qtmux name=mux mux.video_0 demux.audio_00 ! queue ! ffdec_aac ! lame bitrate=128 ! queue ! mux.audio_0 mux. ! filesink location=0000.mp4 –v -e
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
^CCaught interrupt -- handling interrupt.
Interrupt: Stopping pipeline ...

(gst-launch-0.10:17958): GLib-CRITICAL **: Source ID 1 was not found when attempting to remove it
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

哪个不起作用。

仅转码视频有效:

gst-launch-0.10 filesrc location=./gain_1.mp4 ! qtdemux name=demux demux.video_00 ! queue ! ffdec_h264 ! videoscale ! 'video/x-raw-yuv, width=640, height=480' ! x264enc ! queue ! mux. mp4mux name=mux ! filesink location=0000.mp4 –v -e

仅转录音频:

gst-launch-0.10 filesrc location=./gain_1.mp4 ! qtdemux name=demux demux.audio_00 ! ffdec_aac ! lame bitrate=128 ! queue ! mux. mp4mux name=mux ! filesink location=0000.mp4 –v -e

如何使用相同的命令对音频和视频进行转码?

2 个答案:

答案 0 :(得分:1)

哦〜 我解决了这个问题。 下一个命令做得很好。

gst-launch-0.10 ffmux_mp4 name=mux ! \
filesink location=0000.mp4 \
filesrc location=./gain_1.mp4 ! qtdemux name=vdemux vdemux.video_00 ! queue ! ffdec_h264 ! videoscale ! 'video/x-raw-yuv, width=640, height=480' ! x264enc ! queue ! mux. \
filesrc location=./gain_1.mp4 ! qtdemux name=ademux ademux.audio_00 ! ffdec_aac ! lame bitrate=128 ! queue ! mux.`

答案 1 :(得分:0)

@ Lionel.J我想提出两点改进建议:

  1. 如果可能,请使用gstreamer-1
  2. 您的解决方案会两次读取源文件。这不是必要的。此外,执行此操作时,音频和视频流不会同步。您可以从qtdemux中读取音频和视频流。
  3. 这是一个使用gstreamer-1完成工作的管道,只读取源一次:

    gst-launch-1.0 -e filesrc location=/path/to/big_buck_bunny_720p_h264.mov ! \
    decodebin name=decode ! \
    videoscale ! 'video/x-raw,width=640,height=480' ! \
    x264enc ! queue ! mp4mux name=mp4mux ! filesink location=0000.mp4 \
    decode. ! audioconvert ! lamemp3enc bitrate=128 ! queue ! mp4mux.