3
pAvframe = GetVideoFrame();

av_init_packet(&pkt);
/* encode the image */
ret = avcodec_encode_video2(pAvCodecCtx, &pkt, pAvframe, &got_packet); //return Generic error in external library
if (ret < 0) 
{
    char errbuf[128];
    const char *errbuf_ptr = errbuf;

    if (av_strerror(ret, errbuf, sizeof(errbuf)) < 0)
        errbuf_ptr = strerror(AVUNERROR(ret));
    av_log(NULL, AV_LOG_ERROR, "%s\n", errbuf_ptr);

    _stprintf_s(szErr,MAX_PATH, _T("Error encoding video frame:: "));
    LOG_ENTRY_ERROR(E_FAIL,szErr);
}



if(ret >= 0)
{
    ret = WriteFrameToFile(&pAvCodecCtx->time_base, m_stVideoStream.pAVStream, &pkt);
    if(ret < 0)
    {
        av_packet_unref(&pkt);

    }
}

It always return - -542398533 "Generic error in an external library" only with h.264 encoder please provide solution if gop is zero it work some time.

Ronald S. Bultje
  • 10,828
  • 26
  • 47
Parwez Akhtar
  • 243
  • 1
  • 3
  • 13

1 Answers1

1

What are the contents of pAvFrame? For example, what is the pix_fmt, width and height? pix_fmt should (depending on the build of x264, but I'm assuming a typical config here) be AV_PIX_FMT_YUV420P. Assuming 4:2:0 chroma subsampling, sizes should be even numbers. Are the data pointers and linesizes 32-byte aligned?

Could you also provide some information on how you initialized the encoder, i.e. the code that calls avcodec_open2(), particularly which entries you set in the AVCodecContext before the call to avcodec_open2(), and all calls to av_opt_set_*().

Ronald S. Bultje
  • 10,828
  • 26
  • 47
  • I tried to set av_opt_set with three option av_opt_set(pAvCodecCtx->priv_data, "preset", "slow", 0); av_opt_set(pAvCodecCtx->priv_data, "tune", "zerolatency", 0); av_opt_set(pAvCodecCtx->priv_data, "x264opts", "no-mbtree:sliced-threads:sync-lookahead=0", 0); tune and x264opts did the work but i want to know what is it set – Parwez Akhtar Jan 23 '17 at 05:40
  • don't touch priv_data, you can av_opt_set() on pAvCodecCtx and it will do the right thing. What do you mean "I want to know what is it set"? – Ronald S. Bultje Jan 23 '17 at 15:30
  • `av_opt_set(pAvCodecCtx->priv_data, "x264opts", "no-mbtree:sliced threads:sync-lookahead=0", 0);` what is meaning of this method and i tried to pass only pAvCodecCtx than again avcodec_encode_video2 return -542398533 – Parwez Akhtar Jan 24 '17 at 10:51
  • I was wrong, you need priv_data if you use 0 as last argument in av_opt_set(), or you can call it on pAvCodecCtx but need to change the 0 into AV_OPT_SEARCH_CHILDREN, sorry about that. – Ronald S. Bultje Jan 24 '17 at 11:53
  • Ronald sorry for disturb you but last question is it required only for h264 encoder and can i set all available option like `av_opt_set(pAvCodecCtx->priv_data, "tune", "zerolatency", 0); av_opt_set(pAvCodecCtx->priv_data, "preset", "slow", 0); av_opt_set(pAvCodecCtx->priv_data, "x264opts", "no-mbtree:sliced threads:sync-lookahead=0", 0); ` thnks alots – Parwez Akhtar Jan 24 '17 at 12:47
  • av_opt_set(ctx->priv_data, "name", val) is for private options, so those options that are codec-specific (e.g. https://www.ffmpeg.org/doxygen/trunk/libx264_8c_source.html#l00902 for x264). For generic options (like keyframe interval, bitrate), you need to av_opt_set(pAvCodecCtx, "name", value), where option_name is anything from https://www.ffmpeg.org/doxygen/trunk/libavcodec_2options__table_8h-source.html – Ronald S. Bultje Jan 24 '17 at 13:22