]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
remove double check of pb->read_seek
[ffmpeg] / ffmpeg.c
index 3f8ff96f059841acdd43a19e1af8a918cb48425a..1fbae5e5153d5247f297a43d7b6f8a2a92a14b17 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -126,7 +126,6 @@ static float video_rc_qmod_amp=0;
 static int video_rc_qmod_freq=0;
 #endif
 static char *video_rc_override_string=NULL;
-static char *video_rc_eq="tex^qComp";
 static int video_disable = 0;
 static int video_discard = 0;
 static char *video_codec_name = NULL;
@@ -445,6 +444,7 @@ static void do_audio_out(AVFormatContext *s,
 
     int size_out, frame_bytes, ret;
     AVCodecContext *enc= ost->st->codec;
+    AVCodecContext *dec= ist->st->codec;
 
     /* SC: dynamic allocation of buffers */
     if (!audio_buf)
@@ -454,6 +454,20 @@ static void do_audio_out(AVFormatContext *s,
     if (!audio_buf || !audio_out)
         return;               /* Should signal an error ! */
 
+    if (enc->channels != dec->channels)
+        ost->audio_resample = 1;
+
+    if (ost->audio_resample && !ost->resample) {
+        ost->resample = audio_resample_init(enc->channels,    dec->channels,
+                                            enc->sample_rate, dec->sample_rate);
+        if (!ost->resample) {
+            fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
+                    dec->channels, dec->sample_rate,
+                    enc->channels, enc->sample_rate);
+            exit(1);
+        }
+    }
+
     if(audio_sync_method){
         double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
                 - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2);
@@ -1615,38 +1629,8 @@ static int av_encode(AVFormatContext **output_files,
             case CODEC_TYPE_AUDIO:
                 if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
                     goto fail;
-
-                if (codec->channels == icodec->channels &&
-                    codec->sample_rate == icodec->sample_rate) {
-                    ost->audio_resample = 0;
-                } else {
-                    if (codec->channels != icodec->channels &&
-                        (icodec->codec_id == CODEC_ID_AC3 ||
-                         icodec->codec_id == CODEC_ID_DTS)) {
-                        /* Special case for 5:1 AC3 and DTS input */
-                        /* and mono or stereo output      */
-                        /* Request specific number of channels */
-                        icodec->channels = codec->channels;
-                        if (codec->sample_rate == icodec->sample_rate)
-                            ost->audio_resample = 0;
-                        else {
-                            ost->audio_resample = 1;
-                        }
-                    } else {
-                        ost->audio_resample = 1;
-                    }
-                }
-                if(audio_sync_method>1)
-                    ost->audio_resample = 1;
-
-                if(ost->audio_resample){
-                    ost->resample = audio_resample_init(codec->channels, icodec->channels,
-                                                    codec->sample_rate, icodec->sample_rate);
-                    if(!ost->resample){
-                        printf("Can't resample.  Aborting.\n");
-                        abort();
-                    }
-                }
+                ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
+                icodec->request_channels = codec->channels;
                 ist->decoding_needed = 1;
                 ost->encoding_needed = 1;
                 break;
@@ -2170,15 +2154,10 @@ static int opt_default(const char *opt, const char *arg){
 #endif
 
     if(avctx_opts[0]->debug)
-        av_log_level = AV_LOG_DEBUG;
+        av_log_set_level(AV_LOG_DEBUG);
     return 0;
 }
 
-static void opt_video_rc_eq(char *arg)
-{
-    video_rc_eq = arg;
-}
-
 static void opt_video_rc_override_string(char *arg)
 {
     video_rc_override_string = arg;
@@ -2192,7 +2171,7 @@ static void opt_me_threshold(const char *arg)
 static void opt_verbose(const char *arg)
 {
     verbose = atoi(arg);
-    av_log_level = atoi(arg);
+    av_log_set_level(atoi(arg));
 }
 
 static void opt_frame_rate(const char *arg)
@@ -2679,10 +2658,15 @@ static void opt_input_file(const char *filename)
     for(i=0; i<opt_name_count; i++){
         char buf[256];
         const AVOption *opt;
-        char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf));
+        const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf));
         if(str && (opt->flags & AV_OPT_FLAG_DECODING_PARAM))
             av_set_string(ic, opt_names[i], str);
     }
+
+    ic->video_codec_id   = find_codec_or_die(video_codec_name   , CODEC_TYPE_VIDEO   , 0);
+    ic->audio_codec_id   = find_codec_or_die(audio_codec_name   , CODEC_TYPE_AUDIO   , 0);
+    ic->subtitle_codec_id= find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 0);
+
     /* open the input file with generic libav function */
     err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
     if (err < 0) {
@@ -2734,7 +2718,7 @@ static void opt_input_file(const char *filename)
             for(j=0; j<opt_name_count; j++){
                 char buf[256];
                 const AVOption *opt;
-                char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt, buf, sizeof(buf));
+                const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt, buf, sizeof(buf));
                 if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM))
                     av_set_string(enc, opt_names[j], str);
             }
@@ -2748,7 +2732,7 @@ static void opt_input_file(const char *filename)
             for(j=0; j<opt_name_count; j++){
                 char buf[256];
                 const AVOption *opt;
-                char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt, buf, sizeof(buf));
+                const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt, buf, sizeof(buf));
                 if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM))
                     av_set_string(enc, opt_names[j], str);
             }
@@ -2895,7 +2879,7 @@ static void new_video_stream(AVFormatContext *oc)
         for(i=0; i<opt_name_count; i++){
             char buf[256];
             const AVOption *opt;
-            char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt, buf, sizeof(buf));
+            const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt, buf, sizeof(buf));
             if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
                 av_set_string(video_enc, opt_names[i], str);
         }
@@ -2948,7 +2932,6 @@ static void new_video_stream(AVFormatContext *oc)
             video_enc->inter_matrix = inter_matrix;
 
         video_enc->max_qdiff = video_qdiff;
-        video_enc->rc_eq = video_rc_eq;
         video_enc->thread_count = thread_count;
         p= video_rc_override_string;
         for(i=0; p; i++){
@@ -3039,7 +3022,7 @@ static void new_audio_stream(AVFormatContext *oc)
         for(i=0; i<opt_name_count; i++){
             char buf[256];
             const AVOption *opt;
-            char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt, buf, sizeof(buf));
+            const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt, buf, sizeof(buf));
             if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
                 av_set_string(audio_enc, opt_names[i], str);
         }
@@ -3090,7 +3073,7 @@ static void new_subtitle_stream(AVFormatContext *oc)
         for(i=0; i<opt_name_count; i++){
             char buf[256];
             const AVOption *opt;
-            char *str= av_get_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt, buf, sizeof(buf));
+            const char *str= av_get_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt, buf, sizeof(buf));
             if(str && (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
                 av_set_string(subtitle_enc, opt_names[i], str);
         }
@@ -3283,7 +3266,7 @@ static void opt_output_file(const char *filename)
     for(i=0; i<opt_name_count; i++){
         char buf[256];
         const AVOption *opt;
-        char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf));
+        const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf));
         if(str && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
             av_set_string(oc, opt_names[i], str);
     }
@@ -3325,10 +3308,11 @@ static int64_t getutime(void)
 
 static void opt_show_formats(void)
 {
-    AVInputFormat *ifmt;
-    AVOutputFormat *ofmt;
-    URLProtocol *up;
-    AVCodec *p, *p2;
+    AVInputFormat *ifmt=NULL;
+    AVOutputFormat *ofmt=NULL;
+    URLProtocol *up=NULL;
+    AVCodec *p=NULL, *p2;
+    AVBitStreamFilter *bsf=NULL;
     const char *last_name;
 
     printf("File formats:\n");
@@ -3339,7 +3323,7 @@ static void opt_show_formats(void)
         const char *name=NULL;
         const char *long_name=NULL;
 
-        for(ofmt = first_oformat; ofmt != NULL; ofmt = ofmt->next) {
+        while(ofmt= av_oformat_next(ofmt)) {
             if((name == NULL || strcmp(ofmt->name, name)<0) &&
                 strcmp(ofmt->name, last_name)>0){
                 name= ofmt->name;
@@ -3347,7 +3331,7 @@ static void opt_show_formats(void)
                 encode=1;
             }
         }
-        for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) {
+        while(ifmt= av_iformat_next(ifmt)) {
             if((name == NULL || strcmp(ifmt->name, name)<0) &&
                 strcmp(ifmt->name, last_name)>0){
                 name= ifmt->name;
@@ -3379,7 +3363,7 @@ static void opt_show_formats(void)
         const char *type_str;
 
         p2=NULL;
-        for(p = first_avcodec; p != NULL; p = p->next) {
+        while(p= av_codec_next(p)) {
             if((p2==NULL || strcmp(p->name, p2->name)<0) &&
                 strcmp(p->name, last_name)>0){
                 p2= p;
@@ -3424,8 +3408,13 @@ static void opt_show_formats(void)
     }
     printf("\n");
 
+    printf("Bitstream filters:\n");
+    while(bsf = av_bitstream_filter_next(bsf))
+        printf(" %s", bsf->name);
+    printf("\n");
+
     printf("Supported file protocols:\n");
-    for(up = first_protocol; up != NULL; up = up->next)
+    while(up = av_protocol_next(up))
         printf(" %s:", up->name);
     printf("\n");
 
@@ -3774,7 +3763,6 @@ const OptionDef options[] = {
     { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
     { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
     { "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantizer scale (VBR)", "q" },
-    { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" },
     { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
     { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
     { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold",  "" },