<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m in a somewhat similar situation as you, working on a video player, using a more C approach versus C++ classes for all the data and logic. I write a hybrid, with classes, but minimally. I prefer C.  And I’m using wxWidgets with OpenGL, so there is very little hiding/encapsulation of my data handling.<div class=""><br class=""></div><div class=""><ul class="MailOutline"><li class="">In your “Init AV backend” I have additional calls to:</li><ul class=""><li class="">avdevice_register_all();   seems to be necessary for USB streams</li><li class="">avfilter_register_all();    you will want an avfilter graph to filter the stream of failed frames and similar error recovery</li><li class="">avformat_network_init();   if you’re playing IP streams, you’ll want this</li></ul><li class="">When you call <span style="font-family: CourierNewPSMT; font-size: 14px;" class="">sws_getContext()</span>, for your 3rd parameter pass in the videoCodecContext->pix_fmt. It’s value means “unset” and essentially tells sws to insure to return pixels in your desired format. </li><li class="">When using <span style="font-family: CourierNewPSMT; font-size: 14px;" class="">avcodec_send_packet() </span>one needs to use<span style="font-family: CourierNewPSMT; font-size: 14px;" class=""> avcodec_receive_frame(), </span>as that is the API design. Consider those two routines the in and out of a single algorithm. <span style="font-family: CourierNewPSMT; font-size: 14px;" class=""> </span></li><li class="">Also, due to buffering, you will want<font face="CourierNewPSMT" style="font-size: 14px;" class=""> avcodec_receive_frame() </font><font class="">called in a while loop, to drain the buffered frames after</font><font face="CourierNewPSMT" style="font-size: 14px;" class=""> av_read_Frame() </font><font class="">has indicated the stream EOF’ed or terminated. </font></li><li class=""><font class="">It also looks like you’re not using AVFilter yet, which I have found is critical to stable playback - and it replaces your use of sws_context… (with it’s own use of sws, but with a lot more logic around it)</font></li><li class="">Regardless of your using AVFilter or directly using sws, your pixel data is not guaranteed to always be a single continuous pixel buffer with all codecs. Your logic needs to look at each frame’s linesize[0] (in the case of RGB pixels) and compare that to your calculated correct number of expected bytes. If they match, then you have a continuous buffer for each pixel line. If they do not match, your logic needs to loop over the pixel buffer copying the pixels from each row start, because each row can have additional bytes that are not image pixels at the end of the pixel row.</li></ul><div class=""><br class=""></div></div><div class="">I don’t know when you started working on your player, but it looks from reading your comments, you are just a few beats behind my figuring all this out. I can’t share my code directly with you, but keep posting. The advice from others looks correct, but as you point out, you’re working in C, and C++ encapsulation is just hiding details you want to see. </div><div class="">  <br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-family: Arial; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><font class="Apple-style-span" face="Arial"><span class="Apple-style-span"><font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px;"><div style="margin: 0px;" class=""><font face="Helvetica" size="3" style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: Helvetica;" class=""><font class="Apple-style-span" color="#0000FF">Sincerely,</font></font></div><div style="margin: 0px;" class=""><font face="Helvetica" size="3" style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: Helvetica;" class=""><font class="Apple-style-span" color="#0000FF">-Blake Senftner</font></font></div><div style="margin: 0px;" class=""><font class="Apple-style-span" color="#0000FF">Computer Scientist </font></div><div style="margin: 0px;" class=""><br class=""></div></span></font></span></font></span></div></span></div></span></div></span></div></span></div></span></div></span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 5, 2017, at 9:09 AM, Jan <<a href="mailto:jan@dwrox.net" class="">jan@dwrox.net</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On 05.02.2017 17:34, Gonzalo Garramuño wrote:</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><br class="">El 05/02/17 a las 12:07, Jan escribió:<br class=""><blockquote type="cite" class="">Hello,<br class=""><br class="">Im currently working on a video player software, which should be based<br class="">on ffmpeg tools and at the moment of writing, using SDL2 for display<br class="">of the video content.<br class=""><br class="">The documentation for ffmpeg is a bit difficult to get through, as<br class="">most example code seems to be outdated or using deprecated features.<br class="">The SDL tutorial is also not valid anymore, as well as the updated<br class="">version on Github or other information which can be found using a<br class="">search engine of choice.<br class=""><br class="">What am I missing out here, the alignment?<br class=""></blockquote>You are missing several things.  First you need to call<br class="">avcodec_receive_frame to get the returned frame after<br class="">avcodec_send_packet.  See the docs for the function and this blog.<br class=""><br class=""><a href="https://blogs.gentoo.org/lu_zero/2016/03/29/new-avcodec-api/" class="">https://blogs.gentoo.org/lu_zero/2016/03/29/new-avcodec-api/</a><br class=""><br class="">Also, you don't need to set anything to writable or check for it.<br class="">Finally, I would look at the code in ffplay.c as it is now compatible<br class="">with sdl2, I believe.<br class=""><br class=""></blockquote><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The blog does give litte information from what I have looked over. There is no example on how to initialize anything.</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">FFPlay works on my Linux machine, but is so cluttered, that I dont want to use it, and yes, it does the job. Unfortunately its as whole not simple and intuitive as what to use the features.</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">My code is error prone for some formats, but its much clearer to understand on what has to memory allocated and done in order to get working frames.</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The code you provide in your seconds post, c++, is no option.</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I am working with C - so I dont use BoostLib or similar. Its also not an explanation (for me) to use Boost lib as dependency to get things going.</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I appreciate your help, but its simply not the solution, yet.</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Perhaps there is a more like C approach on how to get the setup ready?</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Libav-user mailing list</span><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:Libav-user@ffmpeg.org" style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Libav-user@ffmpeg.org</a><br style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://ffmpeg.org/mailman/listinfo/libav-user" style="font-family: CourierNewPSMT; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://ffmpeg.org/mailman/listinfo/libav-user</a></div></blockquote></div><br class=""></div></body></html>