I am trying to learn to record X11 windows' contents to do game screencasts for Youtube. This should be a fairly trivial task, but it already ate a full evening. Now I have learned a bit about muxing and queueing (using gst-launch
), but the problem remains: When I mux an audio and video into an avi, video plays several times faster than audio in the resultant file. This means that video ends soon and comes to still, while audio continues to babble in the background.
This is my filter chain that causes the issue:
gst-launch-1.0 ximagesrc xid=$XID ! video/x-raw,framerate=30/1 ! videoconvert !
x264enc ! queue ! avimux name=mux ! queue ! filesink location=out.avi
pulsesrc device=$DEV ! queue ! audioconvert !
lamemp3enc bitrate=192 ! queue ! mux.
However, the issue vanishes when I just have video, and it is played with perfectly normal speed:
ximagesrc xid=0x0820000b ! video/x-raw,framerate=30/1 ! videoconvert !
x264enc ! avimux ! filesink location=out.avi
I would also appreciate if you correct me on the usage of ! queue !
. Where is it needed? In the current setup I almost never get warnings that samples were dropped.
Update: I would prefer to use mp4 muxer, but it produces unplayable files lacking moov atom. Youtube recommends putting it at the beginning of file, any chance I can force that with mp4 muxer?
gst-launch-1.0 ximagesrc xid=$XID ! video/x-raw,framerate=30/1 ! queue ! videoconvert ! videorate ! queue ! x264enc ! queue ! avimux name=mux ! queue ! filesink location=out.avi pulsesrc device=$DEV ! queue ! audioconvert ! queue ! lamemp3enc bitrate=192 ! queue ! mux.
The above pipeline should play the audio video at proper speed.
I would also appreciate if you correct me on the usage of ! queue !. Where is it needed? In the current setup I almost never get warnings that samples were dropped.
queue are just buffers, these need to be used in places where one element is slower and one is faster, so for example video generating (ximagesrc) is much faster compared with x264enc (software encoding), so you would add a queue in between them so as to buffers aren’t dropped.
gst-launch-1.0 ximagesrc ! video/x-raw,framerate=30/1 ! queue ! videoconvert ! queue ! x264enc key-int-max=5 ! queue ! mp4mux name=mux reserved-bytes-per-sec=100 reserved-max-duration=20184000000000 reserved-moov-update-period=100000000 ! queue ! filesink location=out.mp4 audiotestsrc ! queue ! audioconvert ! queue ! lamemp3enc bitrate=192 ! queue ! mux.
The above pipeline would create a mp4 file mp4mux, but the moov atom will be at end itself also note make sure you change mp4mux properties as per your need.