Some questions about PTS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Some questions about PTS

Michael Koch
Hello all,

please comment if the following is right or wrong:

-- The timebase of a video (TB in setpts filter) is expressed in the
unit [s] (seconds).
-- The framerate of a video (FR in setpts filter) is expressed in the
unit [s^-1] (1/seconds).
-- In many cases the timebase is the reciprocal of the framerate, but
this isn't always the case.
-- If the timebase is the reciprocal of the framerate, a stream can be
delayed by x frames using setpts=PTS+x
-- In the more general case for arbitrary timebase and framerate, a
stream can be delayed by x frames using setpts=PTS+x/(FR*TB)

Michael


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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Nicolas George
Michael Koch (12020-08-28):
> -- The timebase of a video (TB in setpts filter) is expressed in the unit
> [s] (seconds).
> -- The framerate of a video (FR in setpts filter) is expressed in the unit
> [s^-1] (1/seconds).
> -- In many cases the timebase is the reciprocal of the framerate, but this
> isn't always the case.

Looks mostly correct.

> -- If the timebase is the reciprocal of the framerate, a stream can be
> delayed by x frames using setpts=PTS+x
> -- In the more general case for arbitrary timebase and framerate, a stream
> can be delayed by x frames using setpts=PTS+x/(FR*TB)

"Delayed by x frame" is only relevant for a stream with constant frame
per second. Please think first and foremost about timestamps and as
little as possible in terms of number of frames.

Regards,

--
  Nicolas George

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

kumowoon1025
In reply to this post by Michael Koch
Hello,

I am not confident about this info but I've always thought the timebase is usually the reciprocal of the framerate *or smaller*. As in, the duration of a frame can be represented accurately enough as the difference between the timestamps, which aren't counted using seconds, but "ticks" in whatever timebase. So smaller fractions could be used as the timebase as long as the system is capable, and on the other hand, when you create low-fps video like 4fps, obviously the timebase isn't going to be 1/4, it'll probably have the same timebase as any other export. (I think of it as an analog wall clock, except it doesn't go tick-tock every second, it goes tick-tock every 1/90000 seconds.)

Actually, I think for the codec timebase, it is more common for it to be 1/2 the reciprocal of the frame rate; if that's codec-specific, I don't know why that is. Maybe you've also seen some setpts examples where you divide/multiply something by 2 for some arcane reason? Hopefully someone can explain further..

When you delay some frames by whatever amount, it necessarily effects a change in the frame rate (but not the timebase). I'm not sure where the FR value for setpts comes from, maybe it wouldn't matter if it stays the same as the nominal framerate if indicated by the media, but if it is something that can change, maybe the effective rate at the end of the chain, obviously it wouldn't work as expected.

Just for the sake of curiosity, what has you looking to delay frames using setpts? I feel there are easier methods.

Regards,
Ted Park

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Michael Koch
Am 28.08.2020 um 11:25 schrieb Edward Park:
> Hello,
>
> I am not confident about this info but I've always thought the timebase is usually the reciprocal of the framerate *or smaller*. As in, the duration of a frame can be represented accurately enough as the difference between the timestamps, which aren't counted using seconds, but "ticks" in whatever timebase. So smaller fractions could be used as the timebase as long as the system is capable, and on the other hand, when you create low-fps video like 4fps, obviously the timebase isn't going to be 1/4, it'll probably have the same timebase as any other export. (I think of it as an analog wall clock, except it doesn't go tick-tock every second, it goes tick-tock every 1/90000 seconds.)
>
> Actually, I think for the codec timebase, it is more common for it to be 1/2 the reciprocal of the frame rate; if that's codec-specific, I don't know why that is. Maybe you've also seen some setpts examples where you divide/multiply something by 2 for some arcane reason? Hopefully someone can explain further..
>
> When you delay some frames by whatever amount, it necessarily effects a change in the frame rate (but not the timebase). I'm not sure where the FR value for setpts comes from, maybe it wouldn't matter if it stays the same as the nominal framerate if indicated by the media, but if it is something that can change, maybe the effective rate at the end of the chain, obviously it wouldn't work as expected.
>
> Just for the sake of curiosity, what has you looking to delay frames using setpts? I feel there are easier methods.

Let's assume the framerate is constant. For example, I want to delay a
video by 5 frames and then hstack the original video and the delayed
version:

ffmpeg -i test.mp4 -vf
"split[a][b];[b]setpts=PTS+5/(FR*TB)[c];[a][c]hstack" -y out.mp4

Are there other / better / easier methods to do the same thing?

Michael

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Paul B Mahol
On 8/28/20, Michael Koch <[hidden email]> wrote:

> Am 28.08.2020 um 11:25 schrieb Edward Park:
>> Hello,
>>
>> I am not confident about this info but I've always thought the timebase is
>> usually the reciprocal of the framerate *or smaller*. As in, the duration
>> of a frame can be represented accurately enough as the difference between
>> the timestamps, which aren't counted using seconds, but "ticks" in
>> whatever timebase. So smaller fractions could be used as the timebase as
>> long as the system is capable, and on the other hand, when you create
>> low-fps video like 4fps, obviously the timebase isn't going to be 1/4,
>> it'll probably have the same timebase as any other export. (I think of it
>> as an analog wall clock, except it doesn't go tick-tock every second, it
>> goes tick-tock every 1/90000 seconds.)
>>
>> Actually, I think for the codec timebase, it is more common for it to be
>> 1/2 the reciprocal of the frame rate; if that's codec-specific, I don't
>> know why that is. Maybe you've also seen some setpts examples where you
>> divide/multiply something by 2 for some arcane reason? Hopefully someone
>> can explain further..
>>
>> When you delay some frames by whatever amount, it necessarily effects a
>> change in the frame rate (but not the timebase). I'm not sure where the FR
>> value for setpts comes from, maybe it wouldn't matter if it stays the same
>> as the nominal framerate if indicated by the media, but if it is something
>> that can change, maybe the effective rate at the end of the chain,
>> obviously it wouldn't work as expected.
>>
>> Just for the sake of curiosity, what has you looking to delay frames using
>> setpts? I feel there are easier methods.
>
> Let's assume the framerate is constant. For example, I want to delay a
> video by 5 frames and then hstack the original video and the delayed
> version:
>
> ffmpeg -i test.mp4 -vf
> "split[a][b];[b]setpts=PTS+5/(FR*TB)[c];[a][c]hstack" -y out.mp4
>
> Are there other / better / easier methods to do the same thing?
>

Yes, not using split filter, but using "-i test.mp4" twice.
Should generally use less memory for big offsets.

> Michael
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

kumowoon1025
In reply to this post by Michael Koch
Hi,

> Let's assume the framerate is constant. For example, I want to delay a video by 5 frames and then hstack the original video and the delayed version:
>
> ffmpeg -i test.mp4 -vf "split[a][b];[b]setpts=PTS+5/(FR*TB)[c];[a][c]hstack" -y out.mp4


I would try tpad=start=5, but I'm not sure what happens for the first 5 frames... If your example works I'm pretty sure it would work.

> ffmpeg -i test.mp4 -vf "split[a],tpad=start=5[b];[a][b]hstack" -y out.mp4

Regards,
Ted Park

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Nicolas George
In reply to this post by Michael Koch
Michael Koch (12020-08-28):
> Let's assume the framerate is constant. For example, I want to delay a video
> by 5 frames and then hstack the original video and the delayed version:

No, let us not make unfounded asumption and let us think in terms of
timestamps. Anything else is a waste of time.

--
  Nicolas George

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Michael Koch
In reply to this post by kumowoon1025
Am 28.08.2020 um 13:38 schrieb Edward Park:
> Hi,
>
>> Let's assume the framerate is constant. For example, I want to delay a video by 5 frames and then hstack the original video and the delayed version:
>>
>> ffmpeg -i test.mp4 -vf "split[a][b];[b]setpts=PTS+5/(FR*TB)[c];[a][c]hstack" -y out.mp4
>
> I would try tpad=start=5, but I'm not sure what happens for the first 5 frames... If your example works I'm pretty sure it would work.
>
>> ffmpeg -i test.mp4 -vf "split[a],tpad=start=5[b];[a][b]hstack" -y out.mp4

yes, that does also work fine. For the first 5 frames it's black, or the
first frame can be cloned if "start_mode=clone" is added.

Michael

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Mark Filipak
In reply to this post by Michael Koch
On 08/28/2020 03:51 AM, Michael Koch wrote:

> Hello all,
>
> please comment if the following is right or wrong:
>
> -- The timebase of a video (TB in setpts filter) is expressed in the unit [s] (seconds).
> -- The framerate of a video (FR in setpts filter) is expressed in the unit [s^-1] (1/seconds).
> -- In many cases the timebase is the reciprocal of the framerate, but this isn't always the case.
> -- If the timebase is the reciprocal of the framerate, a stream can be delayed by x frames using
> setpts=PTS+x
> -- In the more general case for arbitrary timebase and framerate, a stream can be delayed by x
> frames using setpts=PTS+x/(FR*TB)

I don't know enough yet to know whether this helps, but PTS in H.222 (§2.1.57) is: "A field that may
be present in a PES packet header that indicates the time that a presentation unit is presented in
the system target decoder." It's a 33 bit field in the PES HEADER EXTENSION, starting at bit 4,

[0000.4] PTS: ---- 000- 0000 0000 0000 000- 1000 1001 1000 111-

and must be divided by 90KHz in order to yield seconds. I've seen it solely in key frames.

I've computed PTS and the deltas between PTSs for several dozen professionally authored videos and
they do not correlate to frames, even for CFR video. H.222 presents a decoding model and PTS seems
to conform to that model, not to the frames in the stream. H.222 appears to be insufficiently
documented to resolve the discrepancy. It remains mysterious but I hope to eventually resolve it.

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Some questions about PTS

Mark Filipak
In reply to this post by Michael Koch
The PTS value below: 000- 0000 0000 0000 000- 1000 1001 1000 111-, is for a particular case. It will
vary for other videos. I hope that didn't confuse you.

On 08/28/2020 03:51 AM, Michael Koch wrote:

> Hello all,
>
> please comment if the following is right or wrong:
>
> -- The timebase of a video (TB in setpts filter) is expressed in the unit [s] (seconds).
> -- The framerate of a video (FR in setpts filter) is expressed in the unit [s^-1] (1/seconds).
> -- In many cases the timebase is the reciprocal of the framerate, but this isn't always the case.
> -- If the timebase is the reciprocal of the framerate, a stream can be delayed by x frames using
> setpts=PTS+x
> -- In the more general case for arbitrary timebase and framerate, a stream can be delayed by x
> frames using setpts=PTS+x/(FR*TB)

I don't know enough yet to know whether this helps, but PTS in H.222 (§2.1.57) is: "A field that may
be present in a PES packet header that indicates the time that a presentation unit is presented in
the system target decoder." It's a 33 bit field in the PES HEADER EXTENSION, starting at bit 4,

[0000.4] PTS: ---- 000- 0000 0000 0000 000- 1000 1001 1000 111-

and must be divided by 90KHz in order to yield seconds. I've seen it solely in key frames.

I've computed PTS and the deltas between PTSs for several dozen professionally authored videos and
they do not correlate to frames, even for CFR video. H.222 presents a decoding model and PTS seems
to conform to that model, not to the frames in the stream. H.222 appears to be insufficiently
documented to resolve the discrepancy. It remains mysterious but I hope to eventually resolve it.

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".