Hello,

I found the reason. In my code, where i initialize the CodecContext and so on, 
the are these lines from a former tutorial (former means here, where we use 
av_read_packet instead of av_read_frame).

if(mPCodec->capabilities & CODEC_CAP_TRUNCATED) 
    mPCodecCtx->flags|=CODEC_FLAG_TRUNCATED;

So I remove these lines and voila! Heureka! It works.

regards,
Sven

Am Sonntag 11 Januar 2009 17:24 schrieb Sven Alisch:
> Hello,
>
> I have a strange problem and do not find a solution. I try to extract a
> serie of Pictures in a MPEG2-Transport-Stream. The I-Frames are nice and
> ok, but the other frames (P- and B-frames) are corrupted. My Code is the
> following:
>
> int i = 0;  // Pic Nr.
> int frameFinished = 0;
>
> do
> {
>    if (packet.stream_index == mStreamID)              // at this step I've 
> already read
> a packet!
>    {
>         int bytesRemaining = packet.size;
>         int bytesDecoded = 0;
>
>         bytesDecoded = avcodec_decode_video(mPCodecCtx, frame,
> &frameFinished, packet.data, packet.size);
>
>         if (frameFinished)
>         {
>           i++;
>
>           if (i == 12)        // only 12 pictures for test
>             return;
>
>           cout << frame->pict_type << " dekodiert!" << endl;
>
>           int numBytes=avpicture_get_size(PIX_FMT_RGB24, mPCodecCtx->width,
> mPCodecCtx->height);
>           uint8_t* imgbuf = (uint8_t*) av_malloc(numBytes*sizeof(uint8_t));
>
>           avpicture_fill((AVPicture *)pFrameRGB, imgbuf, PIX_FMT_RGB24,
> mPCodecCtx->width, mPCodecCtx->height);
>
>           img_convert_ctx = sws_getContext(mPCodecCtx->width,
> mPCodecCtx->height,
>                                            mPCodecCtx->pix_fmt,
>                                            mPCodecCtx->width,
> mPCodecCtx->height,
>                                            PIX_FMT_RGB24,
>                                            SWS_BICUBIC, NULL, NULL, NULL);
>           sws_scale(img_convert_ctx, frame->data, frame->linesize,
>                     0, mPCodecCtx->height, pFrameRGB->data,
> pFrameRGB->linesize);
>
>           // Bild als PPM speichern
>           int flength = (mPCodecCtx->width * mPCodecCtx-> height * 3) + 15;
>           rawframe = new uint8_t[flength+1];
>           sprintf((char*)rawframe,"P6\n%d %d\n255\n", mPCodecCtx->width,
> mPCodecCtx->height);
>
>           // dekodierten Bildinhalt kopieren
>           int buf_stelle = 15;  // Nach dem PPM-Bild-Header
>           for(int y=0; y<mPCodecCtx->height; y++)
>           {
>             memcpy(&rawframe[buf_stelle],
> pFrameRGB->data[0]+y*pFrameRGB->linesize[0], mPCodecCtx->width*3);
>             buf_stelle += mPCodecCtx->width*3;
>           }
>           flength = buf_stelle;
>
>           ostringstream Str;
>           Str << i;
>
>           string filename = "pic" + Str.str() + ".ppm";
>           FILE* fp = fopen(filename.c_str(),"wb");
>           fwrite(rawframe, flength, 1, fp);
>           fclose(fp);
>         }
>       }
>
>       av_free_packet(&packet);
>
>     } while (av_read_frame(mPAVFile->_formatContext(), &packet) >= 0);
>
> After the extraction I get only nice I-Frames. The rest of the pictures are
> corrupted. May anyone help me?
>
> regards,
> Sven
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to