[Ffmpeg-devel] help needed for ffmpeg-x264 'non existing PPS referenced' error

Zhifan Zhu Zhifan.Zhu
Wed Sep 6 18:00:33 CEST 2006


Hi all,
 
I am trying to use libavcodec (compiled with x264 support) in our local
lab.  To start with, I want to test the encoder and decoder first to get
a taste of how it may work best for us.  I wrote a simple test code
which generates a few image frames and feed them to the encoder and then
pass the encoded data to the decoder.  The encoder appears working fine
but the decoder fails on 'non existing PPS referenced' error.  Can
anyone tell me what is wrong?  I am pasting my test code below.  Any
help or hint is appreciated.
 
zz
 
=== test code ====
#include <stdlib.h>
#include <stdio.h>
#include <avcodec.h>
#include "rgb24_to_yuv420p.h"
 
int main(int argc, char *argv[])
{
 int width = 512;
 int height = 400;
 int bitrate = 800000;
 int frame_rate = 10;
 int gop_size = 10;
 int max_bframe = 0;
 
 av_register_all();
 // encoder first
 AVCodec *ecodec = avcodec_find_encoder(CODEC_ID_H264);
 if(!ecodec)
 {
  fprintf(stderr, "codec not found\n");
  return 1;
 }
 AVCodecContext *ec = avcodec_alloc_context();
 ec->codec_id = CODEC_ID_H264;
 ec->codec_type = CODEC_TYPE_VIDEO;
 ec->bit_rate = bitrate;
 ec->width = width;
 ec->height = height;
 ec->time_base.num = 1;
 ec->time_base.den = frame_rate;
 ec->gop_size = gop_size;
 ec->pix_fmt = PIX_FMT_YUV420P;
 ec->max_b_frames = max_bframe;
 ec->flags |= CODEC_FLAG_GLOBAL_HEADER;
 
 if(avcodec_open(ec,ecodec) < 0)
 {
  fprintf(stderr, "could not open codec\n");
  return 1;
 }
  
 AVFrame *epicture = avcodec_alloc_frame();
 int size = avpicture_get_size(ec->pix_fmt,ec->width,ec->height);
    uint8_t * epicture_buf = (uint8_t *)malloc(size);
 avpicture_fill((AVPicture *)epicture, epicture_buf, ec->pix_fmt,
ec->width, ec->height);
 uint8_t* evideo_outbuf = (uint8_t *)malloc(size);
 uint8_t *rgb = new uint8_t[width*height*3];
 // now decoder
 AVCodec *dcodec = avcodec_find_decoder(CODEC_ID_H264);
 if(!dcodec)
 {
  fprintf(stderr, "decoding codec not found\n");
  return 1;
 }
 
 AVCodecContext *dc = avcodec_alloc_context();
 
 if(avcodec_open(dc,dcodec) < 0)
 {
  fprintf(stderr, "could not open decoder.\n");
  return 1;
 }
 AVFrame *dframe = avcodec_alloc_frame();
 
 for(int i=0; i<10; i++)
 {
  for(int y=0; y<height; y++)
  {
   for(int x=0; x<width; x++)
   {
    int idx = (y*width+x)*3;
    rgb[idx+0] = x + y + i;
    rgb[idx+1] = x + y + i*2;
    rgb[idx+2] = x + y + i*3;
   }
  }
 
rgb24_to_yuv420p(epicture->data[0],epicture->data[1],epicture->data[2],rgb,
width,height);
  int out_size = avcodec_encode_video(ec,evideo_outbuf,size,epicture);
 
  int got_picture;
  int len = avcodec_decode_video(dc, dframe, &got_picture,
evideo_outbuf, out_size);
  // the above decode gives error 'non existing PPS referenced'
 
 }
 
 delete rgb;
 av_free(evideo_outbuf);
 avcodec_close(ec);
 av_free(ec);
 av_free(epicture->data[0]);
 av_free(epicture);
 av_free(dframe);
 
 return 0;
}
 

 




More information about the ffmpeg-devel mailing list