我正在尝试进行以下转换:
ffmpeg -i video.mp4 -map 0 -c copy -c:v libx265 -crf 30 -vf "scale=-1:\'min(720,ih)\'" -c:a libopus -b:a 44k -map_metadata 0 -loglevel error -hide_banner video.mkv
除了特定的视频外,这很好用。我得到以下输出:
x265 [info]: HEVC encoder version 3.5+39-7c7ea0a4b
x265 [info]: build info [Windows][GCC 12.1.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x265 [error]: Color Primaries must be unknown, bt709, bt470m, bt470bg, smpte170m, smpte240m, film, bt2020, smpte-st-428, smpte-rp-431 or smpte-eg-432
x265 [error]: Transfer Characteristics must be unknown, bt709, bt470m, bt470bg, smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, bt2020-10, bt2020-12, smpte-st-2084, smpte-st-428 or arib-std-b67
x265 [error]: Matrix Coefficients must be unknown, bt709, fcc, bt470bg, smpte170m, smpte240m, gbr, ycgco, bt2020nc, bt2020c, smpte-st-2085, chroma-nc, chroma-c or ictcp
[libx265 @ 00000000005a2940] Cannot open libx265 encoder.
当我用谷歌搜索第一个错误文本时,找不到一个结果,ffmpeg "Color Primaries must be unknown"
这是详细的输出:
ffmpeg version 2022-06-16-git-5242ede48d-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.3.0 (Rev1, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 57. 27.100 / 57. 27.100
libavcodec 59. 33.100 / 59. 33.100
libavformat 59. 25.100 / 59. 25.100
libavdevice 59. 6.100 / 59. 6.100
libavfilter 8. 41.100 / 8. 41.100
libswscale 6. 6.100 / 6. 6.100
libswresample 4. 6.100 / 4. 6.100
libpostproc 56. 5.100 / 56. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video_2022-07-22_10-01-25.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2022-07-04T13:14:36.000000Z
Duration: 00:01:04.32, start: 0.000000, bitrate: 342 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, reserved, progressive), 1280x720, 209 kb/s, 24.99 fps, 50 tbr, 90k tbn (default)
Metadata:
creation_time : 2022-07-04T13:14:29.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
creation_time : 2022-07-04T13:14:29.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 0, only the last option '-c:v libx265' will be used.
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 1, only the last option '-c:a libopus' will be used.
File 'C:\Users\Administrator\Downloads\delendum\New folder\testout.mkv' already exists. Overwrite? [y/N] Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
Stream #0:1 -> #0:1 (aac (native) -> opus (libopus))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.5+37-07b011400
x265 [info]: build info [Windows][GCC 11.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [error]: Color Primaries must be unknown, bt709, bt470m, bt470bg, smpte170m, smpte240m, film, bt2020, smpte-st-428, smpte-rp-431 or smpte-eg-432
x265 [error]: Transfer Characteristics must be unknown, bt709, bt470m, bt470bg, smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, bt2020-10, bt2020-12, smpte-st-2084, smpte-st-428 or arib-std-b67
x265 [error]: Matrix Coefficients must be unknown, bt709, fcc, bt470bg, smpte170m, smpte240m, gbr, ycgco, bt2020nc, bt2020c, smpte-st-2085, chroma-nc, chroma-c or ictcp
[libx265 @ 0000000002e60340] Cannot open libx265 encoder.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[libopus @ 000000000056fe00] 1 frames left in the queue on closing
Conversion failed!
我不是视频编码方面的专家,所以我真的不知道这一切意味着什么。可能与源文件有关。如何解决这个问题?提前致谢!
我在这里上传了视频。您可以使用右侧播放器下方的按钮下载它。
感谢@Rotem:
第一个修复文件:
然后
video2.mp4
用作输入。参数“原色”、“传输特性”和“矩阵系数”(描述颜色标准)嵌入在输入视频文件的 H.264 流中。
中的颜色特征
video.mp4
值超过了被 FFmpeg 取代的有效值(由于外来/新标准或由于编码器损坏)。将流重新编码为 H.265 时,不受支持的颜色特性会导致 FFmpeg 失败(当重新编码为 H.264 时 FFmpeg 没有失败,因此这是“罕见情况”)。
最简单的解决方案是手动指定 H.265 编码器的颜色特性:
ffmpeg -y -i video.mp4 -map 0 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -c:v libx265 -crf 30 -vf "scale=-1:\'min\(720\,ih\)\'" -c:a libopus -b:a 44k -map_metadata 0 -hide_banner video.mkv
其他选项是
video.mp4
通过使用比特流过滤器替换颜色特征来修复:ffmpeg -y -i video.mp4 -map 0 -c copy -map_metadata 0 -bsf:v h264_metadata=colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1 video2.mp4
bt709
之所以选择它,是因为它是高清视频最常用的标准。我们可以使用 FFprobe 检查颜色特性:
ffprobe -show_frames video.mp4 > 1.txt
输出显示:
reserved
表示值不受支持或无效。