如何在为整个视频生成缩略图时使用 FFMPEG 指定绘制文本?

如何在为整个视频生成缩略图时使用 FFMPEG 指定绘制文本?

我成功地通过 PHP 使用 ffmpeg 每 15 秒从我们的视频中捕获缩略图,但我需要为每个缩略图添加版权声明。我进行了足够的研究,发现这是可以做到的,并且知道执行此操作的参数是什么,但我无法弄清楚使用它的语法,而不会从 ffmpeg 收到各种错误,具体取决于我在命令行中放置它的位置/方式。

我被告知要提供我得到的输出,因此它包含在下面,但我需要帮助的是正确的句法使用 FFMPEG 命令指定我需要的内容。

a.) 工作 FFMPEG 命令:

ffmpeg.exe -i D:\video.mp4 -vf "thumbnail, scale=640:480, fps=1/15" D:\video_%05d.jpg

b.) 需要添加到上述工作命令中的参数:

"drawtext=fontsize=20:box=1:fontfile='c:/windows/fonts/arial.ttf:text=\'My Copyright Text\':x=(w-text_w)/2:0"

如何正确包含所示的参数b.使用命令A。

c.) 我尝过的味道: 我试过b.在以下几个地方,但都产生类似以下的错误e.以下。

ffmpeg.exe -i D:\video.mp4 -vf "thumbnail, scale=640:480, fps=1/15" "drawtext=fontsize=20:box=1:fontfile=c:\windows\fonts\arial.ttf:text='My Copyright Text':x=(w-text_w)/2:0" D:\video_%05d.jpg

e.) 示例输出/错误

C:\>ffmpeg.exe -i D:\video.mp4 -vf "thumbnail, scale=640:480, fps=1/15 drawtext=fontsize=20:box=1:fontfile=Dc:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0" D:\captures\video_%05d.jpg -loglevel error
[fps @ 0000000004fec000] Unable to parse option value "1/15 drawtext=fontsize=20" as video rate
[Parsed_fps_2 @ 0000000005000980] Option 'box' not found
[AVFilterGraph @ 000000000509ba40] Error initializing filter 'fps' with args '1/15 drawtext=fontsize=20:box=1:fontfile=c:/windows/fonts/arial.ttf:text=CMy Copyright Text:x=(w-text_w)/2:0'
Error opening filters!

C:\>ffmpeg.exe -i D:\video.mp4 -vf "thumbnail, scale=640:480, fps=1/15", "drawtext=fontsize=20:box=1:fontfile=c:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0" D:\captures\video_%05d.jpg -loglevel error
[NULL @ 0000000005053140] Unable to find a suitable output format for 'drawtext=fontsize=20:box=1:fontfile=c:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0'
drawtext=fontsize=20:box=1:fontfile=c:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0: Invalid argument

C:\>ffmpeg.exe -i D:\video.mp4 -vf "thumbnail, scale=640:480, fps=1/15"  D:\captures\video_%05d.jpg "drawtext=fontsize=20:box=1:fontfile=c:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0" -loglevel error
[NULL @ 0000000004fc49c0] Unable to find a suitable output format for 'drawtext=fontsize=20:box=1:fontfile=c:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0'
drawtext=fontsize=20:box=1:fontfile=c:\windows/fonts/arial.ttf:text='CMy Copyright Text':x=(w-text_w)/2:0: Invalid argument

典型的控制台输出

ffmpeg.exe -loglevel verbose -i d:\myvideo.mp4 -vf "thumbnail, scale=640:480, fps=1/15 drawtext=fontsize=30:box=1:fontfile=c:/windows/fonts/arial.ttf:text='My Copyright Text':x=(w-text_w)/2:0" D:\captures\captured_%05d.jpg
ffmpeg version N-73975-gda8b70b Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      54. 28.100 / 54. 28.100
  libavcodec     56. 52.100 / 56. 52.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 27.100 /  5. 27.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'd:\myvideo.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isom
    creation_time   : 2013-12-18 21:48:29
    encoder         : Encoded by LearningCORE
  Duration: 00:29:09.88, start: 0.000000, bitrate: 1573 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
    Metadata:
      creation_time   : 2013-12-18 21:48:29
      handler_name    : GPAC ISO Audio Handler
    Stream #0:1(und): Video: h264 (Baseline), 3 reference frames (avc1 / 0x31637661), yuv420p(tv), 640x480 [SAR 1:1 DAR 4:3], 1436 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2013-12-17 21:37:07
      handler_name    : vide
      encoder         : AVC Coding
    Stream #0:2(und): Data: none (rtp  / 0x20707472), 12 kb/s
    Metadata:
      creation_time   : 2013-12-18 21:37:13
    Stream #0:3(und): Data: none (rtp  / 0x20707472), 56 kb/s
    Metadata:
      creation_time   : 2013-12-18 21:37:14
    Stream #0:4(eng): Subtitle: mov_text (tx3g / 0x67337874), 640x480, 0 kb/s (default)
    Metadata:
      creation_time   : 2013-12-18 21:48:43
      handler_name    : bc200_00.srt:hdlr=sbtl:lang=en:group=2:delay=0 - Imported with GPAC 0.5.0-rev4065
[Parsed_thumbnail_0 @ 0000000004fa6780] batch size: 100 frames
[Parsed_scale_1 @ 0000000004fc18c0] w:640 h:480 flags:'0x4' interl:0
[fps @ 0000000004fac9a0] Unable to parse option value "1/15 drawtext=fontsize=30" as video rate
[Parsed_fps_2 @ 0000000004fc2b80] Option 'box' not found
[AVFilterGraph @ 000000000505c0a0] Error initializing filter 'fps' with args '1/15 drawtext=fontsize=30:box=1:fontfile=c:/windows/fonts/arial.ttf:text=My Copyright Text:x=(w-text_w)/2:0'
[Parsed_fps_2 @ 0000000004fc2b80] 0 frames in, 0 frames out; 0 frames dropped, 0 frames duplicated.
Error opening filters!

答案1

应用于单个视频流的一组过滤器应按顺序放在一组引号中,并用逗号分隔每个单独的过滤器。因此,在命令中C,后面应该有一个逗号,后面fps=1/15跟着drawtext过滤器。

相关内容