编码问题

编码问题

我正在使用 FFmpeg 命令行对 mp4 视频进行编码,命令有点长。此示例中有 37 个输入流,其中大部分是 PNG 文件。

下面的命令完全符合我的预期。经过数小时的故障排除,如果其中一个文件是 JPG 而不是 PNG,我可以重现编码问题。或者,更准确地说,如果我将其中一个文件保留为其原始 JPG 格式,但如果我在编码之前将 JPG 转换为 PNG,则可以消除问题并成功编码

我知道我的编程能力,所以我认为我更有可能犯了一个错误更糟糕的是,我遇到了 FFmpeg 中的一个错误。虽然命令按我预期的方式工作,但这并不意味着我正确使用了 FFmpeg:这只意味着我能够预测结果。

编码问题

FFmpeg 没有给我错误,警告似乎与问题无关。问题有两种形式,在我看来似乎相同,但可能有所不同。在第一种形式中,FFmpeg 将编码所有内容直到 JPG 文件,然后它将重复添加该部分的第一帧,直到我停止 FFmpeg。在我停止编码后,视频将播放,一切都很完美,直到重复的帧。在第二种形式中,FFmpeg 将开始编码,写入一帧,然后停止写入帧。但是,FFmpeg 仍在运行:统计数据正在更新并显示编码“速度”正在降低,因为它没有写入新帧,但时间在增加。例如:

frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.01 bitrate= 36.0kbits/s speed=7.63e-06x

密集文本

在写这个问题时,我在写完几乎所有其他内容后添加了 filter_complex 脚本。如果没有文本编辑器的颜色和样式,那段文字太密集了,根本无法阅读。唉。

FFmpeg 是最新的

我使用以下方式编译了 FFmpeg媒体自动构建套件2023 年 6 月 3 日。-buildconf 位于文章末尾。我已使用此版本对许多视频进行编码。

除文件格式外,其他都一样

我使用此命令将 JPG 文件转换为 PNG FFmpeg -i 611.jpg -update 1 611.png,所有其他文件和命令都相同。但这并不意味着我正确使用了命令。FFmpeg 有时具有容错能力。

截断的命令行

命令行和支持文本文件的长度略大于 22,000 个字符,因此我无法在此处复制和粘贴所有内容。不过,我会尝试包含相关内容。

命令行

  1. 问题发生时,第二个文件是 611.jpg。在这种情况下,它会在一帧后停止写入。如果我将 jpg 放在“images\avatars\7_bg.png”占用的位置,FFmpeg 将写入大部分帧,但会停止在该文件处。
  2. 我保留了引号和双引号的使用。
  3. 所有路径均如图所示:相对。
  4. 输入流是有序的,因此流索引是准确的。

(插入换行符以方便阅读)

FFmpeg -hide_banner -loglevel level+error -stats -y 
-an -i images\progress_bar.mp4 
-stream_loop -1 -framerate 60 -t 2000ms -i images\bg\611.png 
-stream_loop -1 -framerate 60 -t 2000ms -i images\box_level.png 
-an -f concat -i 1.FFconcat 
-an -f concat -i 2.FFconcat 
[4 other files]

-an -f concat -i 7.FFconcat 
-itsoffset 27000ms -stream_loop -1 -framerate 60 -t 5100ms -i images\supporter\4237.png 
-itsoffset 61100ms -stream_loop -1 -framerate 60 -t 5100ms -i images\supporter\6787.png 
[16 other files]

-itsoffset 640800ms -stream_loop -1 -framerate 60 -t 5100ms -i images\supporter\3699.png 
-itsoffset 674900ms -stream_loop -1 -framerate 60 -t 5100ms -i images\supporter\2144.png 

-an -itsoffset 180000ms -i images\engage\like_1.mp4 

-stream_loop -1 -framerate 60 -t 8500ms -i images\bg_plain\LevelsEvent.png 
-stream_loop -1 -framerate 60 -t 8500ms -i images\avatars\avatar_frame.png 
-stream_loop -1 -framerate 60 -t 8500ms -i images\avatars\7.png 
-stream_loop -1 -framerate 60 -t 8500ms -i images\avatars\7_bg.png 

-stream_loop -1 -framerate 60 -t 6000ms -i images\bg\Microworld_v.png 

-stream_loop -1 -t 727567ms -i Music\27min.aac 

-filter_complex_script 0.filter_complex 

-r 60 -g 30 -crf 17 -fpre FFpresets\youtube.ffpreset -profile:v high 
-x264opts bframes=2:colormatrix=bt709 -pix_fmt yuv420p -preset slow 

-map 36:a -codec:a copy -map "[3_CONCATENATED_36]" 

-threads 0 "publish\output file.mp4"

n.FF连接

FFconcat 文件类似。在此示例中,每个文件有 6 到 16 个条目,但我制作的视频使用了超过 100 个条目。这是 6.FFconcat 中的 16 个条目中的前 2 个。

ffconcat version 1.0
file '6.mp4'
inpoint 00:00:00.017
outpoint 00:00:06.517
duration 00:00:06.500
file '6.mp4'
inpoint 00:00:13.350
outpoint 00:00:27.050
duration 00:00:13.700

0.filter_complex

  1. 我删除了这 11,000 个字符中的 8,000 多个。
  2. 我并不是说我正确使用了过滤器。
  3. 我写了一些内联解释。
[1]scale=1080:1920:flags=lanczos,setdar=9/16[TRANSITION_BG];
[TRANSITION_BG][2]overlay=x=0-overlay_w/2+540:y=0-overlay_h/2+640[TRANSITION_BOX];

[TRANSITION_BOX]split=7[TRANSITION_BOX_1][TRANSITION_BOX_2][TRANSITION_BOX_3]
[TRANSITION_BOX_4][TRANSITION_BOX_5][TRANSITION_BOX_6][TRANSITION_BOX_7];

[TRANSITION_BOX_1]drawtext=fontcolor=0xffffff:text='Level 1':fontsize=116
:fontfile=/full/path/fonts/font_file.ttf
:x=540-(text_w/2):y=640-(text_h/2)[LEVEL_1];
[LEVEL_1]fade=in:0:30[INTRO_1];

INTRO_1 will be concatenated later

[3]crop=out_w=1080:out_h=1920[1_MIDDLE];
[3]crop=out_w=1080:out_h=190+60:x=0:y=120-60[1_TOP];
[1_MIDDLE][1_TOP]overlay=x=0-overlay_w/2+0+overlay_w/2
:y=0-overlay_h/2+0+overlay_h/2[1_MIDDLE_1_TOP];

[3]crop=out_w=1080:out_h=210+40:x=0:y=in_h-210-80[1_BOTTOM];
[1_MIDDLE_1_TOP][1_BOTTOM]overlay=x=0-overlay_w/2+0+overlay_w/2
:y=0-overlay_h/2+main_h-overlay_h+overlay_h/2[1_VIDEO_OVERLAYS];

[1_VIDEO_OVERLAYS]fade=in:start_time=0:duration=0.5,setdar=9/16[VIDEO_BASE_1];

VIDEO_BASE_1 will be concatenated later 

6 more sections of TRANSITION_BOX_n to VIDEO_BASE_n corresponding to n.FFconcat

concatenate everything up to here
[INTRO_1][VIDEO_BASE_1][INTRO_2][VIDEO_BASE_2][INTRO_3][VIDEO_BASE_3]
[INTRO_4][VIDEO_BASE_4][INTRO_5][VIDEO_BASE_5][INTRO_6][VIDEO_BASE_6]
[INTRO_7][VIDEO_BASE_7]concat=n=14:v=1:a=0[14_CONCATENATED_10];

20 image overlays and 1 video overlay on the concatenated video

[10]fade=type=in:alpha=1:start_time=27000ms:duration=500ms,
fade=type=out:alpha=1:start_time=31600ms:duration=500ms[FADE_10];
[14_CONCATENATED_10][FADE_10]overlay=x=0-overlay_w/2+463:y=0-overlay_h/2+1775
:enable='between(t,27000/1000,32100/1000)'[SUPPORTER_10];

18 more sections of stream index n to SUPPORTER_n
Notice the incrementing start_time and :enable between

[29]fade=type=in:alpha=1:start_time=674900ms:duration=500ms,
fade=type=out:alpha=1:start_time=679500ms:duration=500ms[FADE_29];
[SUPPORTER_28][FADE_29]overlay=x=0-overlay_w/2+463:y=0-overlay_h/2+1775
:enable='between(t,674900/1000,680000/1000)'[SUPPORTER_29];

1 video overlay

[30]colorkey=color=0x00d800:similarity=0.3,
scale=1024:576:flags=lanczos[LIKE_30];
[SUPPORTER_29][LIKE_30]overlay=x=0-overlay_w/2+540
:y=0-overlay_h/2+-140+overlay_h/2
:enable='between(t,180000/1000,184000/1000)'[THUMB_30];

THUMB_30 is all of the overlays on all of the videos to this point
THUMB_30 will be concatenated at the end

[31]crop=out_w=1080:out_h=1920,setdar=9/16[AWARD_BG];
[AWARD_BG][32]overlay=x=0-overlay_w/2+540:y=0-overlay_h/2+376[AWARD_FRAME];
[AWARD_FRAME][33]overlay=x=0-overlay_w/2+540:y=0-overlay_h/2+376[AWARD_AVATAR];
[34]pad=w=1080:h=1080:color=0x4d5e6e:x=(out_w-in_w)/2:y=(out_h-in_h)/2[POSTCARD];
[AWARD_AVATAR][POSTCARD]overlay=x=0-overlay_w/2+540:y=0-overlay_h/2+1290[AWARD_POSTCARD];
[AWARD_POSTCARD]fade=type=in:start_time=0:duration=0.5[AWARD];

AWARD will be concatenated at the end

[35]scale=1080:1920:flags=lanczos,
fade=type=in:start_time=0:duration=0.5:color=black[ENDSCREEN];
[ENDSCREEN]drawtext=fontcolor=0x265b7d:textfile=/full/path/text_UTF-8.txt
:fontsize=64:fontfile=:fontfile=/full/path/fonts/different_font_file.ttf
:box=1:boxcolor=0xf9f9f9:boxborderw=32:x=540-(text_w/2):y=520-(text_h/2)
:enable='between(t,1500/1000,6000/1000)',setdar=9/16[QTY_VIDEOS];

[THUMB_30][AWARD][QTY_VIDEOS]concat=n=3:v=1:a=0[3_CONCATENATED_36];

youtube.ffpreset

  1. 我已经用这个预设文件编码了超过 3000 个视频,但我并不声称它是正确的。
  2. 由于有 3000 个视频,我不认为以下细节是导致问题的原因,但我怀疑这个细节是多余的或不正确的。在这个预设文件中,我写了“bf=2”,在命令行上我写了“-x264opts bframes=2”。冗余?冲突?我真的不知道。
vcodec=libx264
movflags=faststart
field_order=progressive
bf=2
flags=cgop
coder=1
colorspace=bt709
color_trc=bt709
color_primaries=bt709

日志级别 24,警告

我只有 24 级的日志,警告。这是来自成功编码的文件。

[aac @ 0000024c57dea940] [warning] Estimating duration from bitrate, this may be inaccurate
[swscaler @ 0000024c6d3c0040] [swscaler @ 0000024c6d3d5040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
14 more warnings
[swscaler @ 0000024c6d3c0040] [swscaler @ 0000024c6d3ef000] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[concat @ 0000024c57038cc0] [warning] DTS 86097 < 174117 out of order
3 more @ 0000024c57038cc0
[out_0_1 @ 0000024c6997bc00] [warning] 100 buffers queued in out_0_1, something may be wrong.
[concat @ 0000024c57038480] [warning] DTS 116824 < 174116 out of order
10 more @ 0000024c57038480
[concat @ 0000024c57038740] [warning] DTS 166496 < 174939 out of order
14 more @ 0000024c57038740
51 more @ three different addresses
They seem to be perfectly correlated with the 7 command line input streams
"-f concat -i n.FFconcat"

不成功的编码要短得多,因为它只将一帧写入文件。

[aac @ 000001c64988c580] [warning] Estimating duration from bitrate, this may be inaccurate
[swscaler @ 000001c65b2c5f00] [warning] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001c65d9f7040] [swscaler @ 000001c65da04000] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65d9f7040] [swscaler @ 000001c65da18f40] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65d9f7040] [swscaler @ 000001c65da2de40] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65d9f7040] [swscaler @ 000001c65da42d80] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65e50ddc0] [warning] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001c65e50ddc0] [warning] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001c65e50ddc0] [warning] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c661566900] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65d9f7040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65da0a040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65da1d080] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c661566900] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65d9f7040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65da0a040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65da1d080] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c661566900] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65d9f7040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65da0a040] [warning] No accelerated colorspace conversion found from yuv420p to argb.
[swscaler @ 000001c65b8770c0] [swscaler @ 000001c65da1d080] [warning] No accelerated colorspace conversion found from yuv420p to argb.

FFmpeg-buildconf 复制代码

libavutil      58. 12.100 / 58. 12.100
libavcodec     60. 16.100 / 60. 16.100
libavformat    60.  5.100 / 60.  5.100
libavdevice    60.  2.100 / 60.  2.100
libavfilter     9.  8.101 /  9.  8.101
libswscale      7.  3.100 /  7.  3.100
libswresample   4. 11.100 /  4. 11.100
libpostproc    57.  2.100 / 57.  2.100

configuration:
--pkg-config=pkgconf
--cc='ccache gcc'
--cxx='ccache g++'
--ld='ccache g++'
--extra-cxxflags=-fpermissive
--extra-cflags=-Wno-int-conversion
--disable-autodetect
--enable-d3d11va
--enable-dxva2
--enable-iconv
--enable-lzma
--enable-zlib
--enable-sdl2
--enable-ffnvcodec
--enable-nvdec
--enable-libmp3lame
--enable-libopus
--enable-libvorbis
--enable-libvpx
--enable-libx264
--enable-libx265
--enable-libdav1d
--enable-libaom
--disable-debug
--enable-libfdk-aac
--enable-fontconfig
--enable-libass
--enable-libfreetype
--enable-libmysofa
--enable-libopencore-amrnb
--enable-libopencore-amrwb
--enable-libopenjpeg
--enable-libsoxr
--enable-libwebp
--enable-gpl
--enable-libtesseract
--enable-openal
--enable-libopenh264
--enable-openssl
--extra-libs=-liconv
--enable-version3
--enable-nonfree
--extra-cflags=-DAL_LIBTYPE_STATIC
--extra-cflags='-IC:/mabs/local64/include'
--extra-cflags='-IC:/mabs/local64/include/AL'

相关内容