<div dir="ltr">James, Nicolas, <div><br></div><div>Thank you for your replies. I have increased the queue length after the h264parse and that enables the pipeline to record video and audio well beyond the 5 second limit being experienced before. Below is the final pipeline. Notice I have removed the formatting of the audio and the device id changed when I removed the webcam and plugged it back it. </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 max-size-buffers=0 max-size-bytes=0 max-size-time=1000000000 ! mux. pulsesrc device=7 ! audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'<br></div><div><br></div><div>This problem is now resolved. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 17, 2018 at 10:54 AM, Nicolas Dufresne <span dir="ltr"><<a href="mailto:nicolas@ndufresne.ca" target="_blank">nicolas@ndufresne.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Le dimanche 17 juin 2018 à 20:44 +1000, James Cameron a écrit :<br>
> On Sat, Jun 16, 2018 at 08:17:18PM -0700, W.A. Garrett Weaver wrote:<br>
> > I want to take audio and video from a webcam and record it to an mp4 file. When<br>
> > I attempt to do this audio cuts out 5 seconds after the recording starts and<br>
> > gstreamer reports:<br>
> > > WARNING: from element /GstPipeline:pipeline0/<wbr>GstPulseSrc:pulsesrc0: Can't<br>
> > <br>
> > record audio fast enough<br>
> > > Dropped 22932 samples. This is most likely because downstream can't keep up<br>
> > <br>
> > and is consuming samples too slowly.<br>
> <br>
> I had that too.<br>
> <br>
> > I have the Logitech C920, which has the really nice feature of providing h.264<br>
> > video directly so the CPU doesn't need to compress it before writing it out to<br>
> > a file. I suspect that I am either missing something that needs to be in the<br>
> > pipeline to either either buffer out the streams, force everything to stay in<br>
> > sink or there is an option that needs to be added to mpegtsmux, but I don't<br>
> > know enough about gstreamer to know what would be. <br>
> > <br>
> > Here is the basic version of the pipeline I'm trying to employ:<br>
> > <br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! filesink<br>
> > location='output.mp4'<br>
> <br>
> In my tests, I fixed it with two changes;<br>
> <br>
> 1.  add a videorate element after v4l2src, because a camera may not always generate a constant frame rate even if the source has negotiated to do so; although in my case the video was not already encoded, it was raw,<br>
<br>
</span>This is not applicable in this context, because videorate won't accept<br>
H264.<br>
<span class=""><br>
> <br>
> 2.  increase the size of the queues before the mux, as the defaults were quite small,<br>
<br>
</span>This is likely what is happening. The queue size won't old the HW<br>
initialization delay of the C920 (which can be up to 5s). Dropping any<br>
H264 frames will directly lead to broken video. Have a try the<br>
following configuration:<br>
<br>
  v4l2src ! h264parse ! queue max-size-buffers=0 max-size-bytes=0 max-<br>
size-time=1000000000 ! ...<br>
<br>
If you have GStreamer <= 1.12, you  might need even longer queue<br>
duration.<br>
<div class="HOEnZb"><div class="h5"><br>
> <br>
> 3.  when autovideosink was also used, place a videorate ahead of it to limit the display framerate; you're not using a display sink, so this shouldn't matter for you.<br>
> <br>
> I was also going to check that the audio data was being sampled at the correct rate; but didn't need to go that far.  I was working with prototype hardware where I wasn't at the time sure that 8000 samples at 8000 Hz would be one second long; i.e. bad audio codec clocks.<br>
> <br>
> > Below are some observations from my experiments<br>
> > - The CPU is not the limiting factor. In fact, when I run the pipeline and run<br>
> > `top' and `gnome-system-monitor' the reported cpu usage does not go above 30%<br>
> > - The audio drops are not caused by the audio recording device. Using a<br>
> > `audiotestsrc' keeps frame drop warnings from being reported, but the output<br>
> > file still has audio dropping out.<br>
> > - The audio drops are not caused by the recording medium. Using a `fakesink' <br>
> > - The audio drops are not dependent on high video resolutions, they happen with<br>
> > both 1080p video and 480p. <br>
> > - Adding queues many places does not improve performance <br>
> > - Changing the container and the codecs (moving to theora and matroska) removes<br>
> > these audio drop issues, but this has other consequences such as needing more<br>
> > of the CPU resources to compress the video. <br>
> > <br>
> > Here is my gstreamer version:<br>
> > > gst-launch-1.0 --version<br>
> > <br>
> > gst-launch-1.0 version 1.10.4<br>
> > GStreamer 1.10.4<br>
> > [1]<a href="http://packages.qa.debian.org/gstreamer1.0" rel="noreferrer" target="_blank">http://packages.qa.debian.<wbr>org/gstreamer1.0</a><br>
> > <br>
> > Below are my experimental pipelines and the results observed.<br>
> > <br>
> > # Record C920 video and audio to a file<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 ! audioconvert ! queue !<br>
> > avenc_aac ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'<br>
> > # Audio cuts out after 5 seconds and we also got "Can't record audio fast<br>
> > enough", no drop in CPU usage <br>
> > <br>
> > # Put the video audio recording infront of the video for recording C920 video<br>
> > and audio to a file<br>
> > gst-launch-1.0 -v pulsesrc device=2 ! queue ! audio/x-raw,format=S16LE,<wbr>channels<br>
> > =2,rate=8000 ! queue ! audioconvert ! queue ! avenc_aac ! queue ! mux. v4l2src<br>
> > device=/dev/video1 ! queue ! video/x-h264,width=1920,<wbr>height=1080,framerate=30/1<br>
> > ! queue ! h264parse ! queue ! mux. mpegtsmux name=mux ! filesink location=<br>
> > 'output.mp4'<br>
> > # Audio cuts out after 5 seconds and we also got "Can't record audio fast<br>
> > enough", no drop in CPU usage <br>
> > <br>
> > # Try a different mux for recording C920 video and audio to a file<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! avdec_h264 ! theoraenc ! queue !<br>
> > mux. pulsesrc device=2 ! audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 !<br>
> > audioconvert ! queue ! avenc_aac ! queue ! mux. matroskamux name=mux ! filesink<br>
> > location='output.mkv'<br>
> > # Audio and video was in sync for the whole video and we also got "Can't record<br>
> > audio fast enough", but video looked bad and CPU usage was huge<br>
> > <br>
> > # Try the mp3 audio codec<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 ! audioconvert ! queue !<br>
> > lamemp3enc ! queue ! mux. mpegtsmux name=mux ! filesink location='output.mp4'<br>
> > # Just flatout didn't start, perhaps I can only use AAC with the mp4 container<br>
> > <br>
> > # Try a test src<br>
> > gst-launch-1.0 -v audiotestsrc ! queue ! audio/x-raw,format=S16LE,<wbr>channels=<br>
> > 2,rate=8000 ! queue ! audioconvert ! queue ! avenc_aac ! queue ! mux. v4l2src<br>
> > device=/dev/video1 ! queue ! video/x-h264,width=1920,<wbr>height=1080,framerate=30/1<br>
> > ! queue ! h264parse ! queue ! mux. mpegtsmux name=mux ! filesink location=<br>
> > 'output.mp4' <br>
> > # Didn't get any frame drop errors but audio still drops out after 5 seconds<br>
> > <br>
> > # Try using a fake sink<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 ! audioconvert ! queue !<br>
> > avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! fakesink<br>
> > # We still got "Can't record audio fast enough"<br>
> > <br>
> > # Try putting a queue between mpegtsmux and filesink<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 ! audioconvert ! queue !<br>
> > avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location=<br>
> > 'output.mp4'<br>
> > # Audio drops out between 4 and 10 seconds and we also got "Can't record audio<br>
> > fast enough"<br>
> > <br>
> > # add sync=false at the sink<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-h264,width=1920,<wbr>height=<br>
> > 1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 ! queue ! audioconvert ! queue !<br>
> > avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location=<br>
> > 'output.mp4' sync=false<br>
> > # Audio cuts out at 4 seconds and we also got "Can't record audio fast enough"<br>
> > <br>
> > # Add provide-clock=false to pulsesrc from [2]<a href="https://stackoverflow.com/" rel="noreferrer" target="_blank">https://stackoverflow.com/</a><br>
> > questions/35744114/getting-<wbr>warning-messages-from-alsasrc<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! queue ! video/x-h264,width=<br>
> > 1920,height=1080,framerate=30/<wbr>1 ! h264parse ! queue ! mux. pulsesrc device=2<br>
> > provide-clock=false ! audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 !<br>
> > audioconvert ! queue ! avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue !<br>
> > filesink location='output.mp4' sync=false<br>
> > # Doesn't help, no difference in performance Audio cuts out at 4 seconds and we<br>
> > also got "Can't record audio fast enough"<br>
> > <br>
> > # Changed some queues around<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-h264,width=1920,<wbr>height=<br>
> > 1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw,format=S16LE,<wbr>channels=2,rate=8000 ! queue ! audioconvert ! queue !<br>
> > avenc_aac ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location=<br>
> > 'output.mp4' sync=false<br>
> > # Audio falls out after 5 seconds we also got "Can't record audio fast enough",<br>
> > no difference in performance <br>
> > <br>
> > # try using "voaacenc bitrate=65536 ! aacparse" from [3]https://<br>
> > <a href="http://stackoverflow.com/questions/23505166/" rel="noreferrer" target="_blank">stackoverflow.com/questions/<wbr>23505166/</a><br>
> > use-gstreamer-to-stream-video-<wbr>and-audio-of-logitech-c920<br>
> > gst-launch-1.0 -v v4l2src device=/dev/video1 ! video/x-h264,width=1920,<wbr>height=<br>
> > 1080,framerate=30/1 ! queue ! h264parse ! queue ! mux. pulsesrc device=2 !<br>
> > audio/x-raw ! queue ! audioconvert ! queue ! voaacenc bitrate=65536 ! aacparse<br>
> > ! queue ! mux. mpegtsmux name=mux ! queue ! filesink location='output.mp4' sync<br>
> > =false<br>
> > # Audio falls out after 5 seconds we also got "Can't record audio fast enough",<br>
> > no difference in performance <br>
> > <br>
> > If you are intrigued by this issue please let me know your thoughts. <br>
> > <br>
> > References:<br>
> > <br>
> > [1] <a href="http://packages.qa.debian.org/gstreamer1.0" rel="noreferrer" target="_blank">http://packages.qa.debian.org/<wbr>gstreamer1.0</a><br>
> > [2] <a href="https://stackoverflow.com/questions/35744114/getting-warning-messages-from-alsasrc" rel="noreferrer" target="_blank">https://stackoverflow.com/<wbr>questions/35744114/getting-<wbr>warning-messages-from-alsasrc</a><br>
> > [3] <a href="https://stackoverflow.com/questions/23505166/use-gstreamer-to-stream-video-and-audio-of-logitech-c920" rel="noreferrer" target="_blank">https://stackoverflow.com/<wbr>questions/23505166/use-<wbr>gstreamer-to-stream-video-and-<wbr>audio-of-logitech-c920</a><br>
> > ______________________________<wbr>_________________<br>
> > gstreamer-devel mailing list<br>
> > <a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.<wbr>freedesktop.org</a><br>
> > <a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/gstreamer-<wbr>devel</a><br>
> <br>
> <br>
______________________________<wbr>_________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.<wbr>freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/gstreamer-<wbr>devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div><strong>W.A. Garrett Weaver </strong></div>
<div><a href="mailto:weaverg@email.arizona.edu" target="_blank">weaverg@email.arizona.edu</a></div></div>
</div>