[mythtv] mpegts adding av streams with bad codecs

Bryan Mayland bmayland at leoninedev.com
Thu May 3 18:17:33 UTC 2007

In the process of coding up support for Brighthouse Tampa's PACE550 
cablebox via FireWire, my final challenge came in the form of MythTV 
thinking that the AC3 audio stream was actually MPEG1 Video.  I tracked 
the problem down to r6861 (2005-06-18 ljr) where code was added to 
libavformat/mpegts.c handle_packet().
    if (ts->auto_guess && tss == NULL && is_start) {
        PESContext *pes = add_pes_stream(ts, pid, 0);
        if (pes)
            new_pes_av_stream(pes, 0);

        tss = ts->pids[pid];
This adds a pes stream stream to the transport stream context then adds 
a "blank" (for lack of a better term) av stream as the handler for that 
pes.  Since both stream type and stream code are hardcoded to 0, 
codec_type is set to CODEC_TYPE_VIDEO and codec_id is set to 
CODEC_ID_MPEG1VIDEO.  That's fine except...

When mpegts_push_data is later called to parse the actual data in the TS 
packets, the actual stream code is parsed correctly (0xe0 for the video 
ES, and th 0xbd for the audio ES).  However, since the av stream 
(pes->st) is already allocated
                    if (!pes->st && 0 == new_pes_av_stream(pes, code)) {
Is is never updated with the appropriate codec type and ID.

Long story short the video plays but the audio stream is still 
MPEG1VIDEO so I have no audio.  Removing the new_pes_av_stream() call 
from the first code block allows the code in mpegts_push_data to 
allocate it and set the values correctly.  I can't see why this code is 
needed (it was added in r6861 and does not exist in ffmpeg).  Should I 
trac a patch to remove it, or am I missing something obvious here?

More information about the mythtv-dev mailing list