[FFmpeg-devel] MPEGTS stream auto-guessed before PMT is read

Baptiste Coudurier baptiste.coudurier
Thu Nov 25 01:55:19 CET 2010


On 11/18/10 10:54 PM, Baptiste Coudurier wrote:
> Hi,
> 
> On 11/18/10 8:53 AM, Stephen D'Angelo wrote:
>> Hello,
>>
>> I have encountered transport streams where the AVStreams created are not
>> properly associated with the AVPrograms.  I'm no expert on the current
>> mpegts.c code, but I believe it is happening because of the following:
>>
>> - The PMT for the stream's program is not read in mpegts_read_header
>> before auto_guess is turned on (line 1401)
>> - During av_find_stream_info, the pes stream is added to ts->pids in
>> handle_packet because auto_guess is true (line 1196)
>> - The PMT is read later and in pmt_cb the pes stream in found in
>> ts->pids, but pes->st has not been set yet, causing pmt_cb to return
>> (line 936)
>> - The AVStream for the pes stream is then added later in
>> mpegts_push_data (line 693), but it is not properly associated with its
>> AVProgram
>>
>> The following patch fixes the problem by creating an AVStream for the
>> pes stream if it doesn't have one, and then the subsequent call to
>> ff_program_add_stream_index properly associates the AVStream with the
>> AVProgram.
>>
>> Index: libavformat/mpegts.c
>> ===================================================================
>> --- libavformat/mpegts.c        (revision 25762)
>> +++ libavformat/mpegts.c        (working copy)
>> @@ -926,6 +926,8 @@
>>          if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) {
>>              pes = ts->pids[pid]->u.pes_filter.opaque;
>>              st = pes->st;
>> +            if (!st)
>> +                st = pes->st = av_new_stream(pes->stream, pes->pid);
>>          } else {
>>              if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]);
>> //wrongly added sdt filter probably
>>              pes = add_pes_stream(ts, pid, pcr_pid);
>>
>> Would it instead make more sense to "add_pid_to_pmt" before checking
>> that there is no AVStream (line 936) and "continue" if there is no
>> AVStream (line 937) so that all of the pes streams are associated with
>> the program and then after calling av_new_stream in mpegts_push_data,
>> call ff_program_add_stream_index to associate the AVStream with its
>> AVProgram?  If it's done that way, the AVStream will not have the proper
>> language information that's added in pmt_cb.
> 
> Thanks for the patch.
> I believe it is correct and that's the good approach. PMT is the reference.
> 
> Can you please submit a file which shows this problem ?
> 

Applied.

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list