Name ffmpeg generated images using timestamp rather than sequential numbers
As far as I can tell from the ffmpeg docs, they don't provide a way to use timestamps in the filename rather than sequential numbers. What they provide allows you to create 0001.jpg, 0002.jpg, 0003.jpg but not 2011-08-01 7:30:00.jpg, 2011-08-01 7:30:01.j开发者_StackOverflowpg, 2011-08-01 7:30:02.jpg. Can anyone think of a solution that could take the sequentially named files from ffmpeg and name them using their created time?
At least the newer versions of ffmpeg
have the strftime
option that allow you to do what you want.
For example:
ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg"
Will generate files such as:
2015-11-20_16-25-06.jpg
On unixoid systems, you can use find + ImageMagick to identify each file and its creation date-time. ImageMagick normally has to be installed:
find -name "*.jpg" -execdir identify -verbose {} ";" -ls | egrep "(create|^Image)"
Image: ./logo-text-u-sinn.4.2.do.jpg
date:create: 2011-08-03T12:16:55+02:00
Image: ./tasten-in-tasse_3919.jpg
date:create: 2011-06-14T22:37:07+02:00
gnu:find is available for Windows too, but not normally distributed by Microsoft. Instead, Microsoft has its own, inferior (afaik) kind of find(.exe), with very different syntax.
So if you install gnu-find, it has to be called with the whole path, or renamed to gfind for example, to prevent name collision.
I would write a small script
#!/bin/bash
name=$1
dt=$(identify -verbose $name grep "create:")
datetime=${dt/*create:/}
mv $name $datetime.jpg
which is vulnerable to filenames, including blanks, but if your files are always named 0001.jpg and so on, it will be no problem.
The script would produce 2011-08-03T12:39:42+02:00
for example as a filename, and could be called by find:
find -name "*.jpg" -execdir ./myscript.sh {} ";"
If you don't use/have a bash, you need to modify it accordingly.
Warning:
You have to be careful. If the time of 2 or more files is identical, they will be silently overriden. Of course you may build a check into your script, and maybe your filesystem can store the date more precise than in seconds-interval.
I ran this grep on the source:
ffmpeg$ fgrep -r snprintf *|grep name
...
ffmpeg.c: snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
...
There is definitely the code to generate filenames with dates. You could try to run your command with the option -vstats. Perhaps it will generate a log file for each output file.
Unfortunately the code is quite complicated. I can't see right now, where the JPEG filename is created. If you have the program running its straight forward use 'strace' but I'm too lazy for that.
精彩评论