Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why frame->pts increases by 20, rather than by 1?

Following the exmaples of ffmpeg: decoding_encoding.c and filtering_video.c, I process one video file taken by iPhone. The video file: .mov, video dimensions; 480x272, video Codec: H.264/AVC, 30 frames per second, bitrate: 605 kbps.

I first extract each frame, which is YUV. I convert YUV to RGB24, and process the RGB24, then write the RGB24 to a .ppm file. It shows the .ppm file is correct.

Then I plan to encode processed RGB24 frames to a video file. Since MPEG does not support RGB24 picture format, I used AV_CODEC_ID_HUFFYUV. But the output video file (showing 18.5 MB) does not play. Movie Player on Ubuntu claims an error: Could not determine type of stream. I also tried it on VCL. It simply does not work, without any error information.

My second questions is: For each extracted fram from the input video file, I get its pts as follows according to filtering_video.c:

frame->pts = av_frame_get_best_effort_timestamp(frame);

I print out each frame's pts, and find that it increases by 20, like below:

pFrameRGB_count: 0,  frame->pts: 0
pFrameRGB_count: 1,  frame->pts: 20
pFrameRGB_count: 2,  frame->pts: 40
pFrameRGB_count: 3,  frame->pts: 60

Where frame is the extracted frame from the input video, and pFrameRGB_count is the count for processed frame in RGB24 form.

Why are they wrong?

like image 576
user1914692 Avatar asked Mar 17 '13 08:03

user1914692


1 Answers

H.264 videos use a 90 kHz clock for encoding timestamps. Since your video is 30 fps, the PTS delta between 2 successive frames should be 3000 instead of 20.

A value of 20 indicates one or both of the following:

  • Your encoding clock (i.e. sampling rate) is configured incorrectly (to 600 Hz) for the given frame rate of 30 fps

  • Your frames per second is configured incorrectly (to 4500fps).

The general formula to calculate PTS delta is:

PTS delta = (1/fps) * Encoder sampling rate
like image 191
Tuxdude Avatar answered Sep 28 '22 13:09

Tuxdude