I am trying to convert a DVD to mkv file with gstreamer. The pipeline I use is:
gst-launch -evv multifilesrc location="VTS_01_%d.VOB" index=1 ! dvddemux name=demuxer \
matroskamux name=mux ! filesink location=test.mkv \
demuxer.current_video ! queue ! mpeg2dec ! x264enc ! mux. \
demuxer.current_audio ! queue ! ffdec_ac3 ! lamemp3enc ! mux.
Unfortunately the pipeline does not go beyond prerolling. When I replace x264enc with for instance ffenc_mpeg4, then everything works fine..
This may work :
gst-launch filesrc location=file.vob \
! queue \
! dvddemux name=demuxer matroskamux name=mux \
! queue \
! filesink location=test.mkv demuxer.current_video\
! queue \
! ffdec_mpeg2video \
! ffdeinterlace \
! x264enc \
! 'video/x-h264, width=720, height=576, framerate=25/1' \
! mux. demuxer.current_audio \
! queue max-size-bytes=0 max-size-buffers=0 max-size-time=10000000000 \
! ffdec_ac3 \
! audioconvert \
! lamemp3enc \
! mux.
Byte stream should be 0 - sorry for that earlier
You need to give the caps of the video after the x264enc
and you need to increase the limits on the audio queue to handle the delay in x264enc
These two changes have the pipeline running at my end.
The deinterlacer is optional but desirable for interlaced content.
Related
I use the following pipeline to play my video on screen
gst-launch-1.0 filesrc location=01_189_libxvid_1920x1080_6M.mp4 !
qtdemux ! mpeg4videoparse ! omxmpeg4videodec ! videobalance brightness=100 !
video/x-raw,format=BGRA ! waylandsink --gst-debug=*:2
but now instead of directly playing I want to encode it and save it in some folder. Please suggest
Should be something like this (example with h264 codec):
gst-launch-1.0 -e --gst-debug=3 \
filesrc location="/path/input/sample_in.mp4" \
! qtdemux \
! mpeg4videoparse \
! omxmpeg4videodec \
! queue \
! x264enc \
! qtmux \
! filesink location="/path/output/sample_out.mp4"
Here is the code for 2 mp4 videos playing in videoboxes.
gst-launch-1.0 filesrc location=1.mp4 ! decodebin ! queue !
videoconvert ! videobox border-alpha=0 right=-100 ! videomixer
name=mix ! videoconvert ! autovideosink filesrc location=2.mp4 !
decodebin ! queue ! videoconvert ! videobox border-alpha=0 left=-100 !
mix.
I have tried with this code to play 3 videos
gst-launch-1.0 filesrc location=Downloads/1.mp4 ! decodebin ! queue !
videoconvert ! videobox border-alpha=0 right=-100 ! videomixer
name=mix !
videoconvert ! autovideosink filesrc location=Downloads/2.mp4 !
decodebin ! queue ! videoconvert ! videobox border-alpha=0 left=-100 !
mix !
videoconvert ! autovideosink filesrc location=Downloads/3.mp4 !
decodebin ! queue ! videoconvert ! videobox border-alpha=0 left=-200 !
mix.
I get syntax error :(
Something like that with videomixer
gst-launch-1.0 -e \
videomixer name=mix background=0 \
sink_1::xpos=0 sink_1::ypos=0 \
sink_2::xpos=200 sink_2::ypos=0 \
sink_3::xpos=100 sink_3::ypos=100 \
! autovideosink \
uridecodebin uri='file:///data/big_buck_bunny_trailer-360p.mp4' \
! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_1 \
uridecodebin uri='file:///data/sintel_trailer-480p.webm' \
! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_2 \
uridecodebin uri='file:///data/the_daily_dweebs-720p.mp4' \
! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_3
Once you instantiate an element with a name (eg. videomixer name=mix), you can later connect to it with . (eg. mix.). You don't need to repeat autovideosink 3 times after that.
gst-launch-1.0 filesrc location=Downloads/1.mp4 ! decodebin ! queue ! videoconvert ! videobox border-alpha=0 right=-100 ! videomixer name=mix ! videoconvert ! autovideosink
filesrc location=Downloads/2.mp4 ! decodebin ! queue ! videoconvert ! videobox border-alpha=0 left=-100 ! mix.
filesrc location=Downloads/3.mp4 ! decodebin ! queue ! videoconvert ! videobox border-alpha=0 left=-200 ! mix.
Here, we have initialized 3 pipes and merged three of them with mix element.
I run the following code
gst-launch-1.0 -e \
videomixer name=mix \
sink_0::xpos=0 sink_0::ypos=0 sink_0::alpha=0\
sink_1::xpos=0 sink_1::ypos=0 \
sink_2::xpos=200 sink_2::ypos=0 \
sink_3::xpos=0 sink_3::ypos=100 \
sink_4::xpos=200 sink_4::ypos=100 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147924'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_1 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147925'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_2 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147926'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_3 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147927'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_4 \
mix. ! queue ! videoconvert ! x264enc ! flvmux streamable=true ! queue ! rtmpsink location='rtmp://streaming.example.com:1935/test'
Thank you. We solved the problem with the mosaic. This is the working version.
There are two issues.
1) Main issue is "videomixer" has only one src pad. You are connecting it to two pads.
-
gst-launch-1.0 -e \
videomixer name=mix \
sink_0::xpos=0 sink_0::ypos=0 sink_0::alpha=0\
sink_1::xpos=0 sink_1::ypos=0 \
sink_2::xpos=200 sink_2::ypos=0 \
sink_3::xpos=0 sink_3::ypos=100 \
sink_4::xpos=200 sink_4::ypos=100 \
! xvimagesink
By doing this, you are connecting videomixer src_pad to sink pad of sixvimagesink
Again at the end, you are trying to connect videomixer src_ to rtmpsink using queue and other elements.
So you have to remove one of the connections.
If you don't want to connect to xvimagesink, just remove "! xvimagesink"
If you dont want to connect to rtmpsink, remove the "mix ! queue ! videoconvert ..." part.
2) If you want to retain connection to queue, there is the following issue.
You are connecting mix.sink_4 to mix.src.
... ! mix.sink_4 \
! mix. ! queue ! videoconvert ! ...
Remove the first "!" and "." in the last line.
... ! mix.sink_4 \
mix ! queue ! videoconvert ! ...
Then it should not give syntax error.
EDIT 1
I think again you have made a mistake. You are connecting src of mix to mix.sink_0. I have corrected it.
gst-launch-1.0 -e \
videomixer name=mix \
sink_0::xpos=0 sink_0::ypos=0 sink_0::alpha=0\
sink_1::xpos=0 sink_1::ypos=0 \
sink_2::xpos=200 sink_2::ypos=0 \
sink_3::xpos=0 sink_3::ypos=100 \
sink_4::xpos=200 sink_4::ypos=100 \
\ /* You should not add "! .mix.sink_0" here. */
rtmpsrc location='rtmp://streaming.example.com:1935/209147924'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_1 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147925'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_2 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147926'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_3 \
rtmpsrc location='rtmp://streaming.example.com:1935/209147927'\
! decodebin ! videoconvert ! videoscale \
! video/x-raw,width=200,height=100 \
! mix.sink_4 \
mix ! queue ! videoconvert ! x264enc ! flvmux streamable=true ! queue ! rtmpsink location='rtmp://streaming.example.com:1935/test'
Let me give some information about "name=" usage here.
You can name an element in gstreamer pipeline and use it to construct pipeline. It is mostly useful in complex pipelines. let me show its usage with a simple pipeline.
Assume the following is the required pipeline:
srcelem ! elem1 ! elem2 ! elem3 ! sinkelem
It can be written as below.
elem2 name=named_elem \ /* Naming elem2 */
named_elem ! elem3 ! sinkelem \ /* Connecting elem2 to downstream pipeline part. Note that there is no "!" before "named_elem" */
srcelem ! elem1 ! named_elem /* Connecting elem2 to upstream pipeline part. Note that there is no "!" after "named_elem" */
If you read it carefully, it constructs the same pipeline which is mentioned earlier.
This is what I'm trying to achieve
I've been trying with the videobox plugin but all I'm getting is 4 equally sized boxes
I previously did something similar to what you described using 3 cameras.
Here's the pipe I used for it:
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, width=800, height=480, framerate=25/1 ! alpha alpha=1.0 ! videobox left=-800 ! videomixer name=mix sink_00::xpos=0 sink_01::xpos=800 sink_02::xpos=0 sink_02::ypos=480 sink_00::alpha=1.0 sink_01::alpha=1.0 sink_02::alpha=1.0 ! videoconvert ! xvimagesink \
v4l2src device=/dev/video1 ! video/x-raw, width=1600, height=1200, framerate=25/1 ! alpha alpha=1.0 ! videobox border-alpha=0 top=-480 ! mix. \
v4l2src device=/dev/video2 ! video/x-raw, width=800, height=480, framerate=25/1 ! alpha alpha=1.0 ! videobox border-alpha=0 left=-00 ! mix. -e
You need to use a videobox element for each videocapture (in this case I used v4l2src however you can use other sources like filesrc ! decodebin or a network source as well) pipe and combine them in a videomixer element.
In my case I used one video on the left and two videos on the right but you can adjust left and top parameters of videobox and sink_0x::xpos' and 'sink_0x::ypos elements of the videomixer element.
Remember to add alpha to each channel or your videos will be transparent.
So this depends very much on how and what you want to do. For example, this can be be as simple GUI application that presents 4 videos on 4 different surfaces and the GUI is responsible for the layout.
If you really want to create a new single image that contains these 4 video streams then videomixer sounds the way to go. See here for some example:
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good/html/gst-plugins-good-plugins-videomixer.html
I use something like this to mix running streams into a single one
/usr/local/bin/gst-launch-1.0 -vv -e videomixer name=mix background=2 \
sink_0::alpha=1.0 \
sink_0::ypos=0 \
sink_0::xpos=0 \
sink_1::alpha=1.0 \
sink_1::ypos=80 \
sink_1::xpos=40 \
sink_2::alpha=1.0 \
sink_2::ypos=80 \
sink_2::xpos=410 \
sink_3::alpha=1.0 \
sink_3::ypos=80 \
sink_3::xpos=780 \
sink_0::zorder=1 \
sink_1::zorder=3 \
sink_2::zorder=3 \
sink_3::zorder=4 \
! clockoverlay auto-resize=false draw-shadow=false draw-outline=false halignment=left valignment=top \
! timeoverlay auto-resize=false draw-shadow=false draw-outline=false halignment=left valignment=bottom \
! queue \
! nvh264enc preset=1 bitrate=1500 rc-mode=2 gop-size=10 \
! h264parse config-interval=-1 \
! mpegtsmux ! rtpmp2tpay pt=33 \
! udpsink host=239.255.42.61 port=5004 multicast-iface=10g-1 ttl=4 ttl-mc=4 \
multifilesrc location=/IMG/logo.jpg caps="image/jpeg,framerate=1/1" \
! jpegdec ! videoconvert ! videoscale \
! video/x-raw,width=1920,height=1080 \
! mix.sink_0 \
udpsrc multicast-group=239.255.42.60 address=239.255.42.60 port=5004 multicast-iface=eth0 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)MP2T,payload=(int)33" \
! rtpjitterbuffer ! rtpmp2tdepay ! tsdemux ! h264parse config-interval=-1 \
! avdec_h264 skip-frame=1 output-corrupt=false ! videoconvert ! videoscale \
! video/x-raw,width=360,height=240 \
! mix.sink_1 \
udpsrc multicast-group=239.255.42.57 address=239.255.42.57 port=5004 multicast-iface=eth0 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)MP2T,payload=(int)33" \
! rtpjitterbuffer ! rtpmp2tdepay ! tsdemux ! h264parse config-interval=-1 \
! avdec_h264 skip-frame=1 output-corrupt=false ! videoconvert ! videoscale \
! video/x-raw,width=360,height=240 \
! mix.sink_2 \
udpsrc multicast-group=239.255.42.62 address=239.255.42.62 port=5004 multicast-iface=eth0 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)MP2T,payload=(int)33" \
! rtpjitterbuffer ! rtpmp2tdepay ! tsdemux ! h264parse config-interval=-1 \
! avdec_h264 skip-frame=1 output-corrupt=false ! videoconvert ! videoscale \
! video/x-raw,width=360,height=240 \
! mix.sink_3 \
This command adds a text to the video, but the audio is missing in the output MP4 file:
gst-launch-1.0 filesrc location=input.mp4 name=src ! decodebin ! textoverlay text="My Text" ! x264enc ! h264parse ! mp4mux ! filesink location=output.mp4
How can I fix this, so that the audio is preserved?
Thanks
This works:
gst-launch-1.0 \
filesrc location=input.mp4 name=src\
! decodebin name=demuxer \
demuxer. ! queue \
! textoverlay text="My Text" \
! x264enc ! muxer. \
demuxer. ! queue \
! audioconvert ! voaacenc ! muxer. \
mp4mux name=muxer \
! filesink location=output.mp4