Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: CryGuy on July 01, 2018, 07:45:03 PM

Title: PTS of first frame
Post by: CryGuy on July 01, 2018, 07:45:03 PM
Hello,

I have a question only:
I've got an MP4 file with video=H.264 and audio=mp2. Opened in ADM, it shows the timestamp of the first frame as 0.082 s. I don't understand why. As I've already utilized the libav library myself before, I've dumped the timestamps of the file:

Min. video PTS = 0.160 s (4000/25000), min. audio PTS = 0.181 (8688/48000)
Min. video DTS = 0.080 s, min. audio DTS = 0.181

The start time of both streams (as defined in AVStream.start_time) is AV_NOPTS_VALUE. I'm curious how that 0.082 s is computed. I'm unable to derive it from the numbers I have. I'd be glad about some insight how the time of the first frame is computed. (acutally I've got a different issue, but first, I'd like to understand this)

Thank you!
Title: Re: PTS of first frame
Post by: eumagga0x2a on July 01, 2018, 09:03:34 PM
If a video contains B-frames, the display of the first keyframe must be delayed as Avidemux uses uint64_t to store timestamps. A B-frame depends on other frames both earlier and later in the presentation order, so everything must be delayed until these reference frames have been decoded.

FFmpeg uses int64_t for timestamps, so it can let a video with B-frames start at zero by making decode timestamps negative.

As a rule, the first frame delay is (nbRefFrames-1)*timeIncrement.
Title: Re: PTS of first frame
Post by: CryGuy on July 01, 2018, 09:45:49 PM
....Ok, my fault. It seems that the start_time value isn't set before a frame has been read from the stream (by calling av_read_frame).
Though, I'm afraid, I don't understand at all what you're saying. The first frame is a key frame (I frame). It has the smallest PTS (and DTS), so why do the following frames matter at all? Why not just display 0.16 s as the time for the first frame? Sorry for asking dumbly, but I don't get it.
Title: Re: PTS of first frame
Post by: eumagga0x2a on July 01, 2018, 10:43:35 PM
Quote from: CryGuy on July 01, 2018, 09:45:49 PM
The first frame is a key frame (I frame). It has the smallest PTS (and DTS), so why do the following frames matter at all? Why not just display 0.16 s as the time for the first frame?

Why should the delay be greater than necessary? It is pointless to have a non-zero first frame DTS. If you eliminate this offset, ffmpeg and Avidemux are pretty close. Following frames matter, because the alternative to delaying the first frame would be a hole after the first frame.

Imagine, we have a stream I(0)-P(1)-B(2)-B(3)-B(4)-P(5)-B(6)-B(7)-(I...). The display order is 0-2-3-4-1-6-7-5. We can't display 2 before we have decoded 1, so we delay everything by one time increment (max ref frames = 2).
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 12:59:23 AM
First, thanks for your reply!

QuoteWhy should the delay be greater than necessary?
It's not how I want it to be because the value is already there.

For me, only two things would make sense as to which timestamp is displayed:
- As stored in the source video. This means the first frame is at 0.16 s.
- All timestamps of all frames are shifted by -0.16 so that the first frame is at zero.

In no case it makes sense for me as a user that timestamps are shifted so that the first frame is at 0.082.

QuoteIt is pointless to have a non-zero first frame DTS.
For me, the DTS doesn't matter regarding this question and what is shown to the user. I've only mentioned DTS FYI if it might be relevant for explaining me how the 0.082 s have been computed.

QuoteFollowing frames matter, because the alternative to delaying the first frame would be a hole after the first frame.
Isn't this a question of the later encoding process? When I open a video, I expect to see what's in the file (of course, frames ordered by PTS). For frame 1, I expect to see the PTS of frame 1 in the status bar, for frame 2 the PTS of frame 2, and so on, optionally shifted to zero, or to the corresponding alignment position if multiple inputs have been appended.

QuoteWe can't display 2 before we have decoded 1, so we delay everything by one time increment (max ref frames = 2).
The decoding order is an internal issue and not relevant for the question. I'd just like to see the timestamp of the displayed frame. For each frame this is indpendent from any other frame because it can simply be read from the file and doesn't need to be manipulated at the stage of displaying it.
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 02:15:47 AM
In short, the displayed timestamp should have a meaning to the user. For example, it could be the PTS from the video file, or the distance from the start of the video. These would make sense. The value currently displayed makes no sense to me.
I hope I was clearer now.  :)
Thanks anyway.
Title: Re: PTS of first frame
Post by: Jan Gruuthuse on July 02, 2018, 02:21:29 AM
Quote from: CryGuy on July 02, 2018, 02:15:47 AM
>8 In short, the displayed timestamp should have a meaning to the user. >8
What is displayed is the technically information from the video, no more no less ;)

Explanation by a layman:
- avidemux is not a frame based editor but a time based editor, due to the newer codecs.
- There is partially video information (past) before the 1st viewable reconstructed frame, it would also need partially video information after the the 1st viewable reconstructed frame (future).
- Why in heaven would you need to complicate matters more to visibly please a user by showing another time reference instead of the used time reference within the video.
After all the strength of avidemux is editing without the need of re encoding: ([Copy] Mode.
Please remember:
Quote from: Avidemux Start
Avidemux is a simple tool for simple video processing tasks. The keyword here is simple: it does not offer tools like a timeline, multitrack editing, you cannot freely move or splice audio and video clips from various sources. However, Avidemux allows you to do elementary things in a very straightforward way.
source: Avidemux Wiki (https://www.avidemux.org/admWiki/doku.php?id=using:quickstart)
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 03:23:17 AM
Hi Jan, thanks for replying.

QuoteWhat is displayed is the technically information from the video, no more no less ;)
Sorry, but just that is not the case. If it was from the video, it would display 0.16. Instead, it shows an artifical computed value (0.082) which is not from the video, and it's still not clear which meaning it should have.

Quoteavidemux is not a frame based editor but a time based editor, due to the newer codecs.
But it displays frames. And these frames have a timestamp. I only expect it to display the corresponding timestamp.
EDIT: Am I not jumping from frame to frame in the source video when pressing the left/right arrow keys? I think I do. I'm not jumping a fixed timespan forth/back.
QuoteThere is partially video information (past) before the 1st viewable reconstructed frame, it would also need partially video information after the the 1st viewable reconstructed frame (future).
Still every frame has one timestamp. It should just be displayed.
QuoteWhy in heaven would you need to complicate matters more to visibly please a user by showing another time reference instead of the used time reference within the video.
What is so complicated in just displaying the timestamp of the frame? The value is 0.16, so display 0.16. That's most straightforward. Thoughts about decoding order, delays etc posted before make it unnecessarily complicated. But these were not my thoughts.

QuoteAvidemux is a simple tool...
That's absolutely ok.


Maybe there is a reason for not simply showing the information from the opened video, but yet I don't see an explanation for it.
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 03:36:07 AM
(https://abload.de/thumb/admdifferenceyzsb2.png) (http://abload.de/image.php?img=admdifferenceyzsb2.png)

Difference. Why? :)
Title: Re: PTS of first frame
Post by: Jan Gruuthuse on July 02, 2018, 06:17:14 AM
Quote from: CryGuy on July 02, 2018, 03:23:17 AM
But it displays frames. And these frames have a timestamp. I only expect it to display the corresponding timestamp.
EDIT: Am I not jumping from frame to frame in the source video when pressing the left/right arrow keys? I think I do. I'm not jumping a fixed timespan forth/back.
The only fully decodable picture would be the intraframe. Left Right keyboard moves you trough pseudo frames between the intraframe. The concept of Frames Per Second is virtual in the newer codecs, as the frames are not really there due to video compression.

DTS: 0.08 or 0.082, perhaps that is what is showing in 00:00:00.082 ?

Keep in mind I'm (basic) user, not a coder.
is this what you're looking for:
Stack Overflow: Understanding PTS and DTS in video frames (https://stackoverflow.com/questions/13595288/understanding-pts-and-dts-in-video-frames)
Title: Re: PTS of first frame
Post by: eumagga0x2a on July 02, 2018, 09:19:08 AM
Quote from: CryGuy on July 02, 2018, 03:23:17 AM
If it was from the video, it would display 0.16. Instead, it shows an artifical computed value (0.082) which is not from the video, and it's still not clear which meaning it should have.

The PTS values stored in the container are respected, but the offset is adjusted so that the first DTS is zero.

QuoteFor me, only two things would make sense as to which timestamp is displayed:
- As stored in the source video. This means the first frame is at 0.16 s.
- All timestamps of all frames are shifted by -0.16 so that the first frame is at zero.

The first one would be detrimental to video append functionality (an excessive gap between the last frame of the preceding video and the start of the next one), the second outright incompatible with Avidemux design which doesn't allow negative timestamps (DTS would need to become negative this way).

I tried to play with making every video start at zero (grep the source for ADM_ZERO_OFFSET), the attempt turned out to be not viable as it broke the video append functionality.
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 11:07:34 AM
QuoteThe only fully decodable picture would be the intraframe. Left Right keyboard moves you trough pseudo frames between the intraframe. The concept of Frames Per Second is virtual in the newer codecs, as the frames are not really there due to video compression.
Sorry, but I don't think there are pseudo frames. I know there is not (necessarily) a fixed frame rate anymore. That's why there are timestamps per frame. If you navigate through an opened video,you can only navigate to positions where there is a frame in the source video:

(https://abload.de/thumb/framesptsfesb8.png) (http://abload.de/image.php?img=framesptsfesb8.png)

You can navigate only to the arrow positions, not anywhere between. If that's not true, then I misunderstood everything and I have to rethink from start. ;)

QuoteDTS: 0.08 or 0.082, perhaps that is what is showing in 00:00:00.082 ?
No, the value is exactly 0.08. I limitted display to two decimal places as the third place is always 0. If you look in the "DTS (raw)" column, the value is 2000. As the timescale for the stream is 25,000, the value is computed by 2000/25000 = 0.08 (exact).

(sorry for not appending the pictures but attachments didn't appear in the past)

Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 11:30:53 AM
QuoteThe PTS values stored in the container are respected, but the offset is adjusted so that the first DTS is zero.
I didn't say they are not respected. Jan said "What is displayed is the technically information from the video, no more no less ". For me "no more no less" means that the unmodified value from the video is shown. I only said that this is not true.

Quote from: eumagga0x2a on July 02, 2018, 09:19:08 AM
QuoteFor me, only two things would make sense as to which timestamp is displayed:
- As stored in the source video. This means the first frame is at 0.16 s.
- All timestamps of all frames are shifted by -0.16 so that the first frame is at zero.

The first one would be detrimental to video append functionality (an excessive gap between the last frame of the preceding video and the start of the next one), the second outright incompatible with Avidemux design which doesn't allow negative timestamps (DTS would need to become negative this way).
Regarding the first option, I've already taken this into account as I said that the ts of appended videos would have to be shifted so that there is no gap. However,
The second wouldn't be a problem as you do not have to shift to negative valus. Again, I'm only referring to what is displayed to the user!!


Anway... I don't understand what is displayed now. The 0.082 s doesn't make sense at all for me as a user. I don't say it's wrong or anything is not working, but the value is meaningless. However, I take it as it is now. :)

Sorry if I wasn't able to make myself clearer. Thanks guys for the discussion! I'm out.
Title: Re: PTS of first frame
Post by: eumagga0x2a on July 02, 2018, 12:24:21 PM
You could provide admlog.txt resulting from loading the mp4 in question in Avidemux to make the choice of first frame PTS clearer.
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 01:02:58 PM
Quote from: eumagga0x2a on July 02, 2018, 12:24:21 PM
You could provide admlog.txt resulting from loading the mp4 in question in Avidemux to make the choice of first frame PTS clearer.
I have no doubt you can explain it to me. :) And I see it would answer the question I'vee initially asked.

Which value I expect to see instead is a different thing, but I don't expect ADM to be changed. (even if it would make sense IMO)

Thanks again.
Title: Re: PTS of first frame
Post by: CryGuy on July 02, 2018, 06:58:11 PM
Sorry, me again. Last thing I've tried: If I save the video, there's not PTS 0.082 in the output file. Neither in copy mode, nor when transcoding (x264). Even if I can reproduce how 0.082 is computed, I don't see the purpose. Anyway, I'll find myself with with not getting it.;) And thanks a last time.
Title: Re: PTS of first frame
Post by: eumagga0x2a on July 02, 2018, 11:40:23 PM
Please provide at least the Avidemux log or better the mp4 file as a sample, otherwise it is impossible to judge whether Avidemux is doing something wrong here. No, the point of view of libav is not a sufficient reference.
Title: Re: PTS of first frame
Post by: CryGuy on July 03, 2018, 12:51:35 AM
As I already said, this topic is finished for me.
I have other things that might be a bug, but I'll verify it before reporting it.
Title: Re: PTS of first frame
Post by: CryGuy on July 03, 2018, 01:25:40 AM
If you insist on it, this is what I can provide: see attachments. Just look at the bold columns. These are the DTS and PTS values.

Thank you one more time. I do appreciate it. I have to move on with other things now.