mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.74k stars 2.93k forks source link

Screenshots don't match ffmpeg PNG conversions #13561

Closed mariomadproductions closed 9 months ago

mariomadproductions commented 9 months ago

Important Information

Provide following Information:

If you're not using git master or the latest release, update. Releases are listed here: https://github.com/mpv-player/mpv/releases

Reproduction steps

Getting a PNG image of the first frame of a video using ffmpeg -i autodemoA.thp -vf "select=eq(n\,0)" -q:v 3 frame.png and using the screenshot function of mpv.

Expected behavior

Screenshots are the same.

Actual behavior

Screenshots differ.

Log file

$ cat ~/.config/mpv/mpv.conf 
screenshot-format=png
screenshot-directory="/home/user/system/screenshots/"
$ mpv --log-file=log.txt autodemoA.thp 
 (+) Video --vid=1 (thp 640x448 29.970fps)
 (+) Audio --aid=1 (adpcm_thp 2ch 32000Hz)
AO: [pulse] 32000Hz stereo 2ch s16
VO: [gpu] 640x448 yuv420p
(Paused) AV: 00:00:00 / 00:00:40 (0%) A-V:  0.000
Exiting... (Quit)

log.txt

$ ffmpeg -version
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --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-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --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-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --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-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

Sample files

autodemoA.thp frame.png mpv-shot0001.png comparison.png

CounterPillow commented 9 months ago

Why would they be the same? Screenshots, as far as I know, go through mpv's rendering pipeline.

mariomadproductions commented 9 months ago

Why would they be the same? Screenshots, as far as I know, go through mpv's rendering pipeline.

So going through the pipeline is a lossy process? Is there a way to get the frame before it goes through the pipeline?

CounterPillow commented 9 months ago

You're assuming that the way you're capturing screenshots right now in ffmpeg isn't "lossy" in some sense, which is not true. Your video is likely YCbCr with some chroma downscaling, if it's like any commonly found video. PNG is RGB, which means the chroma will be upscaled. What filter you use for upscaling is up to whatever does the conversion.

Even for the case of a 4:4:4 YCbCr video, you'd still be doing the conversion to RGB, and while there are matrices in standards for this there's nothing said about the numerical accuracy of the implementation.

mariomadproductions commented 9 months ago

I see. I guess I can't really get lossless screenshots then, best I can do is make sure use a consistent method between screenshots. Okay, I suppose this issue should be closed then. Thanks

llyyr commented 9 months ago

Try --profile=fast which should match ffmpeg scaling