Reputation: 23
How to get the time stamp of the extracted image obtained by using ffmpeg
? What option is to be passed to the ffmpeg
command?
The current command that i am using is:
ffmpeg -i video.mp4 -vf select='gt(scene\,0.3)' -vsync 0 -an keyframes%03d.jpg
Upvotes: 2
Views: 5555
Reputation: 106
A small update to @DeWil's answer (sorry could not comment as I do not have enough reputations). The below answer gives the appropriate timestamp by matching with the regular expresion for timestamp "t:" not "pts:".
from subprocess import check_output
import re
pts = str(check_output('ffmpeg -i input.mp4 -vf select="eq(pict_type\,I)" -an -vsync 0 keyframes%03d.jpg -loglevel debug 2>&1 |findstr select:1 ',shell=True),'utf-8') #replace findstr with grep on Linux
pts = [float(i) for i in re.findall(r"\bt:(\d+\.\d)", pts)] # Find pattern that starts with "t:"
print(pts)
Upvotes: 0
Reputation: 362
As this question is tagged in python, I would like to add the following solution for Python developers:
from subprocess import check_output
import re
pts = str(check_output('ffmpeg -i video.mp4 -vf select="eq(pict_type\,I)" -an -vsync 0 keyframes%03d.jpg -loglevel debug 2>&1 |findstr select:1 ',shell=True),'utf-8') #replace findstr with grep on Linux
pts = [float(i) for i in re.findall(r"\bpts:(\d+\.\d)", pts)] # Find pattern that starts with "pts:"
print(pts)
Upvotes: 1
Reputation: 61
Extracting frame while scene change and get time for particular frame . May following line might helps:
ffmpeg -i image.mp4 -filter:v "select='gt(scene,0.1)',showinfo" -vsync 0 frames%05d.jpg >& output.txt
You will get output like: [Parsed_showinfo_1 @ 0x25bf900] n: 0 pts: 119357 pts_time:9.95637 pos: 676702..... You need to extract pts_time for that run following command.
grep showinfo ffout | grep pts_time:[0-9.]* -o | grep '[0-9]*\.[0-9]*' -o > timestamps
Using above command you will find following:
9.95637
9.98974
15.0281
21.8016
28.208
28.4082
Upvotes: 2
Reputation: 898
An option could be to write timestamps directly over each frame, using drawtext
video filter.
On a Windows machine, using Zeranoe ffmpeg package you can type:
ffmpeg -i video.mp4 -vf "drawtext=fontfile=/Windows/Fonts/Arial.ttf: timecode='00\:00\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=30" tmp/frame%05d.jpg" -vsync 0 -an keyframes%03d.jpg
The command will dump frame timestamps in the lower part of each frame, with seconds resolution.
Please have a look here to get informations how to setup fonts enviroment variables for ffmpeg.
Upvotes: 1