[Libav-user] Remuxing single MPEG-2 TS to multiple outputs (MPEG2 PS).

wl2776 wl2776 at gmail.com
Mon May 16 13:11:52 CEST 2011

Hi all.

My program remuxes MPEG-2 Transport Stream to several MPEG-2 Program
I have a single AVFormatContext for an input data and several
AVFormatContexts (one for each output file). 
Output AVFormatContexts are created and destroyed dynamically during program

Sometimes one packet should go to several outputs.

Basically, main loop looks like the following

int64_t pkt_pts, pkt_dts;
int pkt_stream_index;

    av_read_frame(input, &pkt);
    pkt_stream_index = pkt.stream_index;
    pkt_pts = pkt.pts;
    pkt_dts = pkt.dts;
    for (< each output stream >) {
        if ( < pkt should go to  the current_output > ) {
          pkt.stream_index = <proper index>;
          pkt.pts = <proper pts>;
          pkt.dts = <proper dts>;

          av_write_frame(current_output, &pkt);

          pkt.stream_index = pkt_stream_index;
          pkt.pts = pkt_pts;
          pkt.dts = pkt_dts;

This scheme worked successfully for a very long time, since 2008.
However, now I've downloaded recent ffmpeg version from git and observe
gdb shows that they are in avformat_free_context();

I've seen the messages here in the list, stating that I should duplicate a
packet before writing it to the output.
It it right?
What else should I correct in the scheme in order to conform to the current
API standards?

View this message in context: http://libav-users.943685.n4.nabble.com/Remuxing-single-MPEG-2-TS-to-multiple-outputs-MPEG2-PS-tp3525959p3525959.html
Sent from the libav-users mailing list archive at Nabble.com.

More information about the Libav-user mailing list