<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:2072919356;
        mso-list-type:hybrid;
        mso-list-template-ids:570032164 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">First-time listener, first-time caller.  Thanks for your patience.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m trying to replace an old inherited piece of code that uses Python’s OpenCV bindings with FFMPEG on the back-end, to record and transcode video from IP cameras*.  My goal is to write C++ code against libav* and get rid of both Python
 and OpenCV in this instance, as this was very much a “we used what we know” approach and isn’t well-suited to developments we’d like to make.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The problem I’m encountering is, while my code successfully receives frames from the cameras and writes an MP4 file as output, and the first frames are crystal-clear, very quickly the video becomes “blocky” (what I would call compression
 artifacts) and never clears up.  The old system records video that stays crystal-clear throughout.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If I ffprobe a video recorded by the old system and the video recorded by my new code, the output is near identical except for bitrates, which are not far different from each other (included below).  I’ve read several threads about similar
 complaints which mention bitrates; while the explanation makes sense, the nearly-same bitrates that ffprobe reports doesn’t support the hypothesis.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m a complete neophyte in the realm of digital video and I’m sure there’s just some knob I haven’t turned properly, but I’d really appreciate some knowledgeable help in figuring out what it is.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ffprobe of a clear video:<o:p></o:p></p>
<p class="MsoNormal">ffprobe version 4.3.6-0+deb11u1 Copyright (c) 2007-2023 the FFmpeg developers<o:p></o:p></p>
<p class="MsoNormal">  built with gcc 10 (Debian 10.2.1-6)<o:p></o:p></p>
<p class="MsoNormal">  configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample
 --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme
 --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr
 --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi
 --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared<o:p></o:p></p>
<p class="MsoNormal">  libavutil      56. 51.100 / 56. 51.100<o:p></o:p></p>
<p class="MsoNormal">  libavcodec     58. 91.100 / 58. 91.100<o:p></o:p></p>
<p class="MsoNormal">  libavformat    58. 45.100 / 58. 45.100<o:p></o:p></p>
<p class="MsoNormal">  libavdevice    58. 10.100 / 58. 10.100<o:p></o:p></p>
<p class="MsoNormal">  libavfilter     7. 85.100 /  7. 85.100<o:p></o:p></p>
<p class="MsoNormal">  libavresample   4.  0.  0 /  4.  0.  0<o:p></o:p></p>
<p class="MsoNormal">  libswscale      5.  7.100 /  5.  7.100<o:p></o:p></p>
<p class="MsoNormal">  libswresample   3.  7.100 /  3.  7.100<o:p></o:p></p>
<p class="MsoNormal">  libpostproc    55.  7.100 / 55.  7.100<o:p></o:p></p>
<p class="MsoNormal">Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '458272.mp4':<o:p></o:p></p>
<p class="MsoNormal">  Metadata:<o:p></o:p></p>
<p class="MsoNormal">    major_brand     : isom<o:p></o:p></p>
<p class="MsoNormal">    minor_version   : 512<o:p></o:p></p>
<p class="MsoNormal">    compatible_brands: isomiso2mp41<o:p></o:p></p>
<p class="MsoNormal">    encoder         : Lavf59.27.100<o:p></o:p></p>
<p class="MsoNormal">  Duration: 00:00:38.00, start: 0.000000, bitrate: 1256 kb/s<o:p></o:p></p>
<p class="MsoNormal">    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1255 kb/s, 10 fps, 10 tbr, 10240 tbn, 10 tbc (default)<o:p></o:p></p>
<p class="MsoNormal">    Metadata:<o:p></o:p></p>
<p class="MsoNormal">      handler_name    : VideoHandler<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ffprobe of the one that gets blocky:<o:p></o:p></p>
<p class="MsoNormal">ffprobe version 4.3.6-0+deb11u1 Copyright (c) 2007-2023 the FFmpeg developers<o:p></o:p></p>
<p class="MsoNormal">  built with gcc 10 (Debian 10.2.1-6)<o:p></o:p></p>
<p class="MsoNormal">  configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample
 --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme
 --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr
 --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi
 --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared<o:p></o:p></p>
<p class="MsoNormal">  libavutil      56. 51.100 / 56. 51.100<o:p></o:p></p>
<p class="MsoNormal">  libavcodec     58. 91.100 / 58. 91.100<o:p></o:p></p>
<p class="MsoNormal">  libavformat    58. 45.100 / 58. 45.100<o:p></o:p></p>
<p class="MsoNormal">  libavdevice    58. 10.100 / 58. 10.100<o:p></o:p></p>
<p class="MsoNormal">  libavfilter     7. 85.100 /  7. 85.100<o:p></o:p></p>
<p class="MsoNormal">  libavresample   4.  0.  0 /  4.  0.  0<o:p></o:p></p>
<p class="MsoNormal">  libswscale      5.  7.100 /  5.  7.100<o:p></o:p></p>
<p class="MsoNormal">  libswresample   3.  7.100 /  3.  7.100<o:p></o:p></p>
<p class="MsoNormal">  libpostproc    55.  7.100 / 55.  7.100<o:p></o:p></p>
<p class="MsoNormal">Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':<o:p></o:p></p>
<p class="MsoNormal">  Metadata:<o:p></o:p></p>
<p class="MsoNormal">    major_brand     : isom<o:p></o:p></p>
<p class="MsoNormal">    minor_version   : 512<o:p></o:p></p>
<p class="MsoNormal">    compatible_brands: isomiso2mp41<o:p></o:p></p>
<p class="MsoNormal">    encoder         : Lavf58.45.100<o:p></o:p></p>
<p class="MsoNormal">  Duration: 00:00:05.00, start: 0.000000, bitrate: 1971 kb/s<o:p></o:p></p>
<p class="MsoNormal">    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1970 kb/s, 10.20 fps, 10 tbr, 10240 tbn, 10 tbc (default)<o:p></o:p></p>
<p class="MsoNormal">    Metadata:<o:p></o:p></p>
<p class="MsoNormal">      handler_name    : VideoHandler<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Especially odd to me is the fact that my blocky video has a higher bitrate than the clear one.  In capturing new examples, I also noticed that my code is doing something bizarre with the chroma channel, too.  Here are links to screenshots.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1">One frame directly from the camera:
<a href="https://imgur.com/BqD6bPe">https://imgur.com/BqD6bPe</a><o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1">A screenshot of video from the old system:
<a href="https://imgur.com/K5aPZyZ">https://imgur.com/K5aPZyZ</a><o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1">A screenshot of video from my code, also showing the channels aren’t in alignment either:
<a href="https://imgur.com/kbHUlYw">https://imgur.com/kbHUlYw</a><o:p></o:p></li></ol>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks for any and all guidance!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Brian<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">* - very simplified view of the situation<o:p></o:p></p>
</div>
</body>
</html>