Revision 4a897224

View differences:

ffmpeg.c
128 128
static char *video_rc_eq="tex^qComp";
129 129
static int video_disable = 0;
130 130
static int video_discard = 0;
131
static int video_codec_id = CODEC_ID_NONE;
131
static char *video_codec_name = NULL;
132 132
static int video_codec_tag = 0;
133 133
static int same_quality = 0;
134 134
static int do_deinterlace = 0;
......
146 146
static float audio_qscale = QSCALE_NONE;
147 147
static int audio_disable = 0;
148 148
static int audio_channels = 1;
149
static int audio_codec_id = CODEC_ID_NONE;
149
static char  *audio_codec_name = NULL;
150 150
static int audio_codec_tag = 0;
151 151
static char *audio_language = NULL;
152 152

  
153 153
static int subtitle_disable = 0;
154
static int subtitle_codec_id = CODEC_ID_NONE;
154
static char *subtitle_codec_name = NULL;
155 155
static char *subtitle_language = NULL;
156 156

  
157 157
static float mux_preload= 0.5;
......
2368 2368
    video_standard = av_strdup(arg);
2369 2369
}
2370 2370

  
2371
static void opt_codec(int *pstream_copy, int *pcodec_id,
2371
static void opt_codec(int *pstream_copy, char **pcodec_name,
2372 2372
                      int codec_type, const char *arg)
2373 2373
{
2374
    AVCodec *p;
2375

  
2374
    av_freep(pcodec_name);
2376 2375
    if (!strcmp(arg, "copy")) {
2377 2376
        *pstream_copy = 1;
2378 2377
    } else {
2379
        p = first_avcodec;
2380
        while (p) {
2381
            if (!strcmp(p->name, arg) && p->type == codec_type)
2382
                break;
2383
            p = p->next;
2384
        }
2385
        if (p == NULL) {
2386
            fprintf(stderr, "Unknown codec '%s'\n", arg);
2387
            exit(1);
2388
        } else {
2389
            *pcodec_id = p->id;
2390
        }
2378
        *pcodec_name = av_strdup(arg);
2391 2379
    }
2392 2380
}
2393 2381

  
2394 2382
static void opt_audio_codec(const char *arg)
2395 2383
{
2396
    opt_codec(&audio_stream_copy, &audio_codec_id, CODEC_TYPE_AUDIO, arg);
2384
    opt_codec(&audio_stream_copy, &audio_codec_name, CODEC_TYPE_AUDIO, arg);
2397 2385
}
2398 2386

  
2399 2387
static void opt_audio_tag(const char *arg)
......
2439 2427

  
2440 2428
static void opt_video_codec(const char *arg)
2441 2429
{
2442
    opt_codec(&video_stream_copy, &video_codec_id, CODEC_TYPE_VIDEO, arg);
2430
    opt_codec(&video_stream_copy, &video_codec_name, CODEC_TYPE_VIDEO, arg);
2443 2431
}
2444 2432

  
2445 2433
static void opt_subtitle_codec(const char *arg)
2446 2434
{
2447
    opt_codec(&subtitle_stream_copy, &subtitle_codec_id, CODEC_TYPE_SUBTITLE, arg);
2435
    opt_codec(&subtitle_stream_copy, &subtitle_codec_name, CODEC_TYPE_SUBTITLE, arg);
2448 2436
}
2449 2437

  
2450 2438
static void opt_map(const char *arg)
......
2507 2495
    input_ts_offset = parse_date(arg, 1);
2508 2496
}
2509 2497

  
2498
static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
2499
{
2500
    AVCodec *codec;
2501

  
2502
    if(!name)
2503
        return CODEC_ID_NONE;
2504
    codec = encoder ?
2505
        avcodec_find_encoder_by_name(name) :
2506
        avcodec_find_decoder_by_name(name);
2507
    if(!codec) {
2508
        av_log(NULL, AV_LOG_ERROR, "Unknown codec '%s'\n", name);
2509
        exit(1);
2510
    }
2511
    if(codec->type != type) {
2512
        av_log(NULL, AV_LOG_ERROR, "Invalid codec type '%s'\n", name);
2513
        exit(1);
2514
    }
2515
    return codec->id;
2516
}
2517

  
2510 2518
static void opt_input_file(const char *filename)
2511 2519
{
2512 2520
    AVFormatContext *ic;
......
2534 2542
    ap->pix_fmt = frame_pix_fmt;
2535 2543
    ap->channel = video_channel;
2536 2544
    ap->standard = video_standard;
2537
    ap->video_codec_id = video_codec_id;
2538
    ap->audio_codec_id = audio_codec_id;
2545
    ap->video_codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 0);
2546
    ap->audio_codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 0);
2539 2547
    if(pgmyuv_compatibility_hack)
2540 2548
        ap->video_codec_id= CODEC_ID_PGMYUV;
2541 2549

  
......
2740 2748
        AVCodec *codec;
2741 2749

  
2742 2750
        codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
2743
        if (video_codec_id != CODEC_ID_NONE)
2744
            codec_id = video_codec_id;
2751
        if (video_codec_name)
2752
            codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);
2745 2753

  
2746 2754
        video_enc->codec_id = codec_id;
2747 2755
        codec = avcodec_find_encoder(codec_id);
......
2849 2857

  
2850 2858
    /* reset some key parameters */
2851 2859
    video_disable = 0;
2852
    video_codec_id = CODEC_ID_NONE;
2860
    av_freep(&video_codec_name);
2853 2861
    video_stream_copy = 0;
2854 2862
}
2855 2863

  
......
2896 2904
                av_set_double(audio_enc, opt_names[i], d);
2897 2905
        }
2898 2906

  
2899
        if (audio_codec_id != CODEC_ID_NONE)
2900
            codec_id = audio_codec_id;
2907
        if (audio_codec_name)
2908
            codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);
2901 2909
        audio_enc->codec_id = codec_id;
2902 2910

  
2903 2911
        if (audio_qscale > QSCALE_NONE) {
......
2917 2925

  
2918 2926
    /* reset some key parameters */
2919 2927
    audio_disable = 0;
2920
    audio_codec_id = CODEC_ID_NONE;
2928
    av_freep(&audio_codec_name);
2921 2929
    audio_stream_copy = 0;
2922 2930
}
2923 2931

  
......
2945 2953
             if(d==d && (opt->flags&AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
2946 2954
                 av_set_double(subtitle_enc, opt_names[i], d);
2947 2955
        }
2948
        subtitle_enc->codec_id = subtitle_codec_id;
2956
        subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1);
2949 2957
    }
2950 2958

  
2951 2959
    if (subtitle_language) {
......
2955 2963
    }
2956 2964

  
2957 2965
    subtitle_disable = 0;
2958
    subtitle_codec_id = CODEC_ID_NONE;
2966
    av_freep(&subtitle_codec_name);
2959 2967
    subtitle_stream_copy = 0;
2960 2968
}
2961 2969

  
......
3025 3033
            exit(1);
3026 3034
        }
3027 3035
    } else {
3028
        use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_id != CODEC_ID_NONE;
3029
        use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_id != CODEC_ID_NONE;
3030
        use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_id != CODEC_ID_NONE;
3036
        use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
3037
        use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
3038
        use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
3031 3039

  
3032 3040
        /* disable if no corresponding type found and at least one
3033 3041
           input file */
......
3863 3871

  
3864 3872
    av_free(opt_names);
3865 3873

  
3874
    av_free(video_codec_name);
3875
    av_free(audio_codec_name);
3876
    av_free(subtitle_codec_name);
3877

  
3866 3878
    av_free(video_standard);
3867 3879

  
3868 3880
#ifdef CONFIG_POWERPC_PERF

Also available in: Unified diff