[FFmpeg-devel] [PATCH] RTSP muxer, round 5

Martin Storsjö martin
Fri Feb 26 14:36:07 CET 2010

Hi Ronald,

On Mon, 22 Feb 2010, Ronald S. Bultje wrote:

> On Fri, Feb 19, 2010 at 6:05 PM, Martin Storsj? <martin at martin.st> wrote:
> in write_packet():
> +    av_init_packet(&local_pkt);
> +    local_pkt.stream_index = 0;
> +    local_pkt.pts   = pkt->pts;
> +    local_pkt.flags = pkt->flags;
> +    local_pkt.data  = pkt->data;
> +    local_pkt.size  = pkt->size;
> Is the packet copy necessary? I'm not totally sure, but could you just
> change pkt->stream_index and forward?

I noticed one issue regarding this... The current code in SVN changes 
pkt->stream_index, so a caller doing av_write_frame and then inspecting 
the packet fields can get confused.

I had code like this in an external application using libavformat:

  av_write_frame(out, pkt);
  double time = pkt->dts*av_q2d(out->streams[pkt->stream_index]->time_base);

When pkt->stream_index initially was 1, but changed to 0 for the chained 
internal muxer, this calculation turned out wrong. In this case, it was 
easy to fix, but there may be a lot of other libavformat users out there 
that could be struck by something similar.

So, is it ok for av_write_frame to update fields of the AVPacket to 
potentially bogus values, or should rtsp_write_packet be changed to set 
stream_index to 0 in a local copy? Or perhaps just backup the index value 
and restore the original value afterwards?

// Martin

More information about the ffmpeg-devel mailing list