[Libav-user] h264_mp4toannexb filter returns -22

francesco at bltitalia.com francesco at bltitalia.com
Wed Apr 20 15:38:29 CEST 2016


Hi
I'm attempting to encode in h264 annex b using libavcodec with quicksync.
I can compress using quicksync, but I can't make working the filter that
should create annex b format.
Here is the code:

AVCodecContext *ff_cdctx;
AVCodec *ff_codec;
AVPacket pkt;
AVDictionary *param;
AVBitStreamFilterContext *bsfc;
int dstsz1;
uint8_t *poutb=NULL;


  ff_codec = avcodec_find_encoder_by_name("mpeg2_qsv");
  ff_cdctx = avcodec_alloc_context3(ff_codec); 
  
  if (av_dict_set(&param, "profile", "main", 0)<0) return -3;
  if (av_dict_set(&param, "preset", "medium", 0)<0) return -4;
  
  ff_cdctx->pix_fmt = AV_PIX_FMT_NV12;
  ff_cdctx->flags |= CODEC_FLAG_GLOBAL_HEADER;

  bsfc = av_bitstream_filter_init("h264_mp4toannexb");
  if (ff_cdctx->extradata_size == 0)
  {
    ff_cdctx->extradata_size = sps_pps_size;
    ff_cdctx->extradata = (uint8_t*)av_mallocz(ff_cdctx->extradata_size);
    if (ff_cdctx->extradata == NULL)
    {
       if (av_strerror(opres, err_str, 256) == 0) OutputDebugStringA(err_str);
				return -100;
    }
    memcpy(ff_cdctx->extradata, sps_pps, sps_pps_size);
  }    
  
  // Other initializations 
      
   avcodec_open2(ff_cdctx,ff_codec,&param);
      
   // main loop
   {
      
      
     enc_err = avcodec_encode_video2(ff_cdctx,&pkt, pfframe,&got_pkt);
     if(got_pkt)
     {
        enc_err = av_bitstream_filter_filter(bsfc, ff_cdctx,
"private_spspps_buf", &poutb, &dstsz1, pkt.data, pkt.size,
pkt.flags&AV_PKT_FLAG_KEY);
     }
        
    }
      
in the loop when I call av_bitstream_filter_filter I receive error -22
(invalid parameter).
The poutb pointer is allocated with size equal to packet size (pkt.size) and
no sps or pps
are inserted.
Where is the mistake ?
/*******************************************************************\
*    Ing. Francesco  Cuzzocrea
*    company:    BLT Italia srl        web:  http://www.blt.it
*    address:    via Rosselli, 91     city:  Lido di CAMAIORE
*    country:    ITALY                 zip:  55043-i
*      Tel. :    +39 0584 904788       Fax:  +39 0584 904789  
*     e-mail:   francesco at bltitalia.com
\*******************************************************************/
--  BLT will be at NAB2016 (18 ~ 21 April 2016)  -  Booth  C7806   --

 



More information about the Libav-user mailing list