1 year ago

#372657

test-img

user1365836

Can't get the right formula to set frame pts for a stream using libav

I'm trying to save a stream of frames as mp4. Source framerate is not fixed and it stay in the range [15,30]

Encoder params:

...
eCodec.time_base = AVRational(1,3000);
eCodec.framerate = AVRational(30, 1);
...

Stream params:

eStream = avformat_new_stream(eFormat, null);                
eStream.codecpar = codecParams;
eStream.time_base = eCodec.time_base;

Decoder time_base is 0/1 and it marks each frame with a pts like:

480000
528000
576000
...

PTS(f) is always == PTS(f-1)+48000

Encoding (dFrame is the received frame, micro the elapsed time in microseconds):

av_frame_copy(eFrame, dFrame);
eFrame.pts = micro*3/1000;

This make the video playing too fast. I can't understand why, but changing micro*3/1000 to micro*3*4/1000 make the video play at the correct speed (checked against a clock after many minutes of varying fps)

What am I missing?

ffmpeg

libav

libavcodec

libavformat

pts

0 Answers

Your Answer

Accepted video resources