title: ffmpeg hangs in avcodec_encode_video2
body: <p>I encode the video stream using ffmeg. Shell QT Creator. OC Windows 7. The compiler MinGW. H264 codec.</p>
  
  <p>There is a function, which I give to the input frame, and I must return an encoded byte array. Within this function it hangs when calling avcodec_encode_video2, but not on the first call, and at random.
  That is, an arbitrary coding frame hangs (100 to 10000).</p>
  
  <pre><code>QByteArray VideoEncoder::createFrameVideoFromImage(QImage picture)
  {
      AVFrame* frame_source = av_frame_alloc();        
      avpicture_fill((AVPicture*)frame_source, picture.bits(), AV_PIX_FMT_RGB24, this-&gt;width_frame, this-&gt;height_frame);
  
      AVFrame* frame_dst = av_frame_alloc();
  
      avpicture_fill((AVPicture*)frame_dst, (uint8_t*)this-&gt;inbuffer, AV_PIX_FMT_YUV420P, this-&gt;width_frame, this-&gt;height_frame);
  
      sws_scale(this-&gt;convert_rgb_yuv, frame_source-&gt;data, frame_source-&gt;linesize,
          0, this-&gt;ctx_codec_in-&gt;height, frame_dst-&gt;data, frame_dst-&gt;linesize);
  
      AVPacket packet;
      av_init_packet(&amp;packet);
      packet.data = NULL;
      packet.size = 0;
      packet.pts = packet.dts = AV_NOPTS_VALUE;
  
      int nOutputSize = 0;
      if (avcodec_encode_video2(this-&gt;ctx_codec_in, &amp;packet, frame_dst, &amp;nOutputSize) &lt; 0)
      {
          qDebug() &lt;&lt; "VideoEncoder error";
      }
      this-&gt;traffic += packet.size;
  
      QByteArray data_frame = QByteArray((char*)packet.data, packet.size);
  
      av_frame_free(&amp;frame_source);
      av_frame_free(&amp;frame_dst);
      av_free_packet(&amp;packet);
  
      return data_frame;
  }
  </code></pre>
  
  <p>Thank you in advance!</p>