[Libav-user] Advice on decoding order madness
florian.loferer at me.com
Thu Jun 26 17:26:53 CEST 2014
Hi there guys,
I wrote my own audio/video player based on FFmpeg/libav.
It works basically but I’d need your advice on some decoding issues I ran into.
Being a video-coding newbie, I first thought that it would be wise to just have one function returning decoded video frames at given indices and another giving me audio samples at given indices.
However, I had to realize that randomly accessing the movie file is not working that well and that the file stream should be read in order.
I have to mention that I’m not 100% sure if I did everything the right way though.
I then changed my strategy to have one function returning video frames.
The function reads the video frames and tries to also decode the audio packets that “belong” to that video frames.
So that when a given frame is to be presented, the audio can also be played back in sync with the video.
This worked pretty well for a couple of files. I found out that these files had the audio info before the video info it belongs to.
So I always read the audio automatically when I read the next video frame.
I then opened a DV file with two audio tracks and there was silence … I noticed that there were 29 video frames before the first piece of audio.
After a couple of thousand audio samples for the first track, there were a couple of thousand audio samples for the second track.
Can anyone with more experience in this field please tell me what’s the best way to read audio and video in this case so that it can be played back in sync properly?
I could of course cache 29 video frames, but I don’t think that’s the best solution. And what if in the next file, there’s 50 frames?
Is it better to just seek and work on a random access basis or does this totally confuse the decoder?
Any advice is highly appreciated!!
More information about the Libav-user