]> git.sesse.net Git - mlt/blobdiff - src/modules/avformat/producer_avformat.c
Fix sample count and rate with audio_index=all.
[mlt] / src / modules / avformat / producer_avformat.c
index d7a34e83eebbbb18bd646ca588cba83f6e6fdac0..3dab6165de3c38852200c8ac9e3b243a4757561e 100644 (file)
@@ -959,7 +959,7 @@ static int seek_video( producer_avformat self, mlt_position position,
                                timestamp -= 2 / av_q2d( self->video_time_base );
                        if ( timestamp < 0 )
                                timestamp = 0;
-                       mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "seeking timestamp %"PRId64" position %d expected %d last_pos %"PRId64"\n",
+                       mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "seeking timestamp %"PRId64" position " MLT_POSITION_FMT " expected "MLT_POSITION_FMT" last_pos %"PRId64"\n",
                                timestamp, position, self->video_expected, self->last_position );
 
                        // Seek to the timestamp
@@ -2010,31 +2010,33 @@ static int sample_bytes( AVCodecContext *context )
 #endif
 }
 
-static void planar_to_interleaved( uint8_t *dest, uint8_t *src, int samples, int channels, int bytes_per_sample )
+#if LIBAVCODEC_VERSION_MAJOR >= 55
+static void planar_to_interleaved( uint8_t *dest, AVFrame *src, int samples, int channels, int bytes_per_sample )
 {
        int s, c;
        for ( s = 0; s < samples; s++ )
        {
                for ( c = 0; c < channels; c++ )
                {
-                       memcpy( dest, src + ( c * samples + s ) * bytes_per_sample, bytes_per_sample );
+                       memcpy( dest, &src->data[c][s * bytes_per_sample], bytes_per_sample );
                        dest += bytes_per_sample;
                }
        }
 }
-
-static void planar_to_interleaved2( uint8_t *dest, AVFrame *src, int samples, int channels, int bytes_per_sample )
+#else
+static void planar_to_interleaved( uint8_t *dest, uint8_t *src, int samples, int channels, int bytes_per_sample )
 {
        int s, c;
        for ( s = 0; s < samples; s++ )
        {
                for ( c = 0; c < channels; c++ )
                {
-                       memcpy( dest, &src->data[c][s * bytes_per_sample], bytes_per_sample );
+                       memcpy( dest, src + ( c * samples + s ) * bytes_per_sample, bytes_per_sample );
                        dest += bytes_per_sample;
                }
        }
 }
+#endif
 
 static int decode_audio( producer_avformat self, int *ignore, AVPacket pkt, int channels, int samples, double timecode, double fps )
 {
@@ -2106,7 +2108,7 @@ static int decode_audio( producer_avformat self, int *ignore, AVPacket pkt, int
                        case AV_SAMPLE_FMT_S32P:
                        case AV_SAMPLE_FMT_FLTP:
 #if LIBAVCODEC_VERSION_MAJOR >= 55
-                               planar_to_interleaved2( dest, self->audio_frame, convert_samples, codec_context->channels, sizeof_sample );
+                               planar_to_interleaved( dest, self->audio_frame, convert_samples, codec_context->channels, sizeof_sample );
 #else
                                planar_to_interleaved( dest, decode_buffer, convert_samples, codec_context->channels, sizeof_sample );
 #endif
@@ -2209,8 +2211,8 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                index = 0;
                index_max = FFMIN( MAX_AUDIO_STREAMS, context->nb_streams );
                *channels = self->total_channels;
-               *samples = mlt_sample_calculator( fps, FFMAX( self->max_frequency, *frequency ), position );
-               *frequency = FFMAX( self->max_frequency, *frequency );
+               *samples = mlt_sample_calculator( fps, self->max_frequency, position );
+               *frequency = self->max_frequency;
        }
 
        // Initialize the buffers
@@ -2537,14 +2539,11 @@ static void producer_set_up_audio( producer_avformat self, mlt_frame frame )
                                audio_codec_init( self, index, properties );
                }
        }
-       else if ( context && index > -1 && audio_codec_init( self, index, properties ) )
+       else if ( context && index > -1 && index < MAX_AUDIO_STREAMS &&
+               audio_codec_init( self, index, properties ) )
        {
-               // Set the frame properties
-               if ( index < MAX_AUDIO_STREAMS )
-               {
-                       mlt_properties_set_int( frame_properties, "audio_frequency", self->audio_codec[ index ]->sample_rate );
-                       mlt_properties_set_int( frame_properties, "audio_channels", self->audio_codec[ index ]->channels );
-               }
+               mlt_properties_set_int( frame_properties, "audio_frequency", self->audio_codec[ index ]->sample_rate );
+               mlt_properties_set_int( frame_properties, "audio_channels", self->audio_codec[ index ]->channels );
        }
        if ( context && index > -1 )
        {