[FFmpeg-devel] [PATCH] demux individual program out of MPEG-TS

Nico Sabbi nicola_sabbi
Wed Sep 12 23:13:09 CEST 2007


Michael Niedermayer wrote:
> 
>>Index: libavformat/mpegts.c
>>===================================================================
>>--- libavformat/mpegts.c	(revisione 10435)
>>+++ libavformat/mpegts.c	(copia locale)
> 
> [not maintained by me]
> 
>>Index: libavformat/avformat.h
>>===================================================================
>>--- libavformat/avformat.h	(revisione 10435)
>>+++ libavformat/avformat.h	(copia locale)
>>@@ -345,6 +345,14 @@
>>     int64_t pts_buffer[MAX_REORDER_DELAY+1];
>> } AVStream;
>> 
>>+typedef struct AVProgram {
>>+    int running:1;
> 
> 
> please use some normal int flags

done, with some natural reordering of the members

> 
> 
> 
>>+    enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
>>+    int id;
>>+    char *provider_name; /**< DVB Network name, "" if not DVB stream */
>>+    char *name; /**< DVB Service name, "MPEG Program [sid]" if not DVB stream*/
>>+} AVProgram;
> 
> 
> please vertically align them
> 

done

> 
> 
>>+
>> #define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
>>                                          (streams are added dynamically) */
>> 
>>@@ -360,6 +368,8 @@
>>     ByteIOContext pb;
>>     unsigned int nb_streams;
>>     AVStream *streams[MAX_STREAMS];
>>+    unsigned int nb_programs;
>>+    AVProgram **programs;
>>     char filename[1024]; /**< input or output filename */
>>     /* stream info */
>>     int64_t timestamp;
> 
> 
> adding these in the middle breaks the ABI

moved to the bottom of the struct

> 
> 
> 
>>@@ -647,6 +657,7 @@
>>  * @param id file format dependent stream id
>>  */
>> AVStream *av_new_stream(AVFormatContext *s, int id);
>>+AVProgram *av_new_program(AVFormatContext *s, int id, char *provider_name, char *name);
> 
> 
> to match av_new_stream() i would prefer if its just
> AVProgram *av_new_program(AVFormatContext *s, int id);
> 
> 

done, with the addition of av_set_program_name()

> 
>> 
>> /**
>>  * Set the pts for a given stream.
>>Index: libavformat/utils.c
>>===================================================================
>>--- libavformat/utils.c	(revisione 10435)
>>+++ libavformat/utils.c	(copia locale)
>>@@ -2067,6 +2067,11 @@
>>         av_free(st->codec);
>>         av_free(st);
>>     }
>>+    for(i=s->nb_programs-1; i>=0; i--) {
>>+        av_free(s->programs[i]->provider_name);
>>+        av_free(s->programs[i]->name);
>>+        av_free(s->programs[i]);
> 
> 
> use av_freep() please so they all are NULL
> 
> [...]
> 

done.
I also fixed a bug: program->discard must be set only when a new
program is created, not when it's already existent (or because
of the way demux_mpegts blindly creates programs the discard flag will
be set to DISCARD_NONE every time).
There's also another issue to consider: due to how ffmpeg and mplayer
set the streams to use, setting/discarding individual programs is not
enough: the stream selection overrides the program selection
(as in the second patch attached that doesn't work), so we can either
export in AVProgram an array of streams that the
calling application will have to set/discard (a solution that I don't 
like and that breaks the API) or adding a wrapper function to do this
job or ... ??

	Nico

-------------- next part --------------
A non-text attachment was scrubbed...
Name: lavf_programs3.diff
Type: text/x-patch
Size: 9705 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070912/97652790/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffmpeg_program.diff
Type: text/x-patch
Size: 1653 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070912/97652790/attachment-0001.bin>



More information about the ffmpeg-devel mailing list