1

I'm doing some ffmpeg (4.1.3) transcodings by extracting specific frames from the source, in this case, the source can be either a movie or an image sequence, all working fine with the following command:

ffmpeg -i source.mov -vf select='eq(n\,2)+eq(n\,80)+eq(n\,150)' -vsync 0 -frame_pts 1 frames_%04d.jpeg

In the case of a source image sequence, I only need to specify the start number (since my frames usually start in 100 or further):

ffmpeg -start_number 94 -i source.%04d.png -vf select='eq(n\,2)+eq(n\,80)+eq(n\,150)' -vsync 0 -frame_pts 1 frames_%04d.jpeg

But the issue is that the frame numbers that I get match the exact numbers that I asked for, which are those required from the select filter and start at 0, in the example of the image sequence, you can see that it actually starts at frame 94, and technically the movies replicate the same, their first frame is the same as 94 in image sequence, and i will love to have a way to get the output numbers be offset by a certain number so they match the corresponding "source" frame.

I already tried adding a -start_number at the end before the output, which works with regular transcodes, but it seems not to work in combination of -frame_pts

I will love to be able to do something like this:

ffmpeg -start_number 94 -i source.%04d.png -vf select='eq(n\,2)+eq(n\,80)+eq(n\,150)' -vsync 0 -start_number 94 -frame_pts 1 frames_%04d.jpeg

And get frame 96, 174 and 244 instead of 2, 80 and 150.

Is there a way to do that ?

Thanks in advanced!

2 Answers 2

0

start_number is ignored with frame_pts, so a workaround is needed. A generic option output_ts_offset is available but it takes timestamp rather than frame number, so we first set the framerate of the images input as 1.

Use

ffmpeg -start_number 94 -framerate 1 -i source.%04d.png -vf select='eq(n\,2)+eq(n\,80)+eq(n\,150)' -vsync 0 -output_ts_offset 94 -frame_pts 1 frames_%04d.jpeg
0

You probably just need to adjust the pts with: setpts=PTS+(94*TB). You would need to adjust that 94 for each different start number
So:

ffmpeg -start_number 94 -i source.%04d.png -filter_complex select='eq(n\,2)+eq(n\,80)+eq(n\,150)';setpts=PTS+(94*TB) frames_%04d.jpeg

Also vsync is a bit unnecessary when outputting to jpg.

EDIT: Fixed the setpts-Expression, because I was stupid the first time. EDIT2: I can't even read the question properly it seems... Fixed the setpts-Expression again

1
  • Default vsync for images is CFR and so ffmpeg will duplicate frames when the timestamps between output frames is greater than that expected for adjacent frames. vsync 0 is needed to disable that.
    – Gyan
    Jun 18, 2020 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.