ffmpeg.c:3461: error: Null Dereference
  pointer `st` last assigned on line 3435 could be null and is dereferenced at line 3461, column 35.

ffmpeg.c:3427:1: start of procedure new_video_stream()
3425. }
3426. 
3427. static void new_video_stream(AVFormatContext *oc, int file_idx)
      ^
3428. {
3429.     AVStream *st;

ffmpeg.c:3432:5: 
3430.     AVOutputStream *ost;
3431.     AVCodecContext *video_enc;
3432.     enum CodecID codec_id = CODEC_ID_NONE;
          ^
3433.     AVCodec *codec= NULL;
3434. 

ffmpeg.c:3433:5: 
3431.     AVCodecContext *video_enc;
3432.     enum CodecID codec_id = CODEC_ID_NONE;
3433.     AVCodec *codec= NULL;
          ^
3434. 
3435.     st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);

ffmpeg.c:3435:28: Condition is true
3433.     AVCodec *codec= NULL;
3434. 
3435.     st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
                                 ^
3436.     if (!st) {
3437.         fprintf(stderr, "Could not alloc stream\n");

ffmpeg.c:3435:5: 
3433.     AVCodec *codec= NULL;
3434. 
3435.     st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
          ^
3436.     if (!st) {
3437.         fprintf(stderr, "Could not alloc stream\n");

libavformat/utils.c:2642:1: start of procedure av_new_stream()
  2640. }
  2641. 
  2642. AVStream *av_new_stream(AVFormatContext *s, int id)
        ^
  2643. {
  2644.     AVStream *st;

libavformat/utils.c:2648:9: Taking true branch
  2646.     AVStream **streams;
  2647. 
  2648.     if (s->nb_streams >= INT_MAX/sizeof(*streams))
                ^
  2649.         return NULL;
  2650.     streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));

libavformat/utils.c:2649:9: 
  2647. 
  2648.     if (s->nb_streams >= INT_MAX/sizeof(*streams))
  2649.         return NULL;
                ^
  2650.     streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));
  2651.     if (!streams)

libavformat/utils.c:2691:1: return from a call to av_new_stream
  2689.     s->streams[s->nb_streams++] = st;
  2690.     return st;
  2691. }
        ^
  2692. 
  2693. AVProgram *av_new_program(AVFormatContext *ac, int id)

ffmpeg.c:3436:10: Taking true branch
3434. 
3435.     st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
3436.     if (!st) {
               ^
3437.         fprintf(stderr, "Could not alloc stream\n");
3438.         ffmpeg_exit(1);

ffmpeg.c:3437:9: 
3435.     st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
3436.     if (!st) {
3437.         fprintf(stderr, "Could not alloc stream\n");
              ^
3438.         ffmpeg_exit(1);
3439.     }

ffmpeg.c:3438:9: Skipping ffmpeg_exit(): empty list of specs
3436.     if (!st) {
3437.         fprintf(stderr, "Could not alloc stream\n");
3438.         ffmpeg_exit(1);
              ^
3439.     }
3440.     ost = new_output_stream(oc, file_idx);

ffmpeg.c:3440:5: Skipping new_output_stream(): empty list of specs
3438.         ffmpeg_exit(1);
3439.     }
3440.     ost = new_output_stream(oc, file_idx);
          ^
3441. 
3442.     if(!video_stream_copy){

ffmpeg.c:3442:9: Taking true branch
3440.     ost = new_output_stream(oc, file_idx);
3441. 
3442.     if(!video_stream_copy){
              ^
3443.         if (video_codec_name) {
3444.             codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,

ffmpeg.c:3443:13: Taking true branch
3441. 
3442.     if(!video_stream_copy){
3443.         if (video_codec_name) {
                  ^
3444.             codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
3445.                                          avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);

ffmpeg.c:3444:13: 
3442.     if(!video_stream_copy){
3443.         if (video_codec_name) {
3444.             codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
                  ^
3445.                                          avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
3446.             codec = avcodec_find_encoder_by_name(video_codec_name);

ffmpeg.c:3126:1: start of procedure find_codec_or_die()
  3124. }
  3125. 
  3126. static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict)
        ^
  3127. {
  3128.     const char *codec_string = encoder ? "encoder" : "decoder";

ffmpeg.c:3128:32: Condition is true
  3126. static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict)
  3127. {
  3128.     const char *codec_string = encoder ? "encoder" : "decoder";
                                       ^
  3129.     AVCodec *codec;
  3130. 

ffmpeg.c:3128:5: 
  3126. static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict)
  3127. {
  3128.     const char *codec_string = encoder ? "encoder" : "decoder";
            ^
  3129.     AVCodec *codec;
  3130. 

ffmpeg.c:3131:9: Taking false branch
  3129.     AVCodec *codec;
  3130. 
  3131.     if(!name)
                ^
  3132.         return CODEC_ID_NONE;
  3133.     codec = encoder ?

ffmpeg.c:3133:13: Condition is true
  3131.     if(!name)
  3132.         return CODEC_ID_NONE;
  3133.     codec = encoder ?
                    ^
  3134.         avcodec_find_encoder_by_name(name) :
  3135.         avcodec_find_decoder_by_name(name);

ffmpeg.c:3133:5: 
  3131.     if(!name)
  3132.         return CODEC_ID_NONE;
  3133.     codec = encoder ?
            ^
  3134.         avcodec_find_encoder_by_name(name) :
  3135.         avcodec_find_decoder_by_name(name);

ffmpeg.c:3136:9: Taking false branch
  3134.         avcodec_find_encoder_by_name(name) :
  3135.         avcodec_find_decoder_by_name(name);
  3136.     if(!codec) {
                ^
  3137.         fprintf(stderr, "Unknown %s '%s'\n", codec_string, name);
  3138.         ffmpeg_exit(1);

ffmpeg.c:3140:8: Taking false branch
  3138.         ffmpeg_exit(1);
  3139.     }
  3140.     if(codec->type != type) {
               ^
  3141.         fprintf(stderr, "Invalid %s type '%s'\n", codec_string, name);
  3142.         ffmpeg_exit(1);

ffmpeg.c:3144:8: Taking false branch
  3142.         ffmpeg_exit(1);
  3143.     }
  3144.     if(codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
               ^
  3145.        strict > FF_COMPLIANCE_EXPERIMENTAL) {
  3146.         fprintf(stderr, "%s '%s' is experimental and might produce bad "

ffmpeg.c:3157:5: 
  3155.         ffmpeg_exit(1);
  3156.     }
  3157.     return codec->id;
            ^
  3158. }
  3159. 

ffmpeg.c:3158:1: return from a call to find_codec_or_die
  3156.     }
  3157.     return codec->id;
  3158. }
        ^
  3159. 
  3160. static int opt_input_file(const char *opt, const char *filename)

ffmpeg.c:3446:13: Skipping avcodec_find_encoder_by_name(): empty list of specs
3444.             codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
3445.                                          avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
3446.             codec = avcodec_find_encoder_by_name(video_codec_name);
                  ^
3447.             ost->enc = codec;
3448.         } else {

ffmpeg.c:3447:13: 
3445.                                          avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
3446.             codec = avcodec_find_encoder_by_name(video_codec_name);
3447.             ost->enc = codec;
                  ^
3448.         } else {
3449.             codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);

ffmpeg.c:3453:9: 
3451.         }
3452. 
3453.         ost->frame_aspect_ratio = frame_aspect_ratio;
              ^
3454.         frame_aspect_ratio = 0;
3455. #if CONFIG_AVFILTER

ffmpeg.c:3454:9: 
3452. 
3453.         ost->frame_aspect_ratio = frame_aspect_ratio;
3454.         frame_aspect_ratio = 0;
              ^
3455. #if CONFIG_AVFILTER
3456.         ost->avfilter= vfilters;

ffmpeg.c:3456:9: 
3454.         frame_aspect_ratio = 0;
3455. #if CONFIG_AVFILTER
3456.         ost->avfilter= vfilters;
              ^
3457.         vfilters = NULL;
3458. #endif

ffmpeg.c:3457:9: 
3455. #if CONFIG_AVFILTER
3456.         ost->avfilter= vfilters;
3457.         vfilters = NULL;
              ^
3458. #endif
3459.     }

ffmpeg.c:3461:5: 
3459.     }
3460. 
3461.     avcodec_get_context_defaults3(st->codec, codec);
          ^
3462.     ost->bitstream_filters = video_bitstream_filters;
3463.     video_bitstream_filters= NULL;

static void new_video_stream(AVFormatContext *oc, int file_idx)
{
    AVStream *st;
    AVOutputStream *ost;
    AVCodecContext *video_enc;
    enum CodecID codec_id = CODEC_ID_NONE;
    AVCodec *codec= NULL;
    st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
    if (!st) {
        fprintf(stderr, "Could not alloc stream\n");
        ffmpeg_exit(1);
    }
    ost = new_output_stream(oc, file_idx);
    if(!video_stream_copy){
        if (video_codec_name) {
            codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
                                         avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
            codec = avcodec_find_encoder_by_name(video_codec_name);
            ost->enc = codec;
        } else {
            codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
            codec = avcodec_find_encoder(codec_id);
        }
        ost->frame_aspect_ratio = frame_aspect_ratio;
        frame_aspect_ratio = 0;
#if CONFIG_AVFILTER
        ost->avfilter= vfilters;
        vfilters = NULL;
#endif
    }
    avcodec_get_context_defaults3(st->codec, codec);
    ost->bitstream_filters = video_bitstream_filters;
    video_bitstream_filters= NULL;
    st->codec->thread_count= thread_count;
    video_enc = st->codec;
    if(video_codec_tag)
        video_enc->codec_tag= video_codec_tag;
    if(oc->oformat->flags & AVFMT_GLOBALHEADER) {
        video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
        avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
    }
    if (video_stream_copy) {
        st->stream_copy = 1;
        video_enc->codec_type = AVMEDIA_TYPE_VIDEO;
        video_enc->sample_aspect_ratio =
        st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
    } else {
        const char *p;
        int i;
        if (frame_rate.num)
            ost->frame_rate = frame_rate;
        video_enc->codec_id = codec_id;
        set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
        video_enc->width = frame_width;
        video_enc->height = frame_height;
        video_enc->pix_fmt = frame_pix_fmt;
        st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
        if (intra_only)
            video_enc->gop_size = 0;
        if (video_qscale || same_quality) {
            video_enc->flags |= CODEC_FLAG_QSCALE;
            video_enc->global_quality = FF_QP2LAMBDA * video_qscale;
        }
        if(intra_matrix)
            video_enc->intra_matrix = intra_matrix;
        if(inter_matrix)
            video_enc->inter_matrix = inter_matrix;
        p= video_rc_override_string;
        for(i=0; p; i++){
            int start, end, q;
            int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
            if(e!=3){
                fprintf(stderr, "error parsing rc_override\n");
                ffmpeg_exit(1);
            }
            video_enc->rc_override=
                av_realloc(video_enc->rc_override,
                           sizeof(RcOverride)*(i+1));
            video_enc->rc_override[i].start_frame= start;
            video_enc->rc_override[i].end_frame  = end;
            if(q>0){
                video_enc->rc_override[i].qscale= q;
                video_enc->rc_override[i].quality_factor= 1.0;
            }
            else{
                video_enc->rc_override[i].qscale= 0;
                video_enc->rc_override[i].quality_factor= -q/100.0;
            }
            p= strchr(p, '/');
            if(p) p++;
        }
        video_enc->rc_override_count=i;
        if (!video_enc->rc_initial_buffer_occupancy)
            video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
        video_enc->me_threshold= me_threshold;
        video_enc->intra_dc_precision= intra_dc_precision - 8;
        if (do_psnr)
            video_enc->flags|= CODEC_FLAG_PSNR;
        if (do_pass) {
            if (do_pass == 1) {
                video_enc->flags |= CODEC_FLAG_PASS1;
            } else {
                video_enc->flags |= CODEC_FLAG_PASS2;
            }
        }
        if (forced_key_frames)
            parse_forced_key_frames(forced_key_frames, ost, video_enc);
    }
    if (video_language) {
        av_dict_set(&st->metadata, "language", video_language, 0);
        av_freep(&video_language);
    }
    video_disable = 0;
    av_freep(&video_codec_name);
    av_freep(&forced_key_frames);
    video_stream_copy = 0;
    frame_pix_fmt = PIX_FMT_NONE;
}
['static void new_video_stream(AVFormatContext *oc, int file_idx)\n{\n    AVStream *st;\n    AVOutputStream *ost;\n    AVCodecContext *video_enc;\n    enum CodecID codec_id = CODEC_ID_NONE;\n    AVCodec *codec= NULL;\n    st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);\n    if (!st) {\n        fprintf(stderr, "Could not alloc stream\\n");\n        ffmpeg_exit(1);\n    }\n    ost = new_output_stream(oc, file_idx);\n    if(!video_stream_copy){\n        if (video_codec_name) {\n            codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,\n                                         avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);\n            codec = avcodec_find_encoder_by_name(video_codec_name);\n            ost->enc = codec;\n        } else {\n            codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);\n            codec = avcodec_find_encoder(codec_id);\n        }\n        ost->frame_aspect_ratio = frame_aspect_ratio;\n        frame_aspect_ratio = 0;\n#if CONFIG_AVFILTER\n        ost->avfilter= vfilters;\n        vfilters = NULL;\n#endif\n    }\n    avcodec_get_context_defaults3(st->codec, codec);\n    ost->bitstream_filters = video_bitstream_filters;\n    video_bitstream_filters= NULL;\n    st->codec->thread_count= thread_count;\n    video_enc = st->codec;\n    if(video_codec_tag)\n        video_enc->codec_tag= video_codec_tag;\n    if(oc->oformat->flags & AVFMT_GLOBALHEADER) {\n        video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n        avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n    }\n    if (video_stream_copy) {\n        st->stream_copy = 1;\n        video_enc->codec_type = AVMEDIA_TYPE_VIDEO;\n        video_enc->sample_aspect_ratio =\n        st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);\n    } else {\n        const char *p;\n        int i;\n        if (frame_rate.num)\n            ost->frame_rate = frame_rate;\n        video_enc->codec_id = codec_id;\n        set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);\n        video_enc->width = frame_width;\n        video_enc->height = frame_height;\n        video_enc->pix_fmt = frame_pix_fmt;\n        st->sample_aspect_ratio = video_enc->sample_aspect_ratio;\n        if (intra_only)\n            video_enc->gop_size = 0;\n        if (video_qscale || same_quality) {\n            video_enc->flags |= CODEC_FLAG_QSCALE;\n            video_enc->global_quality = FF_QP2LAMBDA * video_qscale;\n        }\n        if(intra_matrix)\n            video_enc->intra_matrix = intra_matrix;\n        if(inter_matrix)\n            video_enc->inter_matrix = inter_matrix;\n        p= video_rc_override_string;\n        for(i=0; p; i++){\n            int start, end, q;\n            int e=sscanf(p, "%d,%d,%d", &start, &end, &q);\n            if(e!=3){\n                fprintf(stderr, "error parsing rc_override\\n");\n                ffmpeg_exit(1);\n            }\n            video_enc->rc_override=\n                av_realloc(video_enc->rc_override,\n                           sizeof(RcOverride)*(i+1));\n            video_enc->rc_override[i].start_frame= start;\n            video_enc->rc_override[i].end_frame  = end;\n            if(q>0){\n                video_enc->rc_override[i].qscale= q;\n                video_enc->rc_override[i].quality_factor= 1.0;\n            }\n            else{\n                video_enc->rc_override[i].qscale= 0;\n                video_enc->rc_override[i].quality_factor= -q/100.0;\n            }\n            p= strchr(p, \'/\');\n            if(p) p++;\n        }\n        video_enc->rc_override_count=i;\n        if (!video_enc->rc_initial_buffer_occupancy)\n            video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;\n        video_enc->me_threshold= me_threshold;\n        video_enc->intra_dc_precision= intra_dc_precision - 8;\n        if (do_psnr)\n            video_enc->flags|= CODEC_FLAG_PSNR;\n        if (do_pass) {\n            if (do_pass == 1) {\n                video_enc->flags |= CODEC_FLAG_PASS1;\n            } else {\n                video_enc->flags |= CODEC_FLAG_PASS2;\n            }\n        }\n        if (forced_key_frames)\n            parse_forced_key_frames(forced_key_frames, ost, video_enc);\n    }\n    if (video_language) {\n        av_dict_set(&st->metadata, "language", video_language, 0);\n        av_freep(&video_language);\n    }\n    video_disable = 0;\n    av_freep(&video_codec_name);\n    av_freep(&forced_key_frames);\n    video_stream_copy = 0;\n    frame_pix_fmt = PIX_FMT_NONE;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n    AVStream *st;\n    int i;\n    AVStream **streams;\n    if (s->nb_streams >= INT_MAX/sizeof(*streams))\n        return NULL;\n    streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));\n    if (!streams)\n        return NULL;\n    s->streams = streams;\n    st = av_mallocz(sizeof(AVStream));\n    if (!st)\n        return NULL;\n    if (!(st->info = av_mallocz(sizeof(*st->info)))) {\n        av_free(st);\n        return NULL;\n    }\n    st->codec= avcodec_alloc_context();\n    if (s->iformat) {\n        st->codec->bit_rate = 0;\n    }\n    st->index = s->nb_streams;\n    st->id = id;\n    st->start_time = AV_NOPTS_VALUE;\n    st->duration = AV_NOPTS_VALUE;\n    st->cur_dts = 0;\n    st->first_dts = AV_NOPTS_VALUE;\n    st->probe_packets = MAX_PROBE_PACKETS;\n    av_set_pts_info(st, 33, 1, 90000);\n    st->last_IP_pts = AV_NOPTS_VALUE;\n    for(i=0; i<MAX_REORDER_DELAY+1; i++)\n        st->pts_buffer[i]= AV_NOPTS_VALUE;\n    st->reference_dts = AV_NOPTS_VALUE;\n    st->sample_aspect_ratio = (AVRational){0,1};\n    s->streams[s->nb_streams++] = st;\n    return st;\n}', 'static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict)\n{\n    const char *codec_string = encoder ? "encoder" : "decoder";\n    AVCodec *codec;\n    if(!name)\n        return CODEC_ID_NONE;\n    codec = encoder ?\n        avcodec_find_encoder_by_name(name) :\n        avcodec_find_decoder_by_name(name);\n    if(!codec) {\n        fprintf(stderr, "Unknown %s \'%s\'\\n", codec_string, name);\n        ffmpeg_exit(1);\n    }\n    if(codec->type != type) {\n        fprintf(stderr, "Invalid %s type \'%s\'\\n", codec_string, name);\n        ffmpeg_exit(1);\n    }\n    if(codec->capabilities & CODEC_CAP_EXPERIMENTAL &&\n       strict > FF_COMPLIANCE_EXPERIMENTAL) {\n        fprintf(stderr, "%s \'%s\' is experimental and might produce bad "\n                "results.\\nAdd \'-strict experimental\' if you want to use it.\\n",\n                codec_string, codec->name);\n        codec = encoder ?\n            avcodec_find_encoder(codec->id) :\n            avcodec_find_decoder(codec->id);\n        if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))\n            fprintf(stderr, "Or use the non experimental %s \'%s\'.\\n",\n                    codec_string, codec->name);\n        ffmpeg_exit(1);\n    }\n    return codec->id;\n}']