[FFmpeg-cvslog] r22943 - trunk/ffmpeg.c

michael subversion
Thu Apr 22 11:40:51 CEST 2010


Author: michael
Date: Thu Apr 22 11:40:51 2010
New Revision: 22943

Log:
Make sure ffmpeg chooses a supported samplerte if the encoder supports
just some.

Modified:
   trunk/ffmpeg.c

Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c	Thu Apr 22 11:04:33 2010	(r22942)
+++ trunk/ffmpeg.c	Thu Apr 22 11:40:51 2010	(r22943)
@@ -485,6 +485,23 @@ static void choose_sample_fmt(AVStream *
     }
 }
 
+static void choose_sample_rate(AVStream *st, AVCodec *codec)
+{
+    if(codec && codec->supported_samplerates){
+        const int *p= codec->supported_samplerates;
+        int best;
+        int best_dist=INT_MAX;
+        for(; *p; p++){
+            int dist= abs(st->codec->sample_rate - *p);
+            if(dist < best_dist){
+                best_dist= dist;
+                best= *p;
+            }
+        }
+        st->codec->sample_rate= best;
+    }
+}
+
 static void choose_pixel_fmt(AVStream *st, AVCodec *codec)
 {
     if(codec && codec->pix_fmts){
@@ -3312,6 +3329,7 @@ static void new_audio_stream(AVFormatCon
     if (audio_stream_copy) {
         st->stream_copy = 1;
         audio_enc->channels = audio_channels;
+        audio_enc->sample_rate = audio_sample_rate;
     } else {
         AVCodec *codec;
 
@@ -3333,13 +3351,14 @@ static void new_audio_stream(AVFormatCon
         }
         audio_enc->channels = audio_channels;
         audio_enc->sample_fmt = audio_sample_fmt;
+        audio_enc->sample_rate = audio_sample_rate;
         audio_enc->channel_layout = channel_layout;
         if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)
             audio_enc->channel_layout = 0;
         choose_sample_fmt(st, codec);
+        choose_sample_rate(st, codec);
     }
     nb_ocodecs++;
-    audio_enc->sample_rate = audio_sample_rate;
     audio_enc->time_base= (AVRational){1, audio_sample_rate};
     if (audio_language) {
         av_metadata_set(&st->metadata, "language", audio_language);



More information about the ffmpeg-cvslog mailing list