Get screenshot of video with subtitles

2019-07-09 14:29发布

问题:

I'm trying to get a single frame of a video with ffmpeg including the the subtitles

ffmpeg -ss 00:09:18 -i movie.mkv -vf subtitles=subtitles.srt -vframes 1 screenshot.png

The screenshot is outputting but the subtitles are not on the image.

I'm new to ffmpeg so if anyone could help me, that would be awesome!

Edit: Here's an example of output that I'm getting:

ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609 configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100 [aac @ 0xfe73c0] element type mismatch 3 != 0 [aac @ 0xfe73c0] element type mismatch 1 != 0 Last message repeated 1 times Input #0, matroska,webm, from 'Community.S01E01.720p.5.1Ch.Web-DL.ReEnc-DeeJayAhmed.mkv':
Metadata: encoder : libebml v1.3.1 + libmatroska v1.4.2 creation_time : 2015-10-16 19:35:27 Duration: 00:25:25.15, start: 0.000000, bitrate: 1135 kb/s Stream #0:0: Video: h264 (High), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default) Metadata: BPS : 947111 BPS-eng : 947111 DURATION : 00:25:25.107000000 DURATION-eng : 00:25:25.107000000 NUMBER_OF_FRAMES: 36566 NUMBER_OF_FRAMES-eng: 36566 NUMBER_OF_BYTES : 180555811 NUMBER_OF_BYTES-eng: 180555811 _STATISTICS_WRITING_APP: mkvmerge v8.4.0 ('A better way to fly') 32bit _STATISTICS_WRITING_APP-eng: mkvmerge v8.4.0 ('A better way to fly') 32bit _STATISTICS_WRITING_DATE_UTC: 2015-10-16 19:35:27 _STATISTICS_WRITING_DATE_UTC-eng: 2015-10-16 19:35:27 _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES Stream #0:1(eng): Audio: aac (HE-AAC), 48000 Hz, 5.1, fltp (default) Metadata: BPS : 186250 BPS-eng : 186250 DURATION : 00:25:25.120000000 DURATION-eng : 00:25:25.120000000 NUMBER_OF_FRAMES: 35745 NUMBER_OF_FRAMES-eng: 35745 NUMBER_OF_BYTES : 35506701 NUMBER_OF_BYTES-eng: 35506701 _STATISTICS_WRITING_APP: mkvmerge v8.4.0 ('A better way to fly') 32bit _STATISTICS_WRITING_APP-eng: mkvmerge v8.4.0 ('A better way to fly') 32bit _STATISTICS_WRITING_DATE_UTC: 2015-10-16 19:35:27 _STATISTICS_WRITING_DATE_UTC-eng: 2015-10-16 19:35:27 _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES [Parsed_subtitles_0 @ 0x106ce60] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.0.1 (COMPLEX) [Parsed_subtitles_0 @ 0x106ce60] Using font provider fontconfig Output #0, image2, to 'screenshot.png': Metadata: encoder : Lavf56.40.101 Stream #0:0: Video: png, rgb24, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default) Metadata: BPS : 947111 BPS-eng : 947111 DURATION : 00:25:25.107000000 DURATION-eng : 00:25:25.107000000 NUMBER_OF_FRAMES: 36566 NUMBER_OF_FRAMES-eng: 36566 NUMBER_OF_BYTES : 180555811 NUMBER_OF_BYTES-eng: 180555811 _STATISTICS_WRITING_APP: mkvmerge v8.4.0 ('A better way to fly') 32bit _STATISTICS_WRITING_APP-eng: mkvmerge v8.4.0 ('A better way to fly') 32bit _STATISTICS_WRITING_DATE_UTC: 2015-10-16 19:35:27 _STATISTICS_WRITING_DATE_UTC-eng: 2015-10-16 19:35:27 _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES encoder : Lavc56.60.100 png Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> png (native)) Press [q] to stop, [?] for help frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A video:1109kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

回答1:

The -copyts option should be added.

ffmpeg -ss 00:09:18 -copyts -i movie.mkv -vf subtitles=subtitles.srt -vframes 1 screenshot.png

The subtitles filter relies on input timestamps to know when to overlay subtitles, but a fast seek (-ss before -i) resets the timestamps of the trimmed portion before passing it along to the subtitles filter.



标签: ffmpeg