使用 ffmpeg 提取帧并包含字幕

使用 ffmpeg 提取帧并包含字幕

我正在尝试使用 ffmpeg 从带有字幕的视频中提取单帧。

我自己构建了ffmpeg:

sircmpwn@picard ~/sources/bakabt-staging/hennkeo/groups $ ffmpeg
ffmpeg version N-54036-g6c4516d Copyright (c) 2000-2013 the FFmpeg developers
  built on Jun 15 2013 11:56:01 with gcc 4.7 (Ubuntu/Linaro 4.7.3-1ubuntu1)
  configuration: --prefix=/home/sircmpwn/ffmpeg_build --extra-cflags=-I/home/sircmpwn/ffmpeg_build/include --extra-ldflags=-L/home/sircmpwn/ffmpeg_build/lib --bindir=/home/sircmpwn/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
  libavutil      52. 35.101 / 52. 35.101
  libavcodec     55. 16.100 / 55. 16.100
  libavformat    55.  8.102 / 55.  8.102
  libavdevice    55.  2.100 / 55.  2.100
  libavfilter     3. 77.101 /  3. 77.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

我运行这个:

sircmpwn@picard ~/sources/bakabt-staging/hennkeo/groups $ ffmpeg -ss 00:09:18 -i horrible.mkv -sn -vf ass=horrible.ass -t 1 -vframes 1 horrible-1.png
ffmpeg version N-54036-g6c4516d Copyright (c) 2000-2013 the FFmpeg developers
  built on Jun 15 2013 11:56:01 with gcc 4.7 (Ubuntu/Linaro 4.7.3-1ubuntu1)
  configuration: --prefix=/home/sircmpwn/ffmpeg_build --extra-cflags=-I/home/sircmpwn/ffmpeg_build/include --extra-ldflags=-L/home/sircmpwn/ffmpeg_build/lib --bindir=/home/sircmpwn/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
  libavutil      52. 35.101 / 52. 35.101
  libavcodec     55. 16.100 / 55. 16.100
  libavformat    55.  8.102 / 55.  8.102
  libavdevice    55.  2.100 / 55.  2.100
  libavfilter     3. 77.101 /  3. 77.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Input #0, matroska,webm, from 'horrible.mkv':
  Metadata:
    creation_time   : 2013-05-26 13:34:41
  Duration: 00:23:42.11, start: 0.000000, bitrate: 1900 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 30.30 fps, 30.30 tbr, 1k tbn, 59.94 tbc (default) (forced)
    Stream #0:1: Audio: aac, 44100 Hz, stereo, fltp (default) (forced)
    Stream #0:2: Subtitle: ssa (default) (forced)
Codec 0x18000 is not in the full list.
    Stream #0:3: Attachment: unknown_codec
    Metadata:
      filename        : OpenSans-Semibold.ttf
      mimetype        : application/x-truetype-font
[Parsed_ass_0 @ 0x3521780] Added subtitle file: 'horrible.ass' (9 styles, 374 events)
Output #0, image2, to 'horrible-1.png':
  Metadata:
    encoder         : Lavf55.8.102
    Stream #0:0: Video: png, rgb24, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30.30 tbc (default) (forced)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.03 bitrate=N/A dup=0 drop=57    
video:364kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.005907%

这让我这个图片. 所需的图像类似于这个

答案1

好吧,在 #ffmpeg IRC 上找到了答案。问题在于参数的顺序(这并不奇怪)。正确的调用是:

ffmpeg -i horrible.mkv -ss 00:09:18 -vf ass=horrible.ass -vframes 1 horrible-1.png

我遇到了第二个字体问题,您可能也遇到过。ffmpeg 不会使用您提供的媒体中的字体,因此您必须先将它们安装到您的系统中。我修改了 IRC 上提供给我的一个脚本,该脚本将视频文件中的字体提取到 ~/.fonts 中:https://gist.github.com/SirCmpwn/5789762

答案2

您的命令中有-sn-sn基本上意味着“无字幕”。 ffmpeg 的行为符合预期。

搜索-sn文档

您的解决方案没有-sn

我可能完全错了,但这可能是解决您的第一个问题的方法。

相关内容