<div dir="ltr"><div>I've just searched for any instance of AVCodecContext->frame_size and it is only read.</div><div><br></div><div>Here is a sample of how the AVCodecContext is setup<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>  // setup context<br>  vcodec_ctx->codec_id = static_cast<AVCodecID>(video_params_.codec);<br>  vcodec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;<br>  vcodec_ctx->width = video_params_.width;<br>  vcodec_ctx->height = video_params_.height;<br>  vcodec_ctx->sample_aspect_ratio = {1, 1};<br>  vcodec_ctx->pix_fmt = vcodec->pix_fmts[0]; // maybe be breakable code<br>  setupFrameRate(*vcodec_ctx, video_params_.frame_rate);<br>  if (video_params_.compression_type == CompressionType::CBR) {<br>    const auto brate = static_cast<int64_t>((video_params_.bitrate * 1E6) + 0.5);<br>    vcodec_ctx->bit_rate = brate;<br>    vcodec_ctx->rc_min_rate = brate;<br>    vcodec_ctx->rc_max_rate = brate;<br>  }<br>  vcodec_ctx->time_base = av_inv_q(vcodec_ctx->framerate);<br>  video_stream->time_base = vcodec_ctx->time_base;<br>  vcodec_ctx->gop_size = video_params_.gop_length_;<br>  vcodec_ctx->thread_count = static_cast<int>(std::thread::hardware_concurrency());</div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>  // Do bare minimum before avcodec_open2<br>  switch (vcodec_ctx->codec_id) {<br>    case AV_CODEC_ID_H264:<br>      setupH264Encoder(*vcodec_ctx, video_params_);<br>      break;<br>    case AV_CODEC_ID_MPEG2VIDEO:<br>      setupMPEG2Encoder(*vcodec_ctx, video_params_);<br>      break;<br>    case AV_CODEC_ID_DNXHD:<br>      setupDNXHDEncoder(*vcodec_ctx, video_params_);<br>      break;<br>    case AV_CODEC_ID_MPEG4:<br>      setupMPEG4Encoder(*vcodec_ctx, video_params_);<br>    default:<br>      // Nothing defined for these codecs yet<br>      break;<br>  }<br><br>  auto ret = avcodec_open2(vcodec_ctx, vcodec, &opts);<br>  if (ret < 0) {<br>    av_strerror(ret, err.data(), ERR_LEN);<br>    qCritical() << "Could not open output video encoder." << err.data();<br>    ed->export_error = tr("could not open output video encoder (%1)").arg(err.data());<br>    return false;<br>  }<br><br>  if (fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {<br>    vcodec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;<br>  }<br><br>  vcodec_ctx->sample_aspect_ratio = {1, 1};<br>  vcodec_ctx->max_b_frames = video_params_.b_frames_;<br><br>  // copy video encoder parameters to output stream<br>  ret = avcodec_parameters_from_context(video_stream->codecpar, vcodec_ctx);<br>  if (ret < 0) {<br>    av_strerror(ret, err.data(), ERR_LEN);<br>    qCritical() << "Could not copy video encoder parameters to output stream, code=" << err.data();<br>    ed->export_error = tr("could not copy video encoder parameters to output stream (%1)").arg(QString::number(ret));<br>    return false;<br>  }</div></blockquote><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div> void ExportThread::setupDNXHDEncoder(AVCodecContext& ctx, const Params& video_params) const<br>{<br>  ctx.profile = FF_PROFILE_DNXHD;<br>  // FIXME: DNXHDEncContext.pb needs setting up somehow<br><br>  if (video_params.profile_.endsWith("x")) {<br>    // dnxhdenc will deduce this as 10bits<br>    if (!video_params.pix_fmts_.empty())<br>    {<br>      auto fmt = video_params.pix_fmts_.front();<br>      switch (fmt)<br>      {<br>        case PixelFormat::YUV444:<br>          ctx.pix_fmt = AV_PIX_FMT_YUV444P10;<br>          break;<br>        case PixelFormat::YUV422:<br>          ctx.pix_fmt = AV_PIX_FMT_YUV422P10;<br>          break;<br>        case PixelFormat::YUV420:<br>          // this may not be in any profile<br>          ctx.pix_fmt = AV_PIX_FMT_YUV420P10;<br>          break;<br>      }<br>    }<br>  }<br>}</div></blockquote></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 3 Oct 2019 at 09:47, Paul B Mahol <<a href="mailto:onemda@gmail.com">onemda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 10/3/19, Jonathan Noble <<a href="mailto:jonnobleuk@gmail.com" target="_blank">jonnobleuk@gmail.com</a>> wrote:<br>
> It isn't reproduceable with ffmpeg. Am i in the wrong mailing-list?<br>
<br>
Perhaps you reset frame_size somehow?<br>
<br>
><br>
> On Thu, 3 Oct 2019 at 07:47, Paul B Mahol <<a href="mailto:onemda@gmail.com" target="_blank">onemda@gmail.com</a>> wrote:<br>
><br>
>> Please provide input samples that allow to reproduce this issue with<br>
>> ffmpeg.<br>
>><br>
>> On 10/2/19, Jonathan Noble <<a href="mailto:jonnobleuk@gmail.com" target="_blank">jonnobleuk@gmail.com</a>> wrote:<br>
>> > Hi,<br>
>> ><br>
>> > I am trying to encode to dnxhd with libavcodec. The result is quite<br>
>> glitchy<br>
>> > with stuttering and anomalies on most frames.<br>
>> ><br>
>> > During encoding I see the following message almost continuously.<br>
>> ><br>
>> >> Internal error, put_bits buffer too small<br>
>> ><br>
>> > I have tried to understand what this buffer is, how it is set up and I<br>
>> > am<br>
>> > struggling. From what I can understand the puts_bit buffer is<br>
>> > DNXHDEncContext->m->pb which is initialised via init_put_bits() in<br>
>> > dnxhd_encode_thread().<br>
>> ><br>
>> > The 2 arguments used in init_put_bits() are DNXHDEncContext->slice_offs<br>
>> and<br>
>> > DNXHDEncContext->slice_size. These 2 are configured in<br>
>> > dnxhd_setup_thread_slices() with 2 variables MpegEncContext->mb_width<br>
>> > and<br>
>> > MpegEncContext->mb_bits.<br>
>> ><br>
>> > If my understanding is correct the 2 aforementioned variables in<br>
>> > MpegEncContext are the variables I need to set. However, I have no idea<br>
>> > what they mean or how they are accessed outside of<br>
>> > AVCodecContext->priv_data.<br>
>> ><br>
>> > Is my understanding correct? How does one setup the puts_bit buffer<br>
>> > correctly for a dnxhd encode?<br>
>> ><br>
>> > Kind regards<br>
>> ><br>
>> > Jon Noble<br>
>> ><br>
>> _______________________________________________<br>
>> Libav-user mailing list<br>
>> <a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
>> <a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
>><br>
>> To unsubscribe, visit link above, or email<br>
>> <a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
><br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote></div>