I am trying to use libavcodec along with libx264 to encode H.264 video in an flv container. Even though the equivalent works with ffmpeg from the command line (ffmpeg -i infile.flv -vcodec libx264 -vpre lossless_ultrafast -crf 22 -threads 0 outfile.flv), and even though the avcodec_find and avcodec_find_by_name calls both pass, the avcodec_open call fails for codec id CODEC_ID_H264. Any ideas? Any tips on trouble shooting?

Thanks,
Bob

<<
   AVCodec* l_pCodec;
   AVCodecContext* l_pCodecCtx;

   l_pCodecCtx = a_pStream->codec;

   a_pStream->codec->bit_rate = 250;
   switch (a_pStream->codec->codec_id)
   {
   case CODEC_ID_H264:
LOG4CXX_DEBUG(logger, l_strFunction << "Initializing libx264 encoder");
       //From libx264-lossless_ultrafast.ffpreset
       //coder=0
       a_pStream->codec->coder_type = FF_CODER_TYPE_VLC;
       //flags=+loop
       a_pStream->codec->flags |= CODEC_FLAG_LOOP_FILTER;
       //cmp=+chroma
       a_pStream->codec->me_cmp |= FF_CMP_CHROMA;
       //partitions=-parti8x8-parti4x4-partp8x8-partp4x4-partb8x8
a_pStream->codec->partitions &= ~(X264_PART_I8X8|X264_PART_I4X4|X264_PART_P8X8|X264_PART_P4X4|X264_PART_B
8X8);
       //me_method=dia
       a_pStream->codec->me_method = ME_EPZS;
       //subq=0
       a_pStream->codec->me_subpel_quality = 0;
       //me_range=16
       a_pStream->codec->me_range = 16;
       //g=250
       a_pStream->codec->gop_size = 250;
       //keyint_min=25
       a_pStream->codec->keyint_min = 25;
       //sc_threshold=40
       a_pStream->codec->scenechange_threshold = 40;
       //i_qfactor=0.71
       a_pStream->codec->i_quant_factor = 0.71;
       //b_strategy=1
       a_pStream->codec->b_frame_strategy = 1;
       //qcomp=0.6
       a_pStream->codec->qcompress = 0.6;
       //qmin=10
       a_pStream->codec->qmin = 10;
       //qmax=51
       a_pStream->codec->qmax = 51;
       //qdiff=4
       a_pStream->codec->max_qdiff = 4;
       //directpred=1
       a_pStream->codec->directpred = 1;
       //flags2=+fastpskip+mbtree
a_pStream->codec->flags2 |= (CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_MBTREE);
       //cqp=0
       a_pStream->codec->cqp = 0;
       //////////////////////////////////////
       a_pStream->codec->crf = 22;
       a_pStream->codec->thread_count = 0;
       break;
   default:
       break;
   }

   // find the video encoder  ********* (Both of these pass) *********
//  l_pCodec = avcodec_find_encoder(l_pCodecCtx->codec_id);
   l_pCodec = avcodec_find_encoder_by_name("libx264");
   if (!l_pCodec)
   {
LOG4CXX_DEBUG(logger, l_strFunction << "encoder not found " << l_pCodecCtx->codec_id);
       exit(1);
   }

   // open the codec  ********* (This Fails) *********
   if (avcodec_open(l_pCodecCtx, l_pCodec) < 0)
   {
LOG4CXX_DEBUG(logger, l_strFunction << "could not open codec " << l_pCodecCtx->codec_id);
       exit(1);
   }

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to