[Libav-user] Newbie hand-holding question: MJPEG to MPEG4 becomes "blocky"

Brian Henning bhenning at baebies.com
Tue May 23 20:20:48 EEST 2023


Hi,

First-time listener, first-time caller.  Thanks for your patience.

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.

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.

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.

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.

ffprobe of a clear video:
ffprobe version 4.3.6-0+deb11u1 Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  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
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '458272.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.27.100
  Duration: 00:00:38.00, start: 0.000000, bitrate: 1256 kb/s
    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)
    Metadata:
      handler_name    : VideoHandler

ffprobe of the one that gets blocky:
ffprobe version 4.3.6-0+deb11u1 Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  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
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 1971 kb/s
    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)
    Metadata:
      handler_name    : VideoHandler


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.


  1.  One frame directly from the camera: https://imgur.com/BqD6bPe
  2.  A screenshot of video from the old system: https://imgur.com/K5aPZyZ
  3.  A screenshot of video from my code, also showing the channels aren't in alignment either: https://imgur.com/kbHUlYw

Thanks for any and all guidance!

-Brian


* - very simplified view of the situation
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230523/ba4a23b1/attachment.htm>


More information about the Libav-user mailing list