5

I'm muxing mpeg4 video to avi container. The video stream is ~4fps, so I set AVCodecContext time_base to 1/4 (formatContext->streams[0]->codec->time_base...) , and then rescal each frame timestamp, because the original time-stamps are in milliseconds. The resulting value I assign to a packet pts and dts.

When I play this avi with VLC, the video is not smooth, and I get the following message repeatedly:

avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)

Is there something wrong with the above pts/dts calculation?

The following table demonstrates how the timestamps are rescaled (original->rescaled)

stream: 0 1329471005111->1
stream: 0 1329471005348->2
stream: 0 1329471005588->3
stream: 0 1329471005828->4
stream: 0 1329471006068->5
stream: 0 1329471006308->6
stream: 0 1329471006551->7
stream: 0 1329471006788->8
stream: 0 1329471007028->9
stream: 0 1329471007268->10
stream: 0 1329471007508->11
stream: 0 1329471007748->12
stream: 0 1329471007988->13
stream: 0 1329471008228->14
stream: 0 1329471008468->15
Igor R.
  • 14,716
  • 2
  • 49
  • 83
  • shouldn't you rescale it to 0, 250, 500, 750, ...? – arash kordi Nov 19 '12 at 08:37
  • @arash kordi Why? Please note that the time-base is reciprocal to the framerate, i.e. 1/4. So I rescale like this: ` AVRational time_base_1kHz = { 1, 1000 }, stream_timebase = { 1, 4 }; pkt.pts = av_rescale_q(stream_pts, time_base_1kHz, stream_timebase);` Is that wrong? – Igor R. Nov 19 '12 at 09:42
  • @arash kordi Comments in avformat.h say: "For fixed-fps content, time base should be 1/framerate and timestamp increments should be 1." – Igor R. Nov 19 '12 at 10:00
  • yes you are right, but av_read_frame() guarantees that pts and dts are always set to the correct value, if you're just remuxing frames you can leave everything intact. one more thing... did you set pkt->duration as well? you can also use AV_NOPTS_VALUE and see what happens – arash kordi Nov 19 '12 at 10:23
  • @arash kordi I don't read these frames from a standard container, originally they reside in some proprietary file and have timestamps in milliseconds, as I mentioned. As for `duration`, the documentation says: "Duration of this packet in AVStream->time_base units, 0 if unknown. Equals next_pts - this_pts in presentation order." I've just tried to set 1, 0, AV_NOPTS_VALUE -- it seems to have no effect at all. – Igor R. Nov 19 '12 at 10:45
  • I've solved this issue for myself by setting video output to XVideo-output (XCB) – Smile4ever Jun 18 '16 at 18:58

0 Answers0