[Ffmpeg-devel] Audio video player in a fixed fps loop.

Måns Rullgård mru
Fri Sep 22 20:52:33 CEST 2006


"Silvano Galliani (kysucix)" <kysucix at dyne.org> writes:

> Hi.
> I would like to implement an audio video player based on ffmpeg and
> the architecture that better suits my needs is a main loop running at
> fixed frame rate catching a frame and the correct amount of audio
> chunk and the ouput them on video and sound card.
>
> while (true)
> {
> 	get_video_frame();
> 	while (audio_buffer_size < sample_rate * channels / fps / sampleformat)
> 	{
> 		get_audio_chunk();
> 	}
> 	output_video_frame();
> 	output_audio();
> 	sleep_until_next_fps();
> }
>
> A part from variable fps codecs and duplicated frames or such things,
> is it a correct approach? How much should I put on the audio buffer ?
> I hope it isn't too OT :)

What is your source of audio and video?  If you are playing from a
file, a good solution is to play the audio at whatever rate the sound
card wants, and display video frames together with the proper sound
samples.

If you are receiving data from a network, satellite, or other
streaming source, things get more complicated.  It is likely that the
clock in your sound card isn't running at exactly the same speed as
the encoder.  Over time, your buffers will either overflow or
underflow.  To avoid glitches you'll have to resample the audio to
match.

-- 
M?ns Rullg?rd
mru at inprovide.com




More information about the ffmpeg-devel mailing list