Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gstreamer: How to get audio and video to play at the same rate

Tags:

gstreamer

My pipe line is simply trying to mux an audiotestsrc with a videotestsrc and output to a filesink.

videotestsrc num-buffers=150  ! video/x-raw-yuv,width=1920, height=1080 ! 
   timeoverlay ! videorate ! queue ! xvidenc ! avimux name=mux mux.
      ! filesink sync=true location=new.avi  
audiotestsrc num-buffers=150 ! 
  queue ! audioconvert ! audiorate ! mux.
  • new.avi is produced.
  • Video is exactly 5 seconds long as expected
  • Audio is about 3.5 seconds long and the remaining 1.5 seconds is
    slient.

What am I missing here? I've tried every combination of sync="" properties, etc.

What pipeline would generate a test clip with autotestpattern and videotest pattern muxed together where audio and video are the same duration?

Thanks

like image 676
thrag Avatar asked Apr 17 '12 05:04

thrag


People also ask

Is GStreamer fast?

GStreamer is an extremely powerful and versatile framework for creating streaming media applications. Many of the virtues of the GStreamer framework come from its modularity: GStreamer can seamlessly incorporate new plugin modules.

What is GST launch?

gst-launch is a tool that builds and runs basic GStreamer pipelines. In simple form, a PIPELINE-DESCRIPTION is a list of elements separated by exclamation marks (!). Options may be appended to elements, in the form "option=value".


2 Answers

audiotestsrc num-buffers=150

By default each buffer contains 1024 samples: samplesperbuffer Which means you are generating 150*1024=153600 samples. Asuming 44.1kHz, the duration would be 153600/44100=3.48 seconds.

So if you need 5 seconds audio, you need 5*44100=220500 samples. with samplesperbuffer==1024, this means 220500/1024=215.33 buffers. (ie 215 or 216 buffers).

It would be easier if you set samplesperbuffer to 441, then you need exactly 100 buffers for every second audio:

audiotestsrc num-buffers=500 samplesperbuffer=441
like image 180
wimh Avatar answered Sep 23 '22 11:09

wimh


You can make use of the blocksize roperty of audiotesrc to match the duration of a frame. this is in bytes and thus you might want to use a caps filter after audiotestsrc to select a sampling-rate and sample format.

like image 38
ensonic Avatar answered Sep 23 '22 11:09

ensonic