How to output real frame number instead of sequentially added image numbers

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to output real frame number instead of sequentially added image numbers

bernard vrh
How to output real frame number instead of sequentially added image numbers

Hello,

I trying to generate scene change keyframes from input video file.

Using   %d.jpeg   output a series of jpeg frames as images named in
sequential order.. and such labeled images (keyframes) do not
representing real time code or reflecting time position of keyframe
images in input video clip.

the only parameter which works is %d

My example:

ffmpeg  -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2
-s 200x112  -f image2  "D:\myoutput_frames\%d.jpeg"

Please suggest which parameter should be used instead of  %d  to
output video time code stamp  or video frame number,  zero or one
based relative to input video clip.


Kind regards,

Bernard
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to output real frame number instead of sequentially added image numbers

Tracey Jaquith
Hi Bernard,

This kind of was a maddeningly needed/wanted feature for me, too 8-)
and actually one step further -- I wanted the actual seconds as close as
possible from the start for each frame extracted.  (If this works for you, you
could tailor it to taste for either frame# (easier) or seconds-from-start like
it will do by default).  I'm nearly certain there is no option to do what you suggest
but OTOH I love to be wrong so I don't need to code 8-)

This isn't really ready for primetime (I'm hacking around by stashing some new globals to
get information in the detection/identify part of the code) but it seems
to work pretty nicely.  Very recently, I was using avidemux to make an .idx
(index) file for MPEG1/MPEG2/MPEG-TS and then parsing it to find
the timestamp of GOP for a given frame number to go from
   "frame number" => "seconds from start"
(but now with the updated/current patch, I get very close to the number of seconds
 directly with the patched ffmpeg).

http://archive.org/~tracey/downloads/patches/ffmpeg-thumbnails.patch


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

hope that helps!
-Tracey


On Jan 22, 2013, at 12:56 AM, bernard vrh <[hidden email]> wrote:

> How to output real frame number instead of sequentially added image numbers
>
> Hello,
>
> I trying to generate scene change keyframes from input video file.
>
> Using   %d.jpeg   output a series of jpeg frames as images named in
> sequential order.. and such labeled images (keyframes) do not
> representing real time code or reflecting time position of keyframe
> images in input video clip.
>
> the only parameter which works is %d
>
> My example:
>
> ffmpeg  -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2
> -s 200x112  -f image2  "D:\myoutput_frames\%d.jpeg"
>
> Please suggest which parameter should be used instead of  %d  to
> output video time code stamp  or video frame number,  zero or one
> based relative to input video clip.
>
>
> Kind regards,
>
> Bernard
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to output real frame number instead of sequentially added image numbers

bernard vrh
Hi Tracey,

in the mean time I've found one link with old code, seems not working in
newer FFMPEG release as still a lot work should be done to adopt code to
newest release.

the code was provide from Yuval Adam

http://ffmpeg.org/pipermail/ffmpeg-devel/2011-December/117830.html

The idea behind Yuval work is to replace %d parameter with  %t
parameter, but this parameter is already now in use %T  or %t for log
file creation and will probably be in collision with our intention for
labeling Keyframes.


My idea here is to introduce descriptive names instead.

Example:

%frames   will output    12345.jpg

complete command line will be:

ffmpeg -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2 -s 200x112  -f image2  "D:\myoutput_file\%frames.jpeg"


when the FFMPEG is in debug mode  (  - loglevel debug  ) all this
information is already there:

ffmpeg   - loglevel debug  -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2
-s 200x112  -f image2  "D:\myoutput_frames\%d.jpeg"

above command line produces  file named   "ffmpeg-20130123-005308.log"  (generated today) and a part of file is:

frame=    3 fps=0.0 q=0.0 size=N/A time=00:00:00.52 bitrate=N/A n:34
pts:122400 t:1.360000 pos:180224 key:0 interlace_type:P pict_type:P
scene:nan -> select:0.000000
frame=  319 fps=1.5 q=0.0 size=N/A time=00:02:31.80 bitrate=N/A n:3811
pts:13719600 t:152.440000 pos:17766412 key:0 interlace_type:P
pict_type:P scene:nan -> select:0.000000

You can find that the "frame"  is the name of  the Generated outgoing
images  and the corresponding frame number is n: (keyframe)

D:\myoutput_frames\3.jpg and D:\myoutput_frames\319.jpg in this case.  and there is also n: parameter which is in fact the correct frame number from input file

So:
frame=  3 = n:34
frame=  319  = n:3811

interpreting n: you can produce time code image name or in your case the
time offset from start of the input video clip.

I think this is also the solution of your problem..

What we must do is to selectively link what is generated from  -
loglevel debug parameter and then with this information (n:) renaming
outgoing (generated)  images.

Regards,

Bernard

On 22.1.2013 23:55, tracey jaquith wrote:

> Hi Bernard,
>
> This kind of was a maddeningly needed/wanted feature for me, too 8-)
> and actually one step further -- I wanted the actual seconds as close as
> possible from the start for each frame extracted.  (If this works for you, you
> could tailor it to taste for either frame# (easier) or seconds-from-start like
> it will do by default).  I'm nearly certain there is no option to do what you suggest
> but OTOH I love to be wrong so I don't need to code 8-)
>
> This isn't really ready for primetime (I'm hacking around by stashing some new globals to
> get information in the detection/identify part of the code) but it seems
> to work pretty nicely.  Very recently, I was using avidemux to make an .idx
> (index) file for MPEG1/MPEG2/MPEG-TS and then parsing it to find
> the timestamp of GOP for a given frame number to go from
>     "frame number" => "seconds from start"
> (but now with the updated/current patch, I get very close to the number of seconds
>   directly with the patched ffmpeg).
>
> http://archive.org/~tracey/downloads/patches/ffmpeg-thumbnails.patch
>
>
> 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
>
> hope that helps!
> -Tracey
>
>
> On Jan 22, 2013, at 12:56 AM, bernard vrh <[hidden email]> wrote:
>
>> How to output real frame number instead of sequentially added image numbers
>>
>> Hello,
>>
>> I trying to generate scene change keyframes from input video file.
>>
>> Using   %d.jpeg   output a series of jpeg frames as images named in
>> sequential order.. and such labeled images (keyframes) do not
>> representing real time code or reflecting time position of keyframe
>> images in input video clip.
>>
>> the only parameter which works is %d
>>
>> My example:
>>
>> ffmpeg  -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2
>> -s 200x112  -f image2  "D:\myoutput_frames\%d.jpeg"
>>
>> Please suggest which parameter should be used instead of  %d  to
>> output video time code stamp  or video frame number,  zero or one
>> based relative to input video clip.
>>
>>
>> Kind regards,
>>
>> Bernard
>> _______________________________________________
>> ffmpeg-user mailing list
>> [hidden email]
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to output real frame number instead of sequentially added image numbers

Stefano Sabatini-2
On date Wednesday 2013-01-23 13:22:57 +0100, Bernard wrote:

> Hi Tracey,
>
> in the mean time I've found one link with old code, seems not
> working in newer FFMPEG release as still a lot work should be done
> to adopt code to newest release.
>
> the code was provide from Yuval Adam
>
> http://ffmpeg.org/pipermail/ffmpeg-devel/2011-December/117830.html
>
> The idea behind Yuval work is to replace %d parameter with  %t
> parameter, but this parameter is already now in use %T  or %t for
> log file creation and will probably be in collision with our
> intention for labeling Keyframes.
>
>
> My idea here is to introduce descriptive names instead.
>
> Example:
>
> %frames   will output    12345.jpg
>
> complete command line will be:
>
> ffmpeg -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2 -s 200x112  -f image2  "D:\myoutput_file\%frames.jpeg"
>
>
> when the FFMPEG is in debug mode  (  - loglevel debug  ) all this
> information is already there:
>
> ffmpeg   - loglevel debug  -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2
> -s 200x112  -f image2  "D:\myoutput_frames\%d.jpeg"
>
> above command line produces  file named   "ffmpeg-20130123-005308.log"  (generated today) and a part of file is:
>
> frame=    3 fps=0.0 q=0.0 size=N/A time=00:00:00.52 bitrate=N/A n:34
> pts:122400 t:1.360000 pos:180224 key:0 interlace_type:P pict_type:P
> scene:nan -> select:0.000000
> frame=  319 fps=1.5 q=0.0 size=N/A time=00:02:31.80 bitrate=N/A
> n:3811 pts:13719600 t:152.440000 pos:17766412 key:0 interlace_type:P
> pict_type:P scene:nan -> select:0.000000
>
> You can find that the "frame"  is the name of  the Generated
> outgoing images  and the corresponding frame number is n: (keyframe)
>
> D:\myoutput_frames\3.jpg and D:\myoutput_frames\319.jpg in this case.  and there is also n: parameter which is in fact the correct frame number from input file
>
> So:
> frame=  3 = n:34
> frame=  319  = n:3811
>
> interpreting n: you can produce time code image name or in your case
> the time offset from start of the input video clip.
>
> I think this is also the solution of your problem..
>
> What we must do is to selectively link what is generated from  -
> loglevel debug parameter and then with this information (n:)
> renaming outgoing (generated)  images.
>
> Regards,
>
> Bernard
>
> On 22.1.2013 23:55, tracey jaquith wrote:
> >Hi Bernard,
> >
> >This kind of was a maddeningly needed/wanted feature for me, too 8-)
> >and actually one step further -- I wanted the actual seconds as close as
> >possible from the start for each frame extracted.  (If this works for you, you
> >could tailor it to taste for either frame# (easier) or seconds-from-start like
> >it will do by default).  I'm nearly certain there is no option to do what you suggest
> >but OTOH I love to be wrong so I don't need to code 8-)
> >
> >This isn't really ready for primetime (I'm hacking around by stashing some new globals to
> >get information in the detection/identify part of the code) but it seems
> >to work pretty nicely.  Very recently, I was using avidemux to make an .idx
> >(index) file for MPEG1/MPEG2/MPEG-TS and then parsing it to find
> >the timestamp of GOP for a given frame number to go from
> >    "frame number" => "seconds from start"
> >(but now with the updated/current patch, I get very close to the number of seconds
> >  directly with the patched ffmpeg).
> >
> >http://archive.org/~tracey/downloads/patches/ffmpeg-thumbnails.patch
> >
> >
> >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

[...]

Please avoid top-posting on this list.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to output real frame number instead of sequentially added image numbers

Tracey Jaquith

On Jan 29, 2013, at 4:20 PM, Stefano Sabatini <[hidden email]> wrote:

> On date Wednesday 2013-01-23 13:22:57 +0100, Bernard wrote:
>> Hi Tracey,
>>
>> in the mean time I've found one link with old code, seems not
>> working in newer FFMPEG release as still a lot work should be done
>> to adopt code to newest release.
>>
>> the code was provide from Yuval Adam
>>
>> http://ffmpeg.org/pipermail/ffmpeg-devel/2011-December/117830.html
>>
>> The idea behind Yuval work is to replace %d parameter with  %t
>> parameter, but this parameter is already now in use %T  or %t for
>> log file creation and will probably be in collision with our
>> intention for labeling Keyframes.
>>
>>
>> My idea here is to introduce descriptive names instead.
>>
>> Example:
>>
>> %frames   will output    12345.jpg
>>
>> complete command line will be:
>>
>> ffmpeg -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2 -s 200x112  -f image2  "D:\myoutput_file\%frames.jpeg"
>>
>>
>> when the FFMPEG is in debug mode  (  - loglevel debug  ) all this
>> information is already there:
>>
>> ffmpeg   - loglevel debug  -i "C:\myfilename.avi"  -vf select="eq(pict_type\,I)" -vsync 2
>> -s 200x112  -f image2  "D:\myoutput_frames\%d.jpeg"
>>
>> above command line produces  file named   "ffmpeg-20130123-005308.log"  (generated today) and a part of file is:
>>
>> frame=    3 fps=0.0 q=0.0 size=N/A time=00:00:00.52 bitrate=N/A n:34
>> pts:122400 t:1.360000 pos:180224 key:0 interlace_type:P pict_type:P
>> scene:nan -> select:0.000000
>> frame=  319 fps=1.5 q=0.0 size=N/A time=00:02:31.80 bitrate=N/A
>> n:3811 pts:13719600 t:152.440000 pos:17766412 key:0 interlace_type:P
>> pict_type:P scene:nan -> select:0.000000
>>
>> You can find that the "frame"  is the name of  the Generated
>> outgoing images  and the corresponding frame number is n: (keyframe)
>>
>> D:\myoutput_frames\3.jpg and D:\myoutput_frames\319.jpg in this case.  and there is also n: parameter which is in fact the correct frame number from input file
>>
>> So:
>> frame=  3 = n:34
>> frame=  319  = n:3811
>>
>> interpreting n: you can produce time code image name or in your case
>> the time offset from start of the input video clip.
>>
>> I think this is also the solution of your problem..
>>
>> What we must do is to selectively link what is generated from  -
>> loglevel debug parameter and then with this information (n:)
>> renaming outgoing (generated)  images.
>>
>> Regards,
>>
>> Bernard
>>
>> On 22.1.2013 23:55, tracey jaquith wrote:
>>> Hi Bernard,
>>>
>>> This kind of was a maddeningly needed/wanted feature for me, too 8-)
>>> and actually one step further -- I wanted the actual seconds as close as
>>> possible from the start for each frame extracted.  (If this works for you, you
>>> could tailor it to taste for either frame# (easier) or seconds-from-start like
>>> it will do by default).  I'm nearly certain there is no option to do what you suggest
>>> but OTOH I love to be wrong so I don't need to code 8-)
>>>
>>> This isn't really ready for primetime (I'm hacking around by stashing some new globals to
>>> get information in the detection/identify part of the code) but it seems
>>> to work pretty nicely.  Very recently, I was using avidemux to make an .idx
>>> (index) file for MPEG1/MPEG2/MPEG-TS and then parsing it to find
>>> the timestamp of GOP for a given frame number to go from
>>>   "frame number" => "seconds from start"
>>> (but now with the updated/current patch, I get very close to the number of seconds
>>> directly with the patched ffmpeg).
>>>
>>> http://archive.org/~tracey/downloads/patches/ffmpeg-thumbnails.patch
>>>
>>>
>>> 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-)
--Tracey  (archive.org)


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to output real frame number instead of sequentially added image numbers

Stefano Sabatini-2
On date Tuesday 2013-01-29 18:17:50 -0800, tracey jaquith wrote:
>
> On Jan 29, 2013, at 4:20 PM, Stefano Sabatini <[hidden email]> 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).
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to output real frame number instead of sequentially added image numbers

Tracey Jaquith

On Jan 30, 2013, at 11:00 AM, Stefano Sabatini <[hidden email]> wrote:

> On date Tuesday 2013-01-29 18:17:50 -0800, tracey jaquith wrote:
>>
>> On Jan 29, 2013, at 4:20 PM, Stefano Sabatini <[hidden email]> 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


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user