ffmpeg 编码将视频转换为 PNG,带字幕

ffmpeg 编码将视频转换为 PNG,带字幕

假设我有这样的视频格式:

Metadata:
    CREATION_TIME   : 2017-08-04T21:29:42Z
    ENCODER         : Lavf57.7.2
  Duration: 00:24:45.83, start: 0.000000, bitrate: 1130 kb/s
    Chapter #0:0: start 0.000000, end 90.048000
    Metadata:
      title           : Chapter 1
    Chapter #0:1: start 90.048000, end 741.074000
    Metadata:
      title           : Chapter 2
    Chapter #0:2: start 741.074000, end 1391.348000
    Metadata:
      title           : Chapter 3
    Chapter #0:3: start 1391.348000, end 1422.338000
    Metadata:
      title           : Chapter 4
    Chapter #0:4: start 1422.338000, end 1485.693000
    Metadata:
      title           : Chapter 5
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 960x720 [SAR 1:1 DAR 4:3], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Stereo
    Stream #0:2(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp
    Metadata:
      title           : Stereo
    Stream #0:3(eng): Subtitle: ass (default) (forced)
    Stream #0:4: Attachment: ttf
    Metadata:
      filename        : FRAMD.TTF
      mimetype        : application/x-truetype-font
    Stream #0:5: Attachment: ttf
    Metadata:
      filename        : FRAMDCN.TTF
      mimetype        : application/x-truetype-font
    Stream #0:6: Attachment: ttf
    Metadata:
      filename        : FRAMDIT.TTF
      mimetype        : application/x-truetype-font
    Stream #0:7: Attachment: ttf
    Metadata:
      filename        : DEJAVUSERIF.TTF
      mimetype        : application/x-truetype-font
    Stream #0:8: Attachment: ttf
    Metadata:
      filename        : FRADM.TTF
      mimetype        : application/x-truetype-font
    Stream #0:9: Attachment: ttf
    Metadata:
      filename        : FRADMCN.TTF
      mimetype        : application/x-truetype-font
    Stream #0:10: Attachment: ttf
    Metadata:
      filename        : FRADMIT.TTF
      mimetype        : application/x-truetype-font

我想把这个视频的每一帧都转换成图像,但我想保留字幕

我尝试了这样的命令:

 ffmpeg -i file.mkv -r 1 -ss 120 -t 350 -map 0:0  images/output_%05d.png

这使我可以得到我想要的范围内的帧(-ss..-t),但每当我尝试添加一些-map 0:3(字幕流)的变化时,我就会得到

Automatic encoder selection failed for output stream #0:1. Default encoder for format image2 (codec none) is probably disabled. Please choose an encoder manually.

为流 0:1 选择编码器时出错

我也尝试过类似

ffmpeg -i file.mkv -r 1 -ss 120 -t 350 -map 0:0 -attach ~/Library/Fonts/DejaVuSans.ttf -metadata:s:0 mimetype=application/x-truetype-font images/output_%05d.png

它也只是写出了 PNG——没有字幕。

我在这里遗漏了什么?

答案1

在了解到ffmpeg不执行字幕渲染后,我才明白这一点。我不得不使用过滤subtitles,这意味着重新ffmpeg编译--enable-libass

最终的命令如下:

ffmpeg -i file.mkv -r 1 -map 0:0 -vf "subtitles=file.mkv" images/output_%05d.png

相关内容