2 years ago

#51209

test-img

yaskovdev

ffmpeg copies packet pts to frame pts during audio decoding without time base conversion

I have the MKV file. I am taking an audio stream from it and using ffmpeg and its opus decoder to decode audio packets into audio frames.

The problem is that the resulting frames have unexpected presentation timestamps (pts): during decoding, ffmpeg just copies pkt->pts to frame->pts, ignoring the fact that the time base for pkt->pts is 1/1000, while for frame->pts it is 1/48000 (which means they definitely cannot be the same).

Setting pkt_timebase of the audio decoder to 1/1000 does not help. I also tried using libopus audio decoder instead of opus (which is considered experimental), but the issue is still there.

How to tell ffmpeg that the time base conversion is needed? Or setting frame->pts manually after decoding is the only option?

I have tried the same test with a really old ffmpeg version (3.0). It sets frame->pts to AV_NOPTS_VALUE, which seems more correct behavior than the current one. Can it be a bug in ffmpeg introduced sometime after version 3.0 and the frame->pts should always be AV_NOPTS_VALUE if the decoder cannot assign it by itself (both opus and libopus cannot, according to their caps_internal)?

The project to reproduce the issue is here. Here it prints pkt->pts (before decoding) and frame->pts (after decoding) and they happen to be the same.

c++

audio

ffmpeg

decoding

opus

0 Answers

Your Answer

Accepted video resources