Is there a script that can take screenshots of random frames in a video file, with subtitles?

@realcaseyrollins I think a shell script around ffmpeg is the way to go.

-count_frames to get the range
-vf select to just grab a certain frame

Follow

@realcaseyrollins looks like you would just have to pass -copyts as an option alongside -vf select

I wasn’t able to get this to work for me, I’ll look around to see what works for me tho

@realcaseyrollins here's a Bash script that shows what I meant. Working from a random frame is slower than from a timestamp but it gets there in the end. You just have to provide two arguments: video file and subtitle file.

#!/bin/bash

framecount=$(ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 "$1");
(( randomframe = ( $RANDOM * 2**15 + $RANDOM ) % $framecount ));

ffmpeg -copyts -i "$1" -vf "subtitles=$2,select=gte(n\,$randomframe)" -vframes 1 "$1.png"

Does that work with #PGS subtitles? My copy of #ffmpeg is choking on the subtitles, although it can take screenshots without the subtitles well enough.

@realcaseyrollins the documentation suggests it's possible, but I don't think I have anything with PGS subtitles that I could test. If you point me to a test case I can download from somewhere, I'll take a look

If I gave you my file, that would be piracy 😂 And although I did use #ffmpeg to extract the #PGS subtitle into a .sup file, it’s too big for to file upload requirements here.

So I’ve made two bat files so far. One is working, but doesn’t have subtitles:

ffmpeg -i Arrival_t00.mkv -ss 00:05:02 -frames:v 1 foobar.png

The other one, on the first line, successfully extracts the subtitles:

ffmpeg -i Arrival_t00.mkv -map 0:s:0 -c copy out.sup

And then has multiple failed attempts to take a burnt-in screenshot:

ffmpeg -i Arrival_t00.mkv -ss 00:05:02 -frames:v 1 -vf subtitles=out.sup foobar2.png

ffmpeg -i Arrival_t00.mkv -ss 00:05:02 -map 0:v -map 0:s:0 -filter_complex “[0:v][0:s:0]overlay[v]” foobar2.png

ffmpeg -i Arrival_t00.mkv -i Arrival_t00.mkv -map 0:6 -ss 00:05:02 -frames:v 60 mp4 output.mp4

With the last line, I was hoping to make a burnt-in #MP4 and then take a screenshot of that video.

@realcaseyrollins if you can cut down the video to a few seconds of dialogue I would think you could upload that to e.g. dropbox under fair use rules. Your commands look pretty much like what I'd be trying though so I think you're on the right track

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.