[FFmpeg-user] How to output real frame number instead of sequentially added image numbers
Tracey Jaquith
tracey at archive.org
Wed Jan 30 20:30:59 CET 2013
On Jan 30, 2013, at 11:00 AM, Stefano Sabatini <stefasab at gmail.com> wrote:
> On date Tuesday 2013-01-29 18:17:50 -0800, tracey jaquith wrote:
>>
>> On Jan 29, 2013, at 4:20 PM, Stefano Sabatini <stefasab at gmail.com> wrote:
>>
>>> On date Wednesday 2013-01-23 13:22:57 +0100, Bernard wrote:
> [...]
>>>>> I would second an option (and would be happy to work on a more robust unhacky
>>>>> solution/patch for consideration?) to output the #seconds or frame number
>>>>> of each output frame
>>>>>
>>>>> (My build and patch applying scripts, overall, is here, given the kinds of things
>>>>> we do at my work (h.264 and ogv theora creation, vpx/WebM possible)):
>>>>>
>>>>> http://archive.org/~tracey/downloads/ffmpeg-README.txt
>>>
>>> This is ticket #1452:
>>> https://ffmpeg.org/trac/ffmpeg/ticket/1452
>>>
>>> Also see the recent thread:
>>> http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/158092
>>>
>>> [...]
>>
>> Thanks, Stefano!
>> Does the ticket mean I'm working on it or someone else is? 8-)
>
> If you're interested you could join the discussion, once we agree on
> the design we can implement it (better than implementing it and find
> out that we don't agree on the design).
>
> Possibly an extended pattern like
> foobar-%{n:%03d}-%{time:%H-%m-%s}-%{pts}.jpeg, similar to what we
> recently did with drawtext, may be good enough (while my current
> approach is possibly not extensible enough).
Hi Stefano,
I'm fine with that extended pattern (I only happen to want #seconds, but obviously can see the value of adding
lots of options for multiple folks' wants/needs/wishes. 8-)
I found the three keys from spending a bunch of time diving deep (and coming up with thankfully very little needed code changes) were:
(1) for the frame number (not needed directly for just the time of the extracted keyframe), we seem to need the "ist->st->codec->frame_number", which I was passing in as hacky new "pass thru" from ffmpeg.c into a new struct element in avformat.h. that gives us the frame number (I think the %{n:%03d} above, if I understand the pattern suggestion).
(2) to get the pts, I seemed to need the "ist->decoded_frame->pts" from ffmpeg.c, "pass thru" as a similar hack.
(3) to get from "pts" to accurate HH:MM:SS, I seemed to need the "tbn" from libavformat/utils.c passed through.
that way, in the img2enc.c, we can do
+ long sec = (s->ptsxxx==AV_NOPTS_VALUE || s->ptsxxx<0 ? 0 : (long int)floor( av_q2d(s->tbnxxx) * s->ptsxxx ));
and here is the relevant patch with all that (which we are now using live on archive.org for thumbnail extraction and relatively accurate timing (we have a lot of MPEG-TS TV recordings now where we need as close to accurate thumbnail timing filenames as possible):
http://archive.org/~tracey/downloads/patches/ffmpeg-thumbnails.patch
happy to join the discussion and chime in, shape, or work on a patch with others, clean-up my patch, etc.!
--tracey
More information about the ffmpeg-user
mailing list