<div dir="ltr">I want to take audio and video from a webcam and record it to an mp4 file. When I attempt to do this audio cuts out 5 seconds after the recording starts and gstreamer reports:<div>>WARNING: from element /GstPipeline:pipeline0/GstPulseSrc:pulsesrc0: Can't record audio fast enough</div><div><div>>Dropped 22932 samples. This is most likely because downstream can't keep up and is consuming samples too slowly.</div><div><br></div><div>I have the Logitech C920, which has the really nice feature of providing h.264 video directly so the CPU doesn't need to compress it before writing it out to a file. I suspect that I am either missing something that needs to be in the pipeline to either either buffer out the streams, force everything to stay in sink or there is an option that needs to be added to mpegtsmux, but I don't know enough about gstreamer to know what would be. </div><div><br></div><div>Here is the basic version of the pipeline I'm trying to employ:</div><div><br></div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! mux. pulsesrc device=2 ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'<br></div><div><br></div><div><br></div><div>Below are some observations from my experiments</div><div>- The CPU is not the limiting factor. In fact, when I run the pipeline and run `top' and `gnome-system-monitor' the reported cpu usage does not go above 30%</div><div>- <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">The audio drops are not caused by the audio recording device. </span>Using a `audiotestsrc' keeps frame drop warnings from being reported, but the output file still has audio dropping out.</div><div>- The audio drops are not caused by the recording medium. Using a `fakesink' </div><div>- The audio drops are not dependent on high video resolutions, they happen with both 1080p video and 480p. </div><div><div>- Adding queues many places does not improve performance </div><div>- Changing the container and the codecs (moving to theora and matroska) removes these audio drop issues, but this has other consequences such as needing more of the CPU resources to compress the video. </div><div><br></div><div>Here is my gstreamer version:</div><div><div>>gst-launch-1.0 --version</div><div>gst-launch-1.0 version 1.10.4</div><div>GStreamer 1.10.4</div><div><a href="http://packages.qa.debian.org/gstreamer1.0">http://packages.qa.debian.org/gstreamer1.0</a></div></div><div><br></div><div><br></div><div>Below are my experimental pipelines and the results observed.</div><div><br></div><div><div># Record C920 video and audio to a file</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'</div><div># Audio cuts out after 5 seconds and we also got "Can't record audio fast enough", no drop in CPU usage </div><div><br></div><div># Put the video audio recording infront of the video for recording C920 video and audio to a file</div><div>gst-launch-1.0 -v pulsesrc device=2 ! queue ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! queue ! audioconvert ! queue ! avenc_aac ! queue ! mux. v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'</div><div># Audio cuts out after 5 seconds and we also got "Can't record audio fast enough", no drop in CPU usage </div><div><br></div><div># Try a different mux for recording C920 video and audio to a file</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! avdec_h264 ! theoraenc ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! audioconvert ! queue ! avenc_aac ! queue ! mux. matroskamux name=mux ! filesink location='output.mkv'</div><div># Audio and video was in sync for the whole video and we also got "Can't record audio fast enough", but video looked bad and CPU usage was huge</div><div><br></div><div># Try the mp3 audio codec</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! audioconvert ! queue ! lamemp3enc ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'</div><div># Just flatout didn't start, perhaps I can only use AAC with the mp4 container</div><div><br></div><div># Try a test src</div><div>gst-launch-1.0 -v audiotestsrc ! queue ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! queue ! audioconvert ! queue ! avenc_aac ! queue ! mux. v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4' </div><div># Didn't get any frame drop errors but audio still drops out after 5 seconds</div><div><br></div><div># Try using a fake sink</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! fakesink</div><div># We still got "Can't record audio fast enough"</div><div><br></div><div># Try putting a queue between mpegtsmux and filesink</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location='output.mp4'</div><div># Audio drops out between 4 and 10 seconds and we also got "Can't record audio fast enough"</div><div><br></div><div># add sync=false at the sink</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-h264,width=1920,height=1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! queue ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location='output.mp4' sync=false</div><div># Audio cuts out at 4 seconds and we also got "Can't record audio fast enough"</div><div><br></div><div># Add provide-clock=false to pulsesrc from <a href="https://stackoverflow.com/questions/35744114/getting-warning-messages-from-alsasrc">https://stackoverflow.com/questions/35744114/getting-warning-messages-from-alsasrc</a></div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! mux. pulsesrc device=2 provide-clock=false ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location='output.mp4' sync=false</div><div># Doesn't help, no difference in performance Audio cuts out at 4 seconds and we also got "Can't record audio fast enough"</div><div><br></div><div># Changed some queues around</div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-h264,width=1920,height=1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,channels=2,rate=8000 ! queue ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location='output.mp4' sync=false</div><div># Audio falls out after 5 seconds we also got "Can't record audio fast enough", no difference in performance </div><div><br></div><div># try using "voaacenc bitrate=65536 ! aacparse" from <a href="https://stackoverflow.com/questions/23505166/use-gstreamer-to-stream-video-and-audio-of-logitech-c920">https://stackoverflow.com/questions/23505166/use-gstreamer-to-stream-video-and-audio-of-logitech-c920</a></div><div>gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-h264,width=1920,height=1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. pulsesrc device=2 ! audio/x-raw ! queue ! audioconvert ! queue ! voaacenc bitrate=65536 ! aacparse ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location='output.mp4' sync=false</div><div># Audio falls out after 5 seconds we also got "Can't record audio fast enough", no difference in performance </div></div><div><br></div><div>If you are intrigued by this issue please let me know your thoughts. </div><div><div class="gmail_signature"></div>
</div></div></div></div>