FFmpeg調整大小後不保留顏色


1

我想在Ubuntu 18.04上使用ffmpeg version 3.4.6-0ubuntu0.18.04.1將4K mkv視頻的大小調整為1920×1080。原始文件具有以下功能:

Input #0, matroska,webm
encoder         : libebml v1.3.9 + libmatroska v1.5.2
Stream #0:0(eng): Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x2160 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)

此版本的FFmpeg可能不支持x265。我從當前的Git repository(顯式為enabling x265)編譯了一個新版本。現在,ffmpeg -hide_banner -pix_fmts在其輸出中為:

FLAGS NAME            NB_COMPONENTS BITS_PER_PIXEL
-----
IO... yuv420p10le            3            15

現在應同時支持此格式進行編碼和解碼。我嘗試過:

ffmpeg -i original_file.mkv -c:v libx265 -pix_fmt + -vf scale=1920:1080 -colorspace bt709 -c:a copy test_output.mkv

這將產生:

Input #0, matroska,webm, from 'test_output.mkv':
  Metadata:
    ENCODER         : Lavf58.35.100
    Stream #0:0(eng): Video: hevc (Main 10), yuv420p10le(tv, bt709/unknown/unknown), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)

因此,顯然還可以。但是,test_output.mkv顏色似乎仍然是原始顏色強度的一半,就好像4K視頻上疊加了一層灰色。我同時打開了vlcmpv的文件。

  1. 如何盡可能保留原始顏色?

  2. 如果可能的話,我也想降低比特率,但是我嘗試

    ffmpeg -i original_file.mkv -s 1920x1080 -b 1700 output.mkv
    

    製作了純灰色的純色視頻,帶有一些移動的方塊。


我總是收到此消息:

[matroska,webm @ 0x55a5507ad100] Could not find codec parameters for stream 1 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options

從源構建的

FFmpeg具有以下配置:

ffmpeg version N-95768-gd831edc387 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
configuration: --enable-gpl --enable-libx264 --enable-libx265
libavutil      56. 36.100 / 56. 36.100
libavcodec     58. 62.100 / 58. 62.100
libavformat    58. 35.100 / 58. 35.100
libavdevice    58.  9.101 / 58.  9.101
libavfilter     7. 66.100 /  7. 66.100
libswscale      5.  6.100 /  5.  6.100
libswresample   3.  6.100 /  3.  6.100
libpostproc    55.  6.100 / 55.  6.100
1

Ad 1:

Try adding the -pix_fmt yuv420p10le option (e.g. before -vf). Or only -pix_fmt + for using the same pixel format as the input video has.

If it doesn't help, you obviously have an inappropriate, albeit more common FFmpeg version — only for 8-bit colors. (Your original video uses 10-bit colors, and FFmpeg will try use the best 8-bit pixel format in this case — with the colors' degradation, of course.)

FFmpeg may be built for 8-bit colors or for 10-bit colors, or — in recent time — for both of them (for your HEVC encoded video).

So you need to build (or obtain by other way) version for 8-/10- or 10-bit color depth.

Ad 2:

Bitrate of 1700 is very low — only 1700 bits per second, i. e. about 212 bytes per second.

To reach such a low bitrate and at the same time reach your 23.98 frames per second, the encoder is limited with average size for 1 frame about 212 / 24 = 9 bytes only!

Did you see a picture of such small memory? It has almost no information, so the gray image.

You probably wanted 1700k (Kilobits per second) — or, more probably — 170k:

-b:v 170k

so correct your command in this way.


Addendum to Ad 1:

You use the (default) 4:2:0 chroma subsampling (with inevitable color and contrast degradation).
Try the maximum quality, i.e. 4:4:4 (no subsampling), or — if it will be sufficient for you — 4:2:2.

To reach this, use -pix_fmt yuv444p10le and change the video profile to main444-10 (with option -profile:v main444-10).