avtools/avconv.c:299: error: Null Dereference
  pointer `&tmp_pkt->side_data` last assigned on line 284 could be null and is dereferenced by call to `av_packet_ref()` at line 299, column 15.

avtools/avconv.c:277:1: start of procedure write_packet()
275. }
276. 
277. static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
     ^
278. {
279.     AVFormatContext *s = of->ctx;

avtools/avconv.c:279:5: 
277. static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
278. {
279.     AVFormatContext *s = of->ctx;
         ^
280.     AVStream *st = ost->st;
281.     int ret;

avtools/avconv.c:280:5: 
278. {
279.     AVFormatContext *s = of->ctx;
280.     AVStream *st = ost->st;
         ^
281.     int ret;
282. 

avtools/avconv.c:283:10: Taking true branch
281.     int ret;
282. 
283.     if (!of->header_written) {
              ^
284.         AVPacket tmp_pkt = {0};
285.         /* the muxer is not initialized yet, buffer the packet */

avtools/avconv.c:284:9: 
282. 
283.     if (!of->header_written) {
284.         AVPacket tmp_pkt = {0};
             ^
285.         /* the muxer is not initialized yet, buffer the packet */
286.         if (!av_fifo_space(ost->muxing_queue)) {

avtools/avconv.c:286:14: 
284.         AVPacket tmp_pkt = {0};
285.         /* the muxer is not initialized yet, buffer the packet */
286.         if (!av_fifo_space(ost->muxing_queue)) {
                  ^
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
288.                                  ost->max_muxing_queue_size);

libavutil/fifo.c:57:1: start of procedure av_fifo_space()
  55. }
  56. 
  57. int av_fifo_space(AVFifoBuffer *f)
      ^
  58. {
  59.     return f->end - f->buffer - av_fifo_size(f);

libavutil/fifo.c:59:5: 
  57. int av_fifo_space(AVFifoBuffer *f)
  58. {
  59.     return f->end - f->buffer - av_fifo_size(f);
          ^
  60. }
  61. 

libavutil/fifo.c:52:1: start of procedure av_fifo_size()
    50. }
    51. 
    52. int av_fifo_size(AVFifoBuffer *f)
        ^
    53. {
    54.     return (uint32_t)(f->wndx - f->rndx);

libavutil/fifo.c:54:5: 
    52. int av_fifo_size(AVFifoBuffer *f)
    53. {
    54.     return (uint32_t)(f->wndx - f->rndx);
            ^
    55. }
    56. 

libavutil/fifo.c:55:1: return from a call to av_fifo_size
    53. {
    54.     return (uint32_t)(f->wndx - f->rndx);
    55. }
        ^
    56. 
    57. int av_fifo_space(AVFifoBuffer *f)

libavutil/fifo.c:60:1: return from a call to av_fifo_space
  58. {
  59.     return f->end - f->buffer - av_fifo_size(f);
  60. }
      ^
  61. 
  62. int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)

avtools/avconv.c:286:14: Taking true branch
284.         AVPacket tmp_pkt = {0};
285.         /* the muxer is not initialized yet, buffer the packet */
286.         if (!av_fifo_space(ost->muxing_queue)) {
                  ^
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
288.                                  ost->max_muxing_queue_size);

avtools/avconv.c:287:28: 
285.         /* the muxer is not initialized yet, buffer the packet */
286.         if (!av_fifo_space(ost->muxing_queue)) {
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
                                ^
288.                                  ost->max_muxing_queue_size);
289.             if (new_size <= av_fifo_size(ost->muxing_queue)) {

libavutil/fifo.c:52:1: start of procedure av_fifo_size()
  50. }
  51. 
  52. int av_fifo_size(AVFifoBuffer *f)
      ^
  53. {
  54.     return (uint32_t)(f->wndx - f->rndx);

libavutil/fifo.c:54:5: 
  52. int av_fifo_size(AVFifoBuffer *f)
  53. {
  54.     return (uint32_t)(f->wndx - f->rndx);
          ^
  55. }
  56. 

libavutil/fifo.c:55:1: return from a call to av_fifo_size
  53. {
  54.     return (uint32_t)(f->wndx - f->rndx);
  55. }
      ^
  56. 
  57. int av_fifo_space(AVFifoBuffer *f)

avtools/avconv.c:287:28: Condition is true
285.         /* the muxer is not initialized yet, buffer the packet */
286.         if (!av_fifo_space(ost->muxing_queue)) {
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
                                ^
288.                                  ost->max_muxing_queue_size);
289.             if (new_size <= av_fifo_size(ost->muxing_queue)) {

avtools/avconv.c:287:13: 
285.         /* the muxer is not initialized yet, buffer the packet */
286.         if (!av_fifo_space(ost->muxing_queue)) {
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
                 ^
288.                                  ost->max_muxing_queue_size);
289.             if (new_size <= av_fifo_size(ost->muxing_queue)) {

avtools/avconv.c:289:17: 
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
288.                                  ost->max_muxing_queue_size);
289.             if (new_size <= av_fifo_size(ost->muxing_queue)) {
                     ^
290.                 av_log(NULL, AV_LOG_ERROR,
291.                        "Too many packets buffered for output stream %d:%d.\n",

libavutil/fifo.c:52:1: start of procedure av_fifo_size()
  50. }
  51. 
  52. int av_fifo_size(AVFifoBuffer *f)
      ^
  53. {
  54.     return (uint32_t)(f->wndx - f->rndx);

libavutil/fifo.c:54:5: 
  52. int av_fifo_size(AVFifoBuffer *f)
  53. {
  54.     return (uint32_t)(f->wndx - f->rndx);
          ^
  55. }
  56. 

libavutil/fifo.c:55:1: return from a call to av_fifo_size
  53. {
  54.     return (uint32_t)(f->wndx - f->rndx);
  55. }
      ^
  56. 
  57. int av_fifo_space(AVFifoBuffer *f)

avtools/avconv.c:289:17: Taking false branch
287.             int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
288.                                  ost->max_muxing_queue_size);
289.             if (new_size <= av_fifo_size(ost->muxing_queue)) {
                     ^
290.                 av_log(NULL, AV_LOG_ERROR,
291.                        "Too many packets buffered for output stream %d:%d.\n",

avtools/avconv.c:295:13: 
293.                 exit_program(1);
294.             }
295.             ret = av_fifo_realloc2(ost->muxing_queue, new_size);
                 ^
296.             if (ret < 0)
297.                 exit_program(1);

libavutil/fifo.c:62:1: start of procedure av_fifo_realloc2()
  60. }
  61. 
  62. int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
      ^
  63. {
  64.     unsigned int old_size = f->end - f->buffer;

libavutil/fifo.c:64:5: 
  62. int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
  63. {
  64.     unsigned int old_size = f->end - f->buffer;
          ^
  65. 
  66.     if (old_size < new_size) {

libavutil/fifo.c:66:9: Taking false branch
  64.     unsigned int old_size = f->end - f->buffer;
  65. 
  66.     if (old_size < new_size) {
              ^
  67.         int len          = av_fifo_size(f);
  68.         AVFifoBuffer *f2 = av_fifo_alloc(new_size);

libavutil/fifo.c:79:5: 
  77.         av_free(f2);
  78.     }
  79.     return 0;
          ^
  80. }
  81. 

libavutil/fifo.c:80:1: return from a call to av_fifo_realloc2
  78.     }
  79.     return 0;
  80. }
      ^
  81. 
  82. /* src must NOT be const as it can be a context for func that may need

avtools/avconv.c:296:17: Taking false branch
294.             }
295.             ret = av_fifo_realloc2(ost->muxing_queue, new_size);
296.             if (ret < 0)
                     ^
297.                 exit_program(1);
298.         }

avtools/avconv.c:299:9: 
297.                 exit_program(1);
298.         }
299.         ret = av_packet_ref(&tmp_pkt, pkt);
             ^
300.         if (ret < 0)
301.             exit_program(1);

libavcodec/avpacket.c:357:1: start of procedure av_packet_ref()
  355. }
  356. 
  357. int av_packet_ref(AVPacket *dst, const AVPacket *src)
       ^
  358. {
  359.     int ret;

libavcodec/avpacket.c:361:5: 
  359.     int ret;
  360. 
  361.     ret = av_packet_copy_props(dst, src);
           ^
  362.     if (ret < 0)
  363.         return ret;

libavcodec/avpacket.c:316:1: start of procedure av_packet_copy_props()
    314. }
    315. 
    316. int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
         ^
    317. {
    318.     int i;

libavcodec/avpacket.c:320:5: 
    318.     int i;
    319. 
    320.     dst->pts                  = src->pts;
             ^
    321.     dst->dts                  = src->dts;
    322.     dst->pos                  = src->pos;

libavcodec/avpacket.c:321:5: 
    319. 
    320.     dst->pts                  = src->pts;
    321.     dst->dts                  = src->dts;
             ^
    322.     dst->pos                  = src->pos;
    323.     dst->duration             = src->duration;

libavcodec/avpacket.c:322:5: 
    320.     dst->pts                  = src->pts;
    321.     dst->dts                  = src->dts;
    322.     dst->pos                  = src->pos;
             ^
    323.     dst->duration             = src->duration;
    324. #if FF_API_CONVERGENCE_DURATION

libavcodec/avpacket.c:323:5: 
    321.     dst->dts                  = src->dts;
    322.     dst->pos                  = src->pos;
    323.     dst->duration             = src->duration;
             ^
    324. #if FF_API_CONVERGENCE_DURATION
    325. FF_DISABLE_DEPRECATION_WARNINGS

libavcodec/avpacket.c:326:5: 
    324. #if FF_API_CONVERGENCE_DURATION
    325. FF_DISABLE_DEPRECATION_WARNINGS
    326.     dst->convergence_duration = src->convergence_duration;
             ^
    327. FF_ENABLE_DEPRECATION_WARNINGS
    328. #endif

libavcodec/avpacket.c:329:5: 
    327. FF_ENABLE_DEPRECATION_WARNINGS
    328. #endif
    329.     dst->flags                = src->flags;
             ^
    330.     dst->stream_index         = src->stream_index;
    331. 

libavcodec/avpacket.c:330:5: 
    328. #endif
    329.     dst->flags                = src->flags;
    330.     dst->stream_index         = src->stream_index;
             ^
    331. 
    332.     for (i = 0; i < src->side_data_elems; i++) {

libavcodec/avpacket.c:332:10: 
    330.     dst->stream_index         = src->stream_index;
    331. 
    332.     for (i = 0; i < src->side_data_elems; i++) {
                  ^
    333.          enum AVPacketSideDataType type = src->side_data[i].type;
    334.          int size          = src->side_data[i].size;

libavcodec/avpacket.c:332:17: Loop condition is false. Leaving loop
    330.     dst->stream_index         = src->stream_index;
    331. 
    332.     for (i = 0; i < src->side_data_elems; i++) {
                         ^
    333.          enum AVPacketSideDataType type = src->side_data[i].type;
    334.          int size          = src->side_data[i].size;

libavcodec/avpacket.c:345:5: 
    343.     }
    344. 
    345.     return 0;
             ^
    346. }
    347. 

libavcodec/avpacket.c:346:1: return from a call to av_packet_copy_props
    344. 
    345.     return 0;
    346. }
         ^
    347. 
    348. void av_packet_unref(AVPacket *pkt)

libavcodec/avpacket.c:362:9: Taking false branch
  360. 
  361.     ret = av_packet_copy_props(dst, src);
  362.     if (ret < 0)
               ^
  363.         return ret;
  364. 

libavcodec/avpacket.c:365:10: Taking true branch
  363.         return ret;
  364. 
  365.     if (!src->buf) {
                ^
  366.         ret = packet_alloc(&dst->buf, src->size);
  367.         if (ret < 0)

libavcodec/avpacket.c:366:9: 
  364. 
  365.     if (!src->buf) {
  366.         ret = packet_alloc(&dst->buf, src->size);
               ^
  367.         if (ret < 0)
  368.             goto fail;

libavcodec/avpacket.c:69:1: start of procedure packet_alloc()
    67. }
    68. 
    69. static int packet_alloc(AVBufferRef **buf, int size)
        ^
    70. {
    71.     int ret;

libavcodec/avpacket.c:72:9: Taking false branch
    70. {
    71.     int ret;
    72.     if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
                ^
    73.         return AVERROR(EINVAL);
    74. 

libavcodec/avpacket.c:72:21: Taking false branch
    70. {
    71.     int ret;
    72.     if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
                            ^
    73.         return AVERROR(EINVAL);
    74. 

libavcodec/avpacket.c:75:5: 
    73.         return AVERROR(EINVAL);
    74. 
    75.     ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE);
            ^
    76.     if (ret < 0)
    77.         return ret;

libavutil/buffer.c:148:1: start of procedure av_buffer_realloc()
      146. }
      147. 
      148. int av_buffer_realloc(AVBufferRef **pbuf, int size)
           ^
      149. {
      150.     AVBufferRef *buf = *pbuf;

libavutil/buffer.c:150:5: 
      148. int av_buffer_realloc(AVBufferRef **pbuf, int size)
      149. {
      150.     AVBufferRef *buf = *pbuf;
               ^
      151.     uint8_t *tmp;
      152. 

libavutil/buffer.c:153:10: Taking false branch
      151.     uint8_t *tmp;
      152. 
      153.     if (!buf) {
                    ^
      154.         /* allocate a new buffer with av_realloc(), so it will be reallocatable
      155.          * later */

libavutil/buffer.c:170:16: Taking false branch
      168. 
      169.         return 0;
      170.     } else if (buf->size == size)
                          ^
      171.         return 0;
      172. 

libavutil/buffer.c:173:11: Taking false branch
      171.         return 0;
      172. 
      173.     if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) ||
                     ^
      174.         !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {
      175.         /* cannot realloc, allocate a new reallocable buffer and copy data */

libavutil/buffer.c:174:10: 
      172. 
      173.     if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) ||
      174.         !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {
                    ^
      175.         /* cannot realloc, allocate a new reallocable buffer and copy data */
      176.         AVBufferRef *new = NULL;

libavutil/buffer.c:122:1: start of procedure av_buffer_is_writable()
        120. }
        121. 
        122. int av_buffer_is_writable(const AVBufferRef *buf)
             ^
        123. {
        124.     if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)

libavutil/buffer.c:124:9: Taking false branch
        122. int av_buffer_is_writable(const AVBufferRef *buf)
        123. {
        124.     if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)
                     ^
        125.         return 0;
        126. 

libavutil/buffer.c:127:12: Condition is true
        125.         return 0;
        126. 
        127.     return atomic_load(&buf->buffer->refcount) == 1;
                        ^
        128. }
        129. 

libavutil/buffer.c:127:5: 
        125.         return 0;
        126. 
        127.     return atomic_load(&buf->buffer->refcount) == 1;
                 ^
        128. }
        129. 

libavutil/buffer.c:128:1: return from a call to av_buffer_is_writable
        126. 
        127.     return atomic_load(&buf->buffer->refcount) == 1;
        128. }
             ^
        129. 
        130. int av_buffer_make_writable(AVBufferRef **pbuf)

libavutil/buffer.c:174:10: Taking false branch
      172. 
      173.     if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) ||
      174.         !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {
                    ^
      175.         /* cannot realloc, allocate a new reallocable buffer and copy data */
      176.         AVBufferRef *new = NULL;

libavutil/buffer.c:174:40: Taking false branch
      172. 
      173.     if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) ||
      174.         !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {
                                                  ^
      175.         /* cannot realloc, allocate a new reallocable buffer and copy data */
      176.         AVBufferRef *new = NULL;

libavutil/buffer.c:189:5: 
      187.     }
      188. 
      189.     tmp = av_realloc(buf->buffer->data, size);
               ^
      190.     if (!tmp)
      191.         return AVERROR(ENOMEM);

libavutil/mem.c:107:1: start of procedure av_realloc()
        105. }
        106. 
        107. void *av_realloc(void *ptr, size_t size)
             ^
        108. {
        109.     /* let's disallow possibly ambiguous cases */

libavutil/mem.c:110:9: Taking false branch
        108. {
        109.     /* let's disallow possibly ambiguous cases */
        110.     if (size > (INT_MAX - 16))
                     ^
        111.         return NULL;
        112. 

libavutil/mem.c:116:5: 
        114.     return _aligned_realloc(ptr, size, 32);
        115. #else
        116.     return realloc(ptr, size);
                 ^
        117. #endif
        118. }

libavutil/mem.c:118:1: return from a call to av_realloc
        116.     return realloc(ptr, size);
        117. #endif
        118. }
             ^
        119. 
        120. int av_reallocp(void *ptr, size_t size)

libavutil/buffer.c:190:10: Taking false branch
      188. 
      189.     tmp = av_realloc(buf->buffer->data, size);
      190.     if (!tmp)
                    ^
      191.         return AVERROR(ENOMEM);
      192. 

libavutil/buffer.c:193:5: 
      191.         return AVERROR(ENOMEM);
      192. 
      193.     buf->buffer->data = buf->data = tmp;
               ^
      194.     buf->buffer->size = buf->size = size;
      195.     return 0;

libavutil/buffer.c:194:5: 
      192. 
      193.     buf->buffer->data = buf->data = tmp;
      194.     buf->buffer->size = buf->size = size;
               ^
      195.     return 0;
      196. }

libavutil/buffer.c:195:5: 
      193.     buf->buffer->data = buf->data = tmp;
      194.     buf->buffer->size = buf->size = size;
      195.     return 0;
               ^
      196. }
      197. 

libavutil/buffer.c:196:1: return from a call to av_buffer_realloc
      194.     buf->buffer->size = buf->size = size;
      195.     return 0;
      196. }
           ^
      197. 
      198. AVBufferPool *av_buffer_pool_init2(int size, void *opaque,

libavcodec/avpacket.c:76:9: Taking false branch
    74. 
    75.     ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE);
    76.     if (ret < 0)
                ^
    77.         return ret;
    78. 

libavcodec/avpacket.c:79:5: 
    77.         return ret;
    78. 
    79.     memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
            ^
    80. 
    81.     return 0;

libavcodec/avpacket.c:81:5: 
    79.     memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
    80. 
    81.     return 0;
            ^
    82. }
    83. 

libavcodec/avpacket.c:82:1: return from a call to packet_alloc
    80. 
    81.     return 0;
    82. }
        ^
    83. 
    84. int av_new_packet(AVPacket *pkt, int size)

libavcodec/avpacket.c:367:13: Taking false branch
  365.     if (!src->buf) {
  366.         ret = packet_alloc(&dst->buf, src->size);
  367.         if (ret < 0)
                   ^
  368.             goto fail;
  369.         memcpy(dst->buf->data, src->data, src->size);

libavcodec/avpacket.c:369:9: 
  367.         if (ret < 0)
  368.             goto fail;
  369.         memcpy(dst->buf->data, src->data, src->size);
               ^
  370. 
  371.         dst->data = dst->buf->data;

libavcodec/avpacket.c:371:9: 
  369.         memcpy(dst->buf->data, src->data, src->size);
  370. 
  371.         dst->data = dst->buf->data;
               ^
  372.     } else {
  373.         dst->buf = av_buffer_ref(src->buf);

libavcodec/avpacket.c:381:5: 
  379.     }
  380. 
  381.     dst->size = src->size;
           ^
  382. 
  383.     return 0;

libavcodec/avpacket.c:383:5: 
  381.     dst->size = src->size;
  382. 
  383.     return 0;
           ^
  384. fail:
  385.     av_packet_free_side_data(dst);

libavcodec/avpacket.c:387:1: return from a call to av_packet_ref
  385.     av_packet_free_side_data(dst);
  386.     return ret;
  387. }
       ^
  388. 
  389. AVPacket *av_packet_clone(const AVPacket *src)

static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
{
    AVFormatContext *s = of->ctx;
    AVStream *st = ost->st;
    int ret;
    if (!of->header_written) {
        AVPacket tmp_pkt = {0};
        if (!av_fifo_space(ost->muxing_queue)) {
            int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
                                 ost->max_muxing_queue_size);
            if (new_size <= av_fifo_size(ost->muxing_queue)) {
                av_log(NULL, AV_LOG_ERROR,
                       "Too many packets buffered for output stream %d:%d.\n",
                       ost->file_index, ost->st->index);
                exit_program(1);
            }
            ret = av_fifo_realloc2(ost->muxing_queue, new_size);
            if (ret < 0)
                exit_program(1);
        }
        ret = av_packet_ref(&tmp_pkt, pkt);
        if (ret < 0)
            exit_program(1);
        av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL);
        av_packet_unref(pkt);
        return;
    }
    if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) {
        if (ost->frame_number >= ost->max_frames) {
            av_packet_unref(pkt);
            return;
        }
        ost->frame_number++;
    }
    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
        uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,
                                              NULL);
        ost->quality = sd ? *(int *)sd : -1;
        if (ost->frame_rate.num) {
            pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),
                                         ost->mux_timebase);
        }
    }
    av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);
    if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
        ost->last_mux_dts != AV_NOPTS_VALUE &&
        pkt->dts < ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT)) {
        av_log(NULL, AV_LOG_WARNING, "Non-monotonous DTS in output stream "
               "%d:%d; previous: %"PRId64", current: %"PRId64"; ",
               ost->file_index, ost->st->index, ost->last_mux_dts, pkt->dts);
        if (exit_on_error) {
            av_log(NULL, AV_LOG_FATAL, "aborting.\n");
            exit_program(1);
        }
        av_log(NULL, AV_LOG_WARNING, "changing to %"PRId64". This may result "
               "in incorrect timestamps in the output file.\n",
               ost->last_mux_dts + 1);
        pkt->dts = ost->last_mux_dts + 1;
        if (pkt->pts != AV_NOPTS_VALUE)
            pkt->pts = FFMAX(pkt->pts, pkt->dts);
    }
    ost->last_mux_dts = pkt->dts;
    ost->data_size += pkt->size;
    ost->packets_written++;
    pkt->stream_index = ost->index;
    ret = av_interleaved_write_frame(s, pkt);
    if (ret < 0) {
        print_error("av_interleaved_write_frame()", ret);
        exit_program(1);
    }
}
['static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)\n{\n    AVFormatContext *s = of->ctx;\n    AVStream *st = ost->st;\n    int ret;\n    if (!of->header_written) {\n        AVPacket tmp_pkt = {0};\n        if (!av_fifo_space(ost->muxing_queue)) {\n            int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),\n                                 ost->max_muxing_queue_size);\n            if (new_size <= av_fifo_size(ost->muxing_queue)) {\n                av_log(NULL, AV_LOG_ERROR,\n                       "Too many packets buffered for output stream %d:%d.\\n",\n                       ost->file_index, ost->st->index);\n                exit_program(1);\n            }\n            ret = av_fifo_realloc2(ost->muxing_queue, new_size);\n            if (ret < 0)\n                exit_program(1);\n        }\n        ret = av_packet_ref(&tmp_pkt, pkt);\n        if (ret < 0)\n            exit_program(1);\n        av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL);\n        av_packet_unref(pkt);\n        return;\n    }\n    if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) {\n        if (ost->frame_number >= ost->max_frames) {\n            av_packet_unref(pkt);\n            return;\n        }\n        ost->frame_number++;\n    }\n    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {\n        uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,\n                                              NULL);\n        ost->quality = sd ? *(int *)sd : -1;\n        if (ost->frame_rate.num) {\n            pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),\n                                         ost->mux_timebase);\n        }\n    }\n    av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);\n    if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&\n        ost->last_mux_dts != AV_NOPTS_VALUE &&\n        pkt->dts < ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT)) {\n        av_log(NULL, AV_LOG_WARNING, "Non-monotonous DTS in output stream "\n               "%d:%d; previous: %"PRId64", current: %"PRId64"; ",\n               ost->file_index, ost->st->index, ost->last_mux_dts, pkt->dts);\n        if (exit_on_error) {\n            av_log(NULL, AV_LOG_FATAL, "aborting.\\n");\n            exit_program(1);\n        }\n        av_log(NULL, AV_LOG_WARNING, "changing to %"PRId64". This may result "\n               "in incorrect timestamps in the output file.\\n",\n               ost->last_mux_dts + 1);\n        pkt->dts = ost->last_mux_dts + 1;\n        if (pkt->pts != AV_NOPTS_VALUE)\n            pkt->pts = FFMAX(pkt->pts, pkt->dts);\n    }\n    ost->last_mux_dts = pkt->dts;\n    ost->data_size += pkt->size;\n    ost->packets_written++;\n    pkt->stream_index = ost->index;\n    ret = av_interleaved_write_frame(s, pkt);\n    if (ret < 0) {\n        print_error("av_interleaved_write_frame()", ret);\n        exit_program(1);\n    }\n}', 'int av_fifo_space(AVFifoBuffer *f)\n{\n    return f->end - f->buffer - av_fifo_size(f);\n}', 'int av_fifo_size(AVFifoBuffer *f)\n{\n    return (uint32_t)(f->wndx - f->rndx);\n}', 'int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)\n{\n    unsigned int old_size = f->end - f->buffer;\n    if (old_size < new_size) {\n        int len          = av_fifo_size(f);\n        AVFifoBuffer *f2 = av_fifo_alloc(new_size);\n        if (!f2)\n            return AVERROR(ENOMEM);\n        av_fifo_generic_read(f, f2->buffer, len, NULL);\n        f2->wptr += len;\n        f2->wndx += len;\n        av_free(f->buffer);\n        *f = *f2;\n        av_free(f2);\n    }\n    return 0;\n}', 'int av_packet_ref(AVPacket *dst, const AVPacket *src)\n{\n    int ret;\n    ret = av_packet_copy_props(dst, src);\n    if (ret < 0)\n        return ret;\n    if (!src->buf) {\n        ret = packet_alloc(&dst->buf, src->size);\n        if (ret < 0)\n            goto fail;\n        memcpy(dst->buf->data, src->data, src->size);\n        dst->data = dst->buf->data;\n    } else {\n        dst->buf = av_buffer_ref(src->buf);\n        if (!dst->buf) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        }\n        dst->data = src->data;\n    }\n    dst->size = src->size;\n    return 0;\nfail:\n    av_packet_free_side_data(dst);\n    return ret;\n}', 'int av_packet_copy_props(AVPacket *dst, const AVPacket *src)\n{\n    int i;\n    dst->pts                  = src->pts;\n    dst->dts                  = src->dts;\n    dst->pos                  = src->pos;\n    dst->duration             = src->duration;\n#if FF_API_CONVERGENCE_DURATION\nFF_DISABLE_DEPRECATION_WARNINGS\n    dst->convergence_duration = src->convergence_duration;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n    dst->flags                = src->flags;\n    dst->stream_index         = src->stream_index;\n    for (i = 0; i < src->side_data_elems; i++) {\n         enum AVPacketSideDataType type = src->side_data[i].type;\n         int size          = src->side_data[i].size;\n         uint8_t *src_data = src->side_data[i].data;\n         uint8_t *dst_data = av_packet_new_side_data(dst, type, size);\n        if (!dst_data) {\n            av_packet_free_side_data(dst);\n            return AVERROR(ENOMEM);\n        }\n        memcpy(dst_data, src_data, size);\n    }\n    return 0;\n}', 'static int packet_alloc(AVBufferRef **buf, int size)\n{\n    int ret;\n    if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)\n        return AVERROR(EINVAL);\n    ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE);\n    if (ret < 0)\n        return ret;\n    memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);\n    return 0;\n}', 'int av_buffer_realloc(AVBufferRef **pbuf, int size)\n{\n    AVBufferRef *buf = *pbuf;\n    uint8_t *tmp;\n    if (!buf) {\n        uint8_t *data = av_realloc(NULL, size);\n        if (!data)\n            return AVERROR(ENOMEM);\n        buf = av_buffer_create(data, size, av_buffer_default_free, NULL, 0);\n        if (!buf) {\n            av_freep(&data);\n            return AVERROR(ENOMEM);\n        }\n        buf->buffer->flags |= BUFFER_FLAG_REALLOCATABLE;\n        *pbuf = buf;\n        return 0;\n    } else if (buf->size == size)\n        return 0;\n    if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) ||\n        !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {\n        AVBufferRef *new = NULL;\n        av_buffer_realloc(&new, size);\n        if (!new)\n            return AVERROR(ENOMEM);\n        memcpy(new->data, buf->data, FFMIN(size, buf->size));\n        av_buffer_unref(pbuf);\n        *pbuf = new;\n        return 0;\n    }\n    tmp = av_realloc(buf->buffer->data, size);\n    if (!tmp)\n        return AVERROR(ENOMEM);\n    buf->buffer->data = buf->data = tmp;\n    buf->buffer->size = buf->size = size;\n    return 0;\n}', 'int av_buffer_is_writable(const AVBufferRef *buf)\n{\n    if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)\n        return 0;\n    return atomic_load(&buf->buffer->refcount) == 1;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n    if (size > (INT_MAX - 16))\n        return NULL;\n#if HAVE_ALIGNED_MALLOC\n    return _aligned_realloc(ptr, size, 32);\n#else\n    return realloc(ptr, size);\n#endif\n}']