[Libav-user] Problem using avcodec_decode_video2 for reading HEVC stream

Markus Pfundstein markuspfundstein86 at gmail.com
Wed Aug 27 19:14:36 CEST 2014


a frame can consist of several packets. thats why you need to call av_decode_video2 multiple times until it has a fully decoded frame for you. the return values tell you how much data was read. 
you should adjust packet.data and packet.size by those values.

there a a lot of examples out there that show this.

gr
markus

-- sent from ipad

> On 27 aug. 2014, at 15:48, Krishna <krish.rao.v at gmail.com> wrote:
> 
> Hi, 
> 
> I am writing an HEVC decoder and it seems that the first several frames are not decoded by avcodec_decode_video2(). Here is my code snippet. The input is an video-only stream (no audio). This is my function, that is called each time I need a single frame (that is essentially what I want  -- one frame at a time). 
> 
> bool decode(pFormatCtx, pCodecCtx)
> {
>     int gotaFrame=0;
>     int retVal = 0;
>     while (gotaFrame==0) {
> 
>         printf("1\t");
> 
>         if ( !av_read_frame(pFormatCtx, &packet) ) { 
>             if(packet.stream_index==videoStreamIndex) {
> 
>                 // try decoding
>                 retVal = avcodec_decode_video2(pCodecCtx, pFrame, &gotaFrame, &packet);
>                 printf("%d\t", retVal);
> 
>                 if (gotaFrame) {  // decode success.
> 
>                     printf("2\t");
> 
>                     // dump to yuv ... not shown here. 
> 
>                     // cleanup
>                     av_frame_unref(pFrame);
>                     av_frame_free(&pFrame);
>                     av_free_packet(&packet);
> 
>                     return true;
>                 }
>             }
>         }
>     }
> }
> 
> Here is the output of retVal: 
> 
> retval=33149	
> retval=6715	
> retval=767	
> retval=264	
> retval=126	
> retval=147	
> retval=286	
> retval=140	
> retval=141	
> retval=7243	
> retval=568	
> retval=315	
> retval=95	
> retval=146	
> retval=328	
> retval=159	
> retval=121	
> retval=7010	
> retval=571	
> retval=309
> 
> After the retVal=309, gotaFrame becomes 1. Essentially, I have lost a lot of frames. Can someone help me out here? 
> 
> How do I get one frame at a time?
> 
> Thank you! 
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user


More information about the Libav-user mailing list