Changeset 967

Show
Ignore:
Timestamp:
10/23/08 14:31:55 (3 months ago)
Author:
astrange
Message:

Simplify finding pix_fmt and only use it on codecs where it's necessary. (avoids a bug in QT)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/perian-1.1/FFusionCodec.c

    r960 r967  
    277277} 
    278278 
     279static enum PixelFormat FindPixFmtFromVideo(AVCodec *codec, AVCodecContext *avctx, Ptr data, int bufferSize) 
     280{ 
     281    AVCodecContext tmpContext; 
     282    AVFrame tmpFrame; 
     283    int got_picture; 
     284    enum PixelFormat pix_fmt; 
     285     
     286    avcodec_get_context_defaults2(&tmpContext, CODEC_TYPE_VIDEO); 
     287    tmpContext.width = avctx->width; 
     288    tmpContext.height = avctx->height; 
     289    tmpContext.codec_tag = avctx->codec_tag; 
     290     
     291    avcodec_open(&tmpContext, codec); 
     292    avcodec_decode_video(&tmpContext, &tmpFrame, &got_picture, (UInt8*)data, bufferSize); 
     293    pix_fmt = tmpContext.pix_fmt; 
     294    avcodec_close(&tmpContext); 
     295     
     296    return pix_fmt; 
     297} 
     298 
    279299//--------------------------------------------------------------------------- 
    280300// Component Routines 
     
    536556        Handle imgDescExt; 
    537557        OSErr err = noErr; 
    538         enum PixelFormat pixelFormat = PIX_FMT_NONE; 
    539558         
    540559    // We first open libavcodec library and the codec corresponding 
     
    790809                        err = featureUnsupported; 
    791810                 
    792                 // this format doesn't have enough information in its headers 
    793                 // we have to decode the first frame 
    794                 if (glob->avContext->pix_fmt == PIX_FMT_NONE && p->bufferSize) { 
    795                         AVFrame temp; 
    796                         int got_picture; 
    797                         avcodec_open(glob->avContext, glob->avCodec); 
    798                         avcodec_decode_video(glob->avContext, &temp,  
    799                                                                  &got_picture, (UInt8*)p->data, p->bufferSize); 
    800                          
    801                         avcodec_close(glob->avContext); 
    802                         pixelFormat = glob->avContext->pix_fmt; 
    803                 } 
    804                  
    805811                // some hooks into ffmpeg's buffer allocation to get frames in  
    806812                // decode order without delay more easily 
     
    821827        } 
    822828                 
    823                 if (pixelFormat == PIX_FMT_NONE) 
    824                         pixelFormat = glob->avContext->pix_fmt; 
     829        // this format doesn't have enough information in its headers 
     830                // we have to decode the first frame 
     831                if (glob->avContext->pix_fmt == PIX_FMT_NONE && p->bufferSize && p->data) 
     832            glob->avContext->pix_fmt = FindPixFmtFromVideo(glob->avCodec, glob->avContext, p->data, p->bufferSize); 
    825833    } 
    826834     
     
    861869         
    862870        if (!err) { 
    863         switch (pixelFormat) 
     871        switch (glob->avContext->pix_fmt) 
    864872        { 
    865873                case PIX_FMT_BGR24: