Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6574 closed defect (invalid)

ffmpeg butchers video quality when downscaling

Reported by: Artem S. Tashkinov Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: even if I choose crf 0 (!) the resulting video is extremely blurry and there's a huge loss of details.

How to reproduce:

ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.5.4 (GCC)
  configuration: --disable-static --enable-nonfree --enable-avfilter --enable-shared --enable-gpl --enable-postproc --enable-pthreads --enable-libspeex --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-libopus --enable-libopenjpeg --disable-debug --disable-doc --enable-libpulse --extra-cflags='-march=native' --extra-ldflags='-Wl,-O1 -Wl,--hash-style=gnu -Wl,--enable-new-dtags' --enable-version3 --enable-libvorbis --enable-libfdk-aac --enable-x11grab --enable-gnutls --enable-libfreetype --enable-libx265
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, matroska,webm, from 'source.mkv':
  Metadata:
    ENCODER         : Lavf57.56.100
  Duration: 00:00:14.43, start: 0.000000, bitrate: 5636 kb/s
    Chapter #0:0: start 0.000000, end 179.000000
    Chapter #0:1: start 179.000000, end 998.000000
    Chapter #0:2: start 998.000000, end 1598.000000
    Chapter #0:3: start 1598.000000, end 2043.000000
    Chapter #0:4: start 2043.000000, end 2614.000000
    Chapter #0:5: start 2614.000000, end 3387.000000
    Chapter #0:6: start 3387.000000, end 4007.000000
    Chapter #0:7: start 4007.000000, end 4729.000000
    Chapter #0:8: start 4729.000000, end 5163.504000
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Metadata:
      DURATION        : 00:00:14.431000000
[libx264 @ 0x981b3a0] using SAR=171/160
[libx264 @ 0x981b3a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x981b3a0] profile High 4:4:4 Predictive, level 3.1, 4:2:0 8-bit
[libx264 @ 0x981b3a0] 64 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=16 deblock=1:-1:-1 analyse=0x1:0x131 me=umh subme=9 psy=0 mixed_ref=1 me_range=24 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=230 keyint_min=23 scenecut=40 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'result.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Chapter #0:0: start 0.000000, end 179.000000
    Chapter #0:1: start 179.000000, end 998.000000
    Chapter #0:2: start 998.000000, end 1598.000000
    Chapter #0:3: start 1598.000000, end 2043.000000
    Chapter #0:4: start 2043.000000, end 2614.000000
    Chapter #0:5: start 2614.000000, end 3387.000000
    Chapter #0:6: start 3387.000000, end 4007.000000
    Chapter #0:7: start 4007.000000, end 4729.000000
    Chapter #0:8: start 4729.000000, end 5163.504000
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 768x342 [SAR 171:160 DAR 12:5], q=-1--1, 23.98 fps, 1k tbn, 23.98 tbc (default)
    Metadata:
      DURATION        : 00:00:14.431000000
      encoder         : Lavc57.64.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  343 fps= 26 q=-1.0 Lsize=   26724kB time=00:00:14.39 bitrate=15213.7kbits/s speed=1.08x
video:26720kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.015149%
[libx264 @ 0x981b3a0] frame I:5     Avg QP: 0.00  size:149249
[libx264 @ 0x981b3a0] frame P:338   Avg QP: 0.00  size: 78742
[libx264 @ 0x981b3a0] mb I  I16..4: 21.5%  0.0% 78.5%
[libx264 @ 0x981b3a0] mb P  I16..4:  8.6%  0.0%  3.6%  P16..4: 47.8% 14.8% 21.6%  1.8%  1.7%    skip: 0.0%
[libx264 @ 0x981b3a0] 8x8 transform intra:0.0% inter:65.1%
[libx264 @ 0x981b3a0] coded y,uvDC,uvAC intra: 93.7% 99.5% 99.5% inter: 99.6% 99.4% 99.4%
[libx264 @ 0x981b3a0] i16 v,h,dc,p: 75% 23%  2%  0%
[libx264 @ 0x981b3a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 60% 24%  4%  2%  3%  3%  2%  1%  1%
[libx264 @ 0x981b3a0] i8c dc,h,v,p:  8% 21% 69%  2%
[libx264 @ 0x981b3a0] Weighted P-Frames: Y:0.9% UV:0.0%
[libx264 @ 0x981b3a0] ref P L0: 73.9%  8.6% 11.4%  2.5%  1.5%  0.7%  0.4%  0.2%  0.2%  0.2%  0.1%  0.1%  0.0%  0.1%  0.0%  0.0%
[libx264 @ 0x981b3a0] kb/s:15080.62


I have tried -sws_flags lanczos to no avail. The source file can be downloaded from here:
https://mega.nz/#!bp0jwCoJ!--QLIwVLvDnFfNWdVyYH6zkE0pUApN6tjhVNq0xylPc

Attachments (4)

source.png (393.5 KB ) - added by Artem S. Tashkinov 7 years ago.
Source (when resized using mplayer)
result.png (318.4 KB ) - added by Artem S. Tashkinov 7 years ago.
Result (when resized using ffmpeg + lossless encoding)
result-git.png (323.5 KB ) - added by Artem S. Tashkinov 7 years ago.
Result (when resized using ffmpeg-git + lossless encoding)
source1080p.png (1.2 MB ) - added by Artem S. Tashkinov 7 years ago.
Source as an image

Change History (11)

by Artem S. Tashkinov, 7 years ago

Attachment: source.png added

Source (when resized using mplayer)

by Artem S. Tashkinov, 7 years ago

Attachment: result.png added

Result (when resized using ffmpeg + lossless encoding)

comment:1 by Artem S. Tashkinov, 7 years ago

Oops, I've forgotten to add the encoding string:

ffmpeg -i source.mkv -vf scale=768x342 -c:v libx264 -preset veryslow -x264opts keyint=230:min-keyint=23:bframes=16 -crf 0 -tune film result.mkv

comment:2 by Artem S. Tashkinov, 7 years ago

I've tried ffmpeg from git - the result is the same:

ffmpeg -i source.mkv -vf scale=768x342 -sws_flags spline -c:v libx264 -preset veryslow -x264opts keyint=230:min-keyint=23:bframes=16 -crf 0 -tune film result.mkv

ffmpeg version N-86925-g4ff94558f2 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.4.0 (Debian 6.4.0-2) 20170724
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
  libavutil      55. 69.100 / 55. 69.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 96.100 /  6. 96.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, matroska,webm, from 'source.mkv':
  Metadata:
    ENCODER         : Lavf57.56.100
  Duration: 00:00:14.43, start: 0.000000, bitrate: 5636 kb/s
    Chapter #0:0: start 0.000000, end 179.000000
    Chapter #0:1: start 179.000000, end 998.000000
    Chapter #0:2: start 998.000000, end 1598.000000
    Chapter #0:3: start 1598.000000, end 2043.000000
    Chapter #0:4: start 2043.000000, end 2614.000000
    Chapter #0:5: start 2614.000000, end 3387.000000
    Chapter #0:6: start 3387.000000, end 4007.000000
    Chapter #0:7: start 4007.000000, end 4729.000000
    Chapter #0:8: start 4729.000000, end 5163.504000
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Metadata:
      DURATION        : 00:00:14.431000000
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x4817540] using SAR=171/160
[libx264 @ 0x4817540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x4817540] profile High 4:4:4 Predictive, level 3.1, 4:2:0 8-bit
[libx264 @ 0x4817540] 264 - core 152 r19 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=16 deblock=1:-1:-1 analyse=0x1:0x131 me=umh subme=9 psy=0 mixed_ref=1 me_range=24 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=230 keyint_min=23 scenecut=40 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'result.mkv':
  Metadata:
    encoder         : Lavf57.76.100
    Chapter #0:0: start 0.000000, end 179.000000
    Chapter #0:1: start 179.000000, end 998.000000
    Chapter #0:2: start 998.000000, end 1598.000000
    Chapter #0:3: start 1598.000000, end 2043.000000
    Chapter #0:4: start 2043.000000, end 2614.000000
    Chapter #0:5: start 2614.000000, end 3387.000000
    Chapter #0:6: start 3387.000000, end 4007.000000
    Chapter #0:7: start 4007.000000, end 4729.000000
    Chapter #0:8: start 4729.000000, end 5163.504000
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 768x342 [SAR 171:160 DAR 12:5], q=-1--1, 23.98 fps, 1k tbn, 23.98 tbc (default)
    Metadata:
      DURATION        : 00:00:14.431000000
      encoder         : Lavc57.102.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  343 fps= 30 q=-1.0 Lsize=   27649kB time=00:00:14.39 bitrate=15740.4kbits/s speed=1.24x
video:27645kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.014695%
[libx264 @ 0x4817540] frame I:5     Avg QP: 0.00  size:152679
[libx264 @ 0x4817540] frame P:338   Avg QP: 0.00  size: 81494
[libx264 @ 0x4817540] mb I  I16..4: 22.0%  0.0% 78.0%
[libx264 @ 0x4817540] mb P  I16..4:  6.6%  0.0%  3.6%  P16..4: 49.6% 15.2% 21.5%  1.8%  1.6%    skip: 0.0%
[libx264 @ 0x4817540] 8x8 transform intra:0.0% inter:66.4%
[libx264 @ 0x4817540] coded y,uvDC,uvAC intra: 92.9% 99.8% 99.8% inter: 99.7% 99.7% 99.6%
[libx264 @ 0x4817540] i16 v,h,dc,p: 67% 31%  2%  0%
[libx264 @ 0x4817540] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 59% 24%  4%  2%  3%  3%  2%  1%  1%
[libx264 @ 0x4817540] i8c dc,h,v,p:  9% 26% 63%  2%
[libx264 @ 0x4817540] Weighted P-Frames: Y:0.9% UV:0.0%
[libx264 @ 0x4817540] ref P L0: 74.9%  8.6% 10.8%  2.3%  1.4%  0.6%  0.4%  0.2%  0.2%  0.2%  0.1%  0.1%  0.0%  0.0%  0.0%  0.0%
[libx264 @ 0x4817540] kb/s:15602.79

by Artem S. Tashkinov, 7 years ago

Attachment: result-git.png added

Result (when resized using ffmpeg-git + lossless encoding)

comment:3 by Artem S. Tashkinov, 7 years ago

Version: 3.2.4git-master

comment:4 by Artem S. Tashkinov, 7 years ago

When encoding a single image using

ffmpeg -i source.png -vf scale=768x342:flags=lanczos result.png

The problem disappears (the colors are slightly off though). It's only when encoding the entire video there's this issue.

by Artem S. Tashkinov, 7 years ago

Attachment: source1080p.png added

Source as an image

comment:5 by Artem S. Tashkinov, 7 years ago

Resolution: invalid
Status: newclosed

The problem was with mplayer:

$ cat .mplayer/config

vo = gl:lscale=1,cscale=1

makes the output blurry even when there's no output scaling at all.

comment:6 by Carl Eugen Hoyos, 7 years ago

Component: swscaleundetermined
Priority: criticalnormal

comment:7 by Timo R., 7 years ago

This was already discussed in IRC and could be traced back to breaking aspect ratio with the scale resolution, which results in the DAR being a bit weird, and the player applying scaling to correct for it.
Nothing going wrong here.

Note: See TracTickets for help on using tickets.