6

I have this existing program that uses gst-plugin-1.0 and it passes this:

-e udpsrc port=3003 buffer-size=200000 ! h264parse ! queue ! http://mux.video_0 alsasrc device=plughw:1,0 ! "audio/x-raw,channels=1,depth=16,width=16,rate=44100" ! voaacenc bitrate=128000 ! aacparse ! queue ! http://mux.audio_0 qtmux name=mux ! filesink location="$RECPATH/record-`date +%Y%m%d%-H%M%S`.mp4" sync=true

This takes the video from an udp source which is in x264 and the audio directly from the microphone. It works but since it doesn't encode the video and the audio at the same time I have a bit of delay on the audio when the video stream has latency (due to higher quality settings).

So as a quick-fix I was thinking about adding a delay on the audio recording to compensate. I would calculate that delay by hand depending on the video quality.

Constraint: gst-launch-1.0 version 1.10.4 (on a raspberry pi, debian stretch), use-driver-timestamps doesn't seem to be accessible, I get the error 'WARNING: erroneous pipeline: no property "use-driver-timestamps" in element "alsasrc0"'.

So my question is: is there an easy way to add delay to the audio?

Yozhgoor
  • 123
  • 6

2 Answers2

3

the queue element had the min-threshold-time property, which lets you hold on to data for n amount of time.

https://gstreamer.freedesktop.org/documentation/coreelements/queue.html?gi-language=c#queue:min-threshold-time

Alternatively I found this too, might be useful for your case pipeline Gstremer video streaming with delay

Diego Rodriguez
  • 368
  • 2
  • 9
  • 1
    I tried and it actually helped but either I get corrupted files, or the sound is not there or the video is glitched. In the second comment they also propose a solution with `autoaudiosink` which looks promising but I couldn't figure out how to use it https://stackoverflow.com/a/40196962/2824342 – Cecile Nov 14 '20 at 11:39
1

Try ! autoaudiosink ts-offset=100000000

ts-offset is documented here.

You can also experiment pipelines with latency compensation;

https://gstreamer.freedesktop.org/documentation/additional/design/latency.html#latency-compensation

tozlu
  • 4,667
  • 3
  • 30
  • 44
  • Can you show how to add it to the command line? It seems to be refused everywhere `WARNING: erroneous pipeline: could not link autoaudiosink0 to ...` I tried everywhere – Cecile Nov 21 '20 at 11:05
  • 1
    try `gst-inspect-1.0 autoaudiosink` and if it prints properties of the plugin, then try `gst-launch-1.0 audiotestsrc ! audioconvert ! audioresample ! autoaudiosink` and see if that plays a sound. Then try same command with `ts-offset` and see if it works. – tozlu Nov 21 '20 at 13:19
  • Still no luck. `autoaudiosink` is there but it doesn't play any sound. Are you sure this can be used when recording? I'm mixing a h264 input video with the sound of a microphone to generate an mp4 – Cecile Nov 29 '20 at 09:13