]> git.sesse.net Git - mlt/commitdiff
Fix setting resolution and format in avformat image caching.
authorDan Dennedy <dan@dennedy.org>
Wed, 3 Feb 2010 08:41:25 +0000 (00:41 -0800)
committerDan Dennedy <dan@dennedy.org>
Fri, 5 Feb 2010 04:46:53 +0000 (20:46 -0800)
src/modules/avformat/producer_avformat.c

index 6c95914d5804569115646277d638597e72e158fc..bd3897c38c45d87d3b86307949bce9b47f9a251b 100644 (file)
@@ -831,16 +831,31 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Get the producer properties
        mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
 
+       // Fetch the video format context
+       AVFormatContext *context = this->video_format;
+
+       // Get the video stream
+       AVStream *stream = context->streams[ this->video_index ];
+
+       // Get codec context
+       AVCodecContext *codec_context = stream->codec;
+
        // Get the image cache
        if ( ! this->image_cache )
                this->image_cache = mlt_cache_init();
        mlt_cache_item item = mlt_cache_get( this->image_cache, (void*) position );
-       *buffer = mlt_cache_item_data( item, NULL );
+       *buffer = mlt_cache_item_data( item, format );
        if ( *buffer )
        {
                // Cache hit
                mlt_properties_set_data( frame_properties, "avformat.image_cache", item, 0, ( mlt_destructor )mlt_cache_item_close, NULL );
                mlt_properties_set_data( frame_properties, "image", *buffer, 0, NULL, NULL );
+               
+               // Set the resolution
+               *width = codec_context->width;
+               *height = codec_context->height;
+               mlt_properties_set_int( frame_properties, "width", *width );
+               mlt_properties_set_int( frame_properties, "height", *height );
                goto exit_get_image;
        }
        // Cache miss
@@ -848,15 +863,6 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
 
        avformat_lock();
 
-       // Fetch the video format context
-       AVFormatContext *context = this->video_format;
-
-       // Get the video stream
-       AVStream *stream = context->streams[ this->video_index ];
-
-       // Get codec context
-       AVCodecContext *codec_context = stream->codec;
-
        // Packet
        AVPacket pkt;
 
@@ -1217,7 +1223,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                // Copy buffer to image cache   
                uint8_t *image = mlt_pool_alloc( image_size );
                memcpy( image, *buffer, image_size );
-               mlt_cache_put( this->image_cache, (void*) position, image, image_size, mlt_pool_release );
+               mlt_cache_put( this->image_cache, (void*) position, image, *format, mlt_pool_release );
        }
 
 exit_get_image: