Output encode file audio/video plays too fast in ffplay

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Output encode file audio/video plays too fast in ffplay

So I've been experimenting with making a screen-casting application and have run into another
obstacle. When I play my output file in ffplay.exe, my video and audio are correct, but extremely fast
(like they're in fast-forward). When I play the same file in VLC, WMPClassic, or open it in Sony Vegas,
they detect/play no sound at all and the video is the proper speed, but it detects the file as being 28 
seconds long when it's really only 20. I'm assuming this has to do with the frame->pts and dts, but it
seems like I've tried just about every combination of av_rescale_q() before and after encoding both video
and audio, manually tweaking pts/dts values, changing the frame rate, etc. but to no avail. In ffplay (the 
only player that seems to get the audio along with the video) it at least seems as if the audio and video 
are synced, but then again it's hard to tell since everything seems to be at 3-4x speed. I started working 
from the muxing.c example, so most of my code is the same (except for how I'm generating the audio and 
video, and the settings to make it encode in the baseline profile). So with all that, I'm really just stumped 
as to how I could have gone so wrong with so few changes to the documentation example. I'm not sure 
how much of my code I should post here, but just about all of my changes were made in write_video_frame/
write_audio_frame functions, please let me know if more information is needed.

FFMPEG Build: Zeranoe's ffmpeg-20130428-git-0fb64da
Video Container: MP4 (baseline profile)
Video Codec: H264
Audio Codec: AAC
Here's an example of the output file
Reply | Threaded
Open this post in threaded view

Re: Output encode file audio/video plays too fast in ffplay

Pradeep Karosiya
I've faced a similar problem before. I was just doing stream copy i.e changing the container format to avi.
I think you care correct your pts and dts may not be correct. I  too ended up playing with various combination.
Try following. it worked for me. This is just for stream copy which involves no decoding
 outpkt.pts= av_rescale_q(inputpkt.pts, input_video_strm->time_base, output_video_strm->time_base);
Similar rescaling for dts. Also you will need to do it for audio stream too.

One thing to note it that if you are encoding decoded packet then you can forget about pts and dts. Encoder automatically does that for you.