<div dir="ltr">Thank you very much Nicolas!<div><br></div><div>videoconvert element worked for me. Also " v4l2video8convert ! v4l2h264enc output-io-mode=dmabuf-import" helped to reduce the CPU usage by 2-3%.</div><div><br></div><div>I think I am ok with what I have for now, thank you very much!</div><div><br></div><div>Having said that, I can proceed further with "GST_DEBUG="v4l2*:7"" to attempt to see if zero copy possible with my USB camera source? </div><div>Please advise if you are okay with that. What exact log would be interesting to observe?</div><div><br></div><div>Thank you very much,</div><div> -- Constantine.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 20, 2020 at 9:32 PM Nicolas Dufresne <<a href="mailto:nicolas@ndufresne.ca">nicolas@ndufresne.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Le lundi 20 janvier 2020 à 20:13 +0200, Constantine Elster a écrit :<br>
> Hi Nicolas,<br>
> <br>
> Thank you very much!! <br>
> <br>
> I removed output-io-mode=dmabuf-import from v4l2video8convert and v4l2h264enc<br>
> elements and got the pipeline working!<br>
> This pipeline worked for me: gst-launch-1.0 -vvv v4l2src device="/dev/video9"<br>
> num-buffers=1000 ! "video/x-raw, format=(string)UYVY, width=(int)640,<br>
> height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)45/1,<br>
> colorimetry=bt709" ! v4l2video8convert ! v4l2h264enc ! h264parse ! mp4mux !<br>
> filesink location=aha.mp4<br>
> <br>
> I get about 15% CPU usage with the above pipeline, though I get few dropped<br>
> frames in the output file.<br>
<br>
That might go away with a 'queue' between v4l2src and v4l2video8convert.<br>
<br>
> <br>
> So, the next step I want to perform few optimizations.<br>
> 1) I set the io-mode=dmabuf-import on the v4l2src element though I get this<br>
> error: <br>
> ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed to<br>
> allocate required memory.<br>
> Additional debug info:<br>
> gstv4l2src.c(658): gst_v4l2src_decide_allocation ():<br>
> /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:<br>
> Buffer pool activation failed<br>
> <br>
> So, I presume 0memcopy is not possible?<br>
<br>
I guess not indeed. Would be nice to learn more (GST_DEBUG="v4l2*:7"). Though I<br>
know UVC driver is not flexible at all. Also, buffer importation code isn't safe<br>
in older release of GStreamer. On the good side, the copy is made with a<br>
virtually allocated buffer as source, so it fairly fast.<br>
<br>
> <br>
> 2) I would like to drop frames as close as possible to the v4l2 source to<br>
> achieve 10 fps at the input of the encoder. Though my v4l2 src accepts only 45<br>
> and 60 fps configuration. Is there an elegant way to reduce the frame rate<br>
> this way?<br>
<br>
I'd use "videorate drop-only=0 ! <caps filter with framerate=10/1>". <br>
<br>
> <br>
> 3) Any other recommendations I can pursue to optimize the pipeline?<br>
<br>
You can try to enable 0 copy between v4l2video8convert and v4l2h264enc. Two<br>
options:<br>
<br>
v4l2video8convert capture-io-mode=dmabuf-import ! v4l2h264enc<br>
v4l2video8convert ! v4l2h264enc output-io-mode=dmabuf-import<br>
<br>
> <br>
> Thank you very very much,<br>
> -- Constantine.<br>
> <br>
> <br>
> On Sun, Jan 19, 2020 at 7:57 PM Nicolas Dufresne <<a href="mailto:nicolas@ndufresne.ca" target="_blank">nicolas@ndufresne.ca</a>> wrote:<br>
> > Le dimanche 19 janvier 2020 à 15:12 +0200, Constantine Elster a écrit :<br>
> > > Thank you very much Milian! Looks better with h264parse. Still getting an<br>
> > error, though now different one.<br>
> > > <br>
> > > I added h264parse to the pipeline:<br>
> > > gst-launch-1.0 -vvv v4l2src device="/dev/video9" num-buffers=200 !<br>
> > "video/x-raw, format=(string)UYVY, width=(int)640, height=(int)480, pixel-<br>
> > aspect-ratio=(fraction)1/1, framerate=(fraction)60/1, colorimetry=bt709" !<br>
> > v4l2video8convert output-io-mode=dmabuf-import ! v4l2h264enc output-io-<br>
> > mode=dmabuf-import ! h264parse ! mp4mux ! filesink location=aha.mp4<br>
> > > <br>
> > > Output:<br>
> > > Setting pipeline to PAUSED ...<br>
> > > Pipeline is live and does not need PREROLL ...<br>
> > > Setting pipeline to PLAYING ...<br>
> > > New clock: GstSystemClock<br>
> > > /GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, <br>
> > format=(string)UYVY, width=(int)640, height=(int)480, pixel-aspect-<br>
> > ratio=(fraction)1/1, framerate=(fraction)60/1, colorimetry=(string)bt709,<br>
> > interlace-mode=(string)progressive<br>
> > > /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps =<br>
> > video/x-raw, format=(string)UYVY, width=(int)640, height=(int)480, pixel-<br>
> > aspect-ratio=(fraction)1/1, framerate=(fraction)60/1,<br>
> > colorimetry=(string)bt709, interlace-mode=(string)progressive<br>
> > > /GstPipeline:pipeline0/v4l2video8convert:v4l2video8convert0.GstPad:src:<br>
> > caps = video/x-raw, framerate=(fraction)60/1, interlace-<br>
> > mode=(string)progressive, format=(string)I420, width=(int)640,<br>
> > height=(int)480, colorimetry=(string)bt709<br>
> > > /GstPipeline:pipeline0/v4l2h264enc:v4l2h264enc0.GstPad:src: caps =<br>
> > video/x-h264, stream-format=(string)byte-stream, alignment=(string)au,<br>
> > profile=(string)baseline, level=(string)4, width=(int)640, height=(int)480,<br>
> > pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)60/1, interlace-<br>
> > mode=(string)progressive, colorimetry=(string)bt709<br>
> > > /GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:sink: caps =<br>
> > video/x-h264, stream-format=(string)byte-stream, alignment=(string)au,<br>
> > profile=(string)baseline, level=(string)4, width=(int)640, height=(int)480,<br>
> > pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)60/1, interlace-<br>
> > mode=(string)progressive, colorimetry=(string)bt709<br>
> > > Redistribute latency...<br>
> > > /GstPipeline:pipeline0/v4l2h264enc:v4l2h264enc0.GstPad:sink: caps =<br>
> > video/x-raw, framerate=(fraction)60/1, interlace-mode=(string)progressive,<br>
> > format=(string)I420, width=(int)640, height=(int)480,<br>
> > colorimetry=(string)bt709<br>
> > > /GstPipeline:pipeline0/v4l2video8convert:v4l2video8convert0.GstPad:sink:<br>
> > caps = video/x-raw, format=(string)UYVY, width=(int)640, height=(int)480,<br>
> > pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)60/1,<br>
> > colorimetry=(string)bt709, interlace-mode=(string)progressive<br>
> > > /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps =<br>
> > video/x-raw, format=(string)UYVY, width=(int)640, height=(int)480, pixel-<br>
> > aspect-ratio=(fraction)1/1, framerate=(fraction)60/1,<br>
> > colorimetry=(string)bt709, interlace-mode=(string)progressive<br>
> > > ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal<br>
> > data stream error.<br>
> > > Additional debug info:<br>
> > > gstbasesrc.c(3055): gst_base_src_loop ():<br>
> > /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:<br>
> > > streaming stopped, reason error (-5)<br>
> > <br>
> > Looks like the real error was not propagated (let me know which version you<br>
> > are<br>
> > using, Ubuntu tends to be far behind, or only cherry-picking fixes rather<br>
> > then<br>
> > tracking stable branches).<br>
> > <br>
> > To find our more, set GST_DEBUG="v4l2*:7" env. That will give you a lot more<br>
> > details. By experience, I suspect that your output-io-mode=dmabuf-import is<br>
> > faulty on the v4l2convert element (on newer GStreamer, we now have a fix<br>
> > name<br>
> > for converter too). <br>
> > <br>
> > IMX.6 platform (and IMX.8 too) didn't include an IOMMU in their platform. On<br>
> > the<br>
> > other side, USB cameras (like UVC) produces scattered memory (virtual<br>
> > memory).<br>
> > That makes importation of dmabuf from UVC to v4l2convert impossible in this<br>
> > case. You may want to try the other way around, to set io-mode=dmabuf-import <br>
> > on<br>
> > the v4l2src element. If that does not work, you'll have no choice but to let<br>
> > the<br>
> > pipelein makes a copy (default setting). Normally, I suggest to first try<br>
> > without touching these advance settings, to make it work, and then tweak to<br>
> > gain<br>
> > more performance.<br>
> > <br>
> > > Execution ended after 0:00:00.436501205<br>
> > > Setting pipeline to PAUSED ...<br>
> > > Setting pipeline to READY ...<br>
> > > Setting pipeline to NULL ...<br>
> > > Freeing pipeline ...<br>
> > > <br>
> > > Any hint on debugging would be appreciated!<br>
> > > Thank you,<br>
> > > -- Constantine.<br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > On Sun, Jan 19, 2020 at 2:13 PM Milian Wolff <<a href="mailto:milian.wolff@kdab.com" target="_blank">milian.wolff@kdab.com</a>><br>
> > wrote:<br>
> > > > On Sonntag, 19. Januar 2020 11:06:55 CET Constantine Elster wrote:<br>
> > > > > Hi devs,<br>
> > > > > <br>
> > > > > I'm trying to construct a pipeline that captures frames from a USB<br>
> > camera<br>
> > > > > (YUV) and encodes them with HW encoder and saves into a file. My setup<br>
> > is<br>
> > > > > iMX6 board running Ubuntu 18.04 on 4.20 mainline kernel.<br>
> > > > > <br>
> > > > > When I try a sw encoder, it works okay albeit I get very high 100% CPU<br>
> > > > > usage. The working pipeline based on software plugins:<br>
> > > > > gst-launch-1.0 -v v4l2src device="/dev/video2" num-buffers=200 !<br>
> > > > > "video/x-raw, format=(string)UYVY, width=(int)640, height=(int)480,<br>
> > > > > pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)45/1,<br>
> > > > > colorimetry=bt709" ! videoconvert ! x264enc ! mp4mux ! filesink<br>
> > > > > location=aha.mp4<br>
> > > > > <br>
> > > > > My attempt to replace sw based plugins by HW based with efficient<br>
> > memory<br>
> > > > > management:<br>
> > > > > gst-launch-1.0 -v v4l2src device="/dev/video9" num-buffers=200 !<br>
> > > > > "video/x-raw, format=(string)UYVY, width=(int)640, height=(int)480,<br>
> > > > > pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)45/1,<br>
> > > > > colorimetry=bt709" ! *v4l2video8convert* *output-io-mode=dmabuf-<br>
> > import* !<br>
> > > > > *v4l2h264enc* *output-io-mode=dmabuf-import* ! mp4mux ! filesink<br>
> > > > > location=aha.mp4<br>
> > > > > <br>
> > > > > I get the following error: "WARNING: erroneous pipeline: could not<br>
> > link<br>
> > > > > v4l2h264enc0 to mp4mux0"<br>
> > > > > <br>
> > > > > Would appreciate any ideas how to understand what's wrong, how to<br>
> > debug and<br>
> > > > > make it work.<br>
> > > > <br>
> > > > To debug, I suggest you compare the SRC of `gst-inspect-1.0 v4l2h264enc`<br>
> > with <br>
> > > > the SINK of `gst-inspect-1.0 mp4mux`. My guess is that you may be able<br>
> > to fix <br>
> > > > the issue by adding a `h264parse` element in the middle to fix the<br>
> > alignment <br>
> > > > since `mp4mux` requires `au` alignment, whereas the encoder may output<br>
> > `nal` <br>
> > > > frames?<br>
> > > > <br>
> > > > Good luck<br>
> > > > <br>
> > > > -- <br>
> > > > Milian Wolff | <a href="mailto:milian.wolff@kdab.com" target="_blank">milian.wolff@kdab.com</a> | Senior Software Engineer<br>
> > > > KDAB (Deutschland) GmbH, a KDAB Group company<br>
> > > > Tel: +49-30-521325470<br>
> > > > KDAB - The Qt, C++ and OpenGL Experts<br>
> > > <br>
> > > <br>
> > > _______________________________________________<br>
> > > gstreamer-devel mailing list<br>
> > > <a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
> > > <a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
> > <br>
> > _______________________________________________<br>
> > gstreamer-devel mailing list<br>
> > <a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
> > <a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
> <br>
> <br>
> _______________________________________________<br>
> gstreamer-devel mailing list<br>
> <a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
<br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><font color="#666666"><br></font></div><font color="#666666">Director, Software Engineering</font><div><font color="#666666"><i><a href="http://www.valerann.com" target="_blank">www.valerann.com</a></i></font><div><font color="#888888"><br></font><span style="color:rgb(136,136,136)"><div dir="ltr"><img src="https://drive.google.com/a/valerann.com/uc?id=1cUa5VQGZCb9MrjxREFelyMkD3jH9H2Yx&export=download" width="96" height="96" style="color: rgb(34, 34, 34);"><span style="color:rgb(153,153,153);font-size:12.8px"> </span><span style="color:rgb(153,153,153);font-size:x-small;font-family:arial,helvetica,sans-serif"><a href="https://www.ces.tech/Innovation-Awards/Honorees/2020/Best-Of/T/The-Valerann-Smart-Roads-System.aspx" style="color:rgb(17,85,204)" target="_blank"><img src="https://drive.google.com/a/valerann.com/uc?id=1Oz_UDdgdrtleGGbfg5QoGBcrqC5Ni-Et&export=download" width="69" height="96"></a></span><br></div></span></div></div></div></div>