3

I have the following command:

ffmpeg -f f32le -ar 44100 -channels 2 -i pipe:0 -ss 3 -i input.mp4 -y -f mp4 -map 0:a -map 1:v -c:v copy -use_editlist 0 output.mp4

When copying the video stream instead of re-encoding it, I can't get any useful information out of ffprobe that tells me the seeked position of the video stream.

I tried gathering information on the complete stream:

ffprobe -of json -show_streams -show_format output.mp4

But start_time is 0 and the duration is unaffected. I also tried gathering information on the first frame of the video stream:

ffprobe -of json -select_streams v -show_frames output.mp4

Still no useful information.

However, when I re-encode the video stream (by removing -c:v copy from the command), I get the information I want. The video stream duration is modified by the -ss option. For example if the duration of the video is 5, then ffprobe would return a duration of 2 (5 minus 3), which lets me know the seeked position. If I also throw in a -copyts to the mix, then I can get the useful information by checking the first frame's info.

How can I get the seeked position without having to re-encode the video stream? Cheers!

1 Answers1

3

If you've access to the original file and you've used

ffmpeg -f f32le -ar 44100 -channels 2 -i pipe:0 -ss X -i input.mp4 -y -f mp4 -map 0:a -map 1:v -c:v copy -use_editlist 0 output.mp4

then follow this method.

1) Get duration of source video stream

ffprobe source.mp4 -show_entries stream=duration -select_streams v -of compact=p=0 -v 0

Output e.g.

duration=229.033333

2) Get duration and first PTS of resulting video stream

ffprobe output.mp4 -show_entries packet=pts_time:stream=duration -select_streams v -read_intervals 0%+#1 -of compact=p=0 -v 0

Output e.g.

pts_time=0.066667
duration=220.700000

So, first frame in result is 229.033333 - 220.700000 = 8.333333s of the source stream.

However, this won't be the -ss value, since the -ss may not point to a keyframe.

3), So, get duration and PTS of first audio packet. ffmpeg will give it a prolonged duration to sync the audio with the specified -ss frame.

ffprobe output.mp4 -show_entries packet=pts_time,duration_time -select_streams a -read_intervals 0%+#1 -of compact=p=0 -v 0

Output e.g.

pts_time=0.000000|duration_time=2.733333

So, 8.333333s + 2.733333 - 0.000000 - 0.066667 = 11.000000s is the sought frame.

Gyan
  • 38,955