Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ffmpeg to extract multiple images from video and get timestamp of extracted images

Tags:

video

ffmpeg

I'm using ffmpeg to extract one frame (as a jpeg) every five minutes from videos, and piping the output from the console to a text file in order to get the exact timestamps of the extracted frames.

The command I'm using is:

ffmpeg -i input.avi -ss 00:10:00 -vframes 10 -vf showinfo,fps=fps=1/300 %03d.jpg &> output.txt

Where -ss 00:10:00 lets me skip ahead 10 mins in the video before starting, and -vframes 10 lets me capture only the first 10 frames (1 frame per 5 mins).

This almost works fine except that the command outputs information for all frames, including those that were not written as a jpeg. Here's a three line sample output:

[Parsed_showinfo_0 @ 0x2219020] n:11427 pts:11429 pts_time:599.979 pos:48892180 fmt:yuv420p sar:1/1 s:640x480 i:P iskey:0 type:P checksum:6309A75D plane_checksum:[15A29007 1617E1FE D93A3549] mean:[146 125 153 ] stdev:[17.6 1.0 2.1 ]
[Parsed_showinfo_0 @ 0x2219020] n:11428 pts:11430 pts_time:600.031 pos:48898094 fmt:yuv420p sar:1/1 s:640x480 i:P iskey:0 type:B checksum:815D031A plane_checksum:[E004E973 E28CE2D5 F56636B4] mean:[146 125 153 ] stdev:[17.6 1.0 2.1 ]
[Parsed_showinfo_0 @ 0x2219020] n:11429 pts:11431 pts_time:600.084 pos:48892448 fmt:yuv420p sar:1/1 s:640x480 i:P iskey:0 type:P checksum:6CE2D3C5 plane_checksum:[E983BD86 38B9E198 93B13498] mean:[146 125 153 ] stdev:[17.6 1.0 2.1 ]

I would expect the middle line, with pts_time:600.031, to be the first frame extracted as an image, but have no way to distinguish it from the other frames either side, where images were not extracted.

Does anyone know of a way to resolve this?

Thank you!

like image 869
jogall Avatar asked Jun 26 '14 14:06

jogall


1 Answers

You can use -vf showinfo for get frame information using ffmpeg . For example extracting frame when scene change and get time stamp for that particular frame.

ffmpeg -i image.mp4 -filter:v "select='gt(scene,0.1)',showinfo" -vsync 0 frames%05d.jpg >& output.txt

You will output similar like : [Parsed_showinfo_1 @ 0x25bf900] n: 0 pts: 119357 pts_time:9.95637 .... Our interest part is pts_time, Getting time use following command:

grep showinfo ffout | grep pts_time:[0-9.]* -o | grep '[0-9]*\.[0-9]*' -o > timestamps

You will get similar output:

9.95637
9.98974
15.0281
21.8016
28.208
28.4082
28.5083
like image 115
Suresh Saini Avatar answered Nov 15 '22 10:11

Suresh Saini