5

I used libx264 in ffmpeg to encode video, I used the configuration below.

enCodecContext->bit_rate = 300000;
enCodecContext->width = 80;
enCodecContext->height = 60;
enCodecContext->time_base = (AVRational) {1, 25};
enCodecContext->gop_size = 10;
enCodecContext->max_b_frames = 1;
enCodecContext->pix_fmt = PIX_FMT_YUV420P;
enCodecContext->qcompress = 0.6;
av_opt_set(enCodecContext->priv_data, "preset", "slow", 0);

But when I called avcodec_encode_video2 with enCodecContext, I got the error Input picture width (40) is greater than stride (0).

avcodec_encode_video2(enCodecContext, &filteredAVPacket, pFilteredAVFrame, &got_packet_ptr);

The pFilteredAVFrame->width and pFilteredAVFrame->height is 80 and 60 respectively.

Did I missed something when configured libx264, How can I get a workable configuration for libx264 to encode my video?

alijandro
  • 11,627
  • 2
  • 58
  • 74
  • I see a [recent fix](http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=d1050d9950610aa2b27878b67bb2b902dd717e7c) for this problem. Maybe your ffmpeg is not up-to-date? – Alex Cohn Dec 27 '15 at 08:11
  • @AlexCohn My ffmpeg version is 2.8.2, and I thought this version has already apply this patch. – alijandro Dec 27 '15 at 12:49

1 Answers1

2

x264 is fine. You must fill in the AVPicture.linestride variable for your image planes. The stride describes how the image is laid out in memory. The stride must be at least as big as the image width. In the case of YUV 4:2:0, the stride must be at least half the width on the second and third plane.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx

szatmary
  • 29,969
  • 8
  • 44
  • 57