[mythtv] libavformat doesn't handle multi-audio PS stream correctly

Mark Spieth mark at dclabs.com.au
Wed Oct 4 05:04:06 UTC 2006

> I've been looking at a ticket about mythtranscode dropping audio
> streams when transcoding (input is TS 1 video+2 audio, output is
> reported as 1video+1audio even though all the streams are present).
> Looking at it, it appears to be a problem with libavformat parsing PS
> streams.
> It appears that as soon as av_find_stream_info locates 1 video and 1
> audio, it exits.  I would have expected it to be gated by either the
> availability of a PSM (program stream map) which is similar to the PMT
> in a TS stream (which the transcoder doesn't generate, but I have code
> to do so), or by the sum of the audio_bound + video_bound values from
> the system header (which are set correctly by the transocder already).
> Fixing this would seem to require quite a bit of surgery to mpeg.c,
> or by forcing a read of a minimum set of frames in
> av_find_stream_info.
> This is the piece of code that seems to be causing the issue:
>            if (!(ic->ctx_flags & AVFMTCTX_NOHEADER) ||
>                (read_size >= MAX_READ_SIZE || read_packets >= MAX_FRAMES) 
> ||
>                (hasvideo && hasaudio)) {
> specifically that last part (hasvideo && hasaudio)

Ive noticed this for a long time and have been looking into it sporadically.
it happens for TS (DVB) too.
if you remove 500k from the front of a recording then it can work correctly 
again, recognizing the streams and codecs correctly.
there needs to be some sort of validation of the stream info as its 
incorrectly detecting the stream info start flags from incorrect positions 
in the byte stream. this is because the mpeg byte stream is not aligned in 
any way when recorded.
I havent figured a good way out yet.
it also should find all streams info (multi audio/video) as you mention.

there is a further issue with the start of play is no longer the start of 
the stream due to the stream info reader. I have a simple seek to beginning 
in my avformatdecoder after finding stream info that seems to work. this is 
a bigger issue with avi/mp4 as the key frames are much further apart (>5 
secs) and you can miss a good bit at the start.

> Is this code myth specific?  I don't see it in other libavformat 
> repositories.

dont know but Im starting to look at mplayer (yesterday) and how it does 
stream detection with lavf


More information about the mythtv-dev mailing list