How to write the same AVPacket to multiple outputs

Viewed 501

I'd like to implement some sort of tee function using libav. I read packets from a file and would like to forward them to several output file. So far, since av_interleaved_write_frame free the packet, I did this:

AVPacket pkt;
// Stuff to read packets into pkt

for (ic = 0; ic < nb_outputs; ic++) {
  AVPacket pkt2;
  av_copy_packet(&pkt2,&pkt);
  av_interleaved_write_frame(ofmt_ctx[ic], &pkt2);
}

I wonder if it's the optimal way of doing it? Copying the packet seems overkill. I try to use av_packet_ref but it failed.

0 Answers
Related