21

When using ffmpeg to output a series of frames as images, the only format I can find documentation for is frame_%d.jpg. The %d identifier is replaced by the sequential frame count.

Are there other parameters I can use in the output file format? Specifically, I need the ability to add the timestamp of the specific frame.

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395

6 Answers6

12

Turns out this behavior was not yet implemented at the time.

I implemented an initial version of %t support on my fork of FFmpeg (https://github.com/yuvadm/FFmpeg), and am currently working on cleaning up the patch so that it can be merged upstream.

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
  • 5
    Did you ever submit this to the core project? There's an [open 3yr-old request](https://trac.ffmpeg.org/ticket/1452) (that I found while trying to do this myself). – Su' Jul 16 '15 at 08:26
  • @YuvalAdam take a look to [your ffmpeg repo on github](https://github.com/yuvadm/FFmpeg/commit/e1524dda42c9056f393a0ec0eb494d5dc31e2b1e#commitcomment-19635439) please. :) – Florida Oct 31 '16 at 17:34
  • 1
    @florida I've added an updated patch to https://trac.ffmpeg.org/ticket/1452 which is Works on My Machine™ certified since I was searching for this functionality. – magixx Jun 18 '21 at 21:55
6

The strftime option allows you to expand the filename with date and time information. Check the documentation of the strftime() function for the syntax.

For example to generate image files from the strftime() %Y-%m-%d_%H-%M-%S pattern, the following ffmpeg command can be used:

ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg"
jqgsninimo
  • 6,562
  • 1
  • 36
  • 30
  • 8
    As far as I understand, this will output the actual time and date, while my requirement is for the running time of the video. – Yuval Adam Apr 11 '14 at 09:15
  • Unfortunately only "second" granularity (gives wall clock time) but it does work... – rogerdpack Aug 31 '16 at 17:27
  • For those of us on Ubuntu 14 who a forced to use avconv the strftime option is not available for segmentation. I couldn't find a workaround, but was able to install FFMPEG on ubuntu 14 by doing `sudo add-apt-repository ppa:mc3man/trusty-media` `sudo apt-get update` `sudo apt-get dist-upgrade` `sudo apt-get install ffmpeg` – Tycon Sep 12 '16 at 02:45
2

I hacked up a bash script that creates file names based on time into the film. It uses a format: "hh_mm_ss" in the file name. You can see it at:

https://github.com/pozar/makemoviethumbs

pozar
  • 21
  • 1
1

Another option you'd have would be to run ffprobe -show_packets on it, and use that data to "infer" the timestamp of each generated jpg file (assuming you generate one per incoming video frame). Yikes!

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
0

For number of frames can use report with special debug mode:

FFREPORT=file=\'file.log\':level=48 && ffmpeg ... -vf select=eq(pict_type\,PICT_TYPE_I) -vsync vfr -f image2 OUTPUT

then you can match the name with preg_match_all:

preg_match_all("/] n:(\\d+)\\.[^>]+pict_type:I/Us",$log,$m,PREG_PATTERN_ORDER,5000);
$frames=$m[1];

Please enjoy!

pirs
  • 2,410
  • 2
  • 18
  • 25
0

You can try %s with -strftime if you want to attach epoch.

Example :

ffmpeg -rtsp_transport tcp -i 'input.mp4' -vf fps=1 -strftime 1 "%s_frame.png"
Mihir
  • 11
  • 3