<div dir="ltr">2017-02-27 11:02 GMT-05:00 Gustav González <span dir="ltr"><<a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a>></span>:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class="gmail-"><div class="gmail_quote">2017-02-27 4:30 GMT-05:00 Carl Eugen Hoyos <span dir="ltr"><<a href="mailto:ceffmpeg@gmail.com" target="_blank">ceffmpeg@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-m_-1229266541842708578gmail-">2017-02-27 4:13 GMT+01:00 Gustav González <<a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a>>:<br>
> I'm getting closer to create an animated GIF using a (Qt) QImage<br>
> array as input.<br>
<br>
</span>Since your sample code does not use the gif encoder, I don't see<br>
how it can lead to an animated gif as output file.<br></blockquote></div><br></span>So, the right way to ensure a functional animated GIF is using the<b> avcodec_encode_video2() </b>function to insert the frames?<span class="gmail-"><br><br>-- <br><div class="gmail-m_-1229266541842708578gmail_signature">============================<br> Gustav Gonzalez<br> <a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a><br>============================</div>
</span></div></div>
</blockquote></div><div class="gmail-content">
<p>Finally, I could create an animated GIF for the first time.
Nevertheless, I need to adjust the FPS parameter in some point because
the animation looks too slow. I am doing it from the <strong>AVCodecContext</strong> variable, like this:</p>
<pre class="gmail-markdown-highlight"><code class="gmail-hljs gmail-php"> int fps = <span class="gmail-hljs-number">24</span>;
AVCodecContext *c;
c->time_base.den = fps;
c->time_base.num = <span class="gmail-hljs-number">1</span>;
</code></pre>
<p>But anyway, it doesn't matter the value I set for the fps variable,
the result is always the same (slow). On the other hand, this is the
code I use to process every QImage object:</p>
<pre class="gmail-markdown-highlight"><code class="gmail-hljs gmail-objectivec"> <span class="gmail-hljs-keyword">int</span> got_packet = <span class="gmail-hljs-number">0</span>;
<span class="gmail-hljs-built_in">AVPacket</span> pkt;
av_init_packet(&pkt);
pkt.data = <span class="gmail-hljs-literal">NULL</span>; <span class="gmail-hljs-comment">// packet data will be allocated by the encoder</span>
pkt.size = <span class="gmail-hljs-number">0</span>;
QImage img = image.convertToFormat(Format_RGB888);
avpicture_fill((<span class="gmail-hljs-built_in">AVPicture</span> *)frame, img.bits(), <span class="gmail-hljs-built_in">AV_PIX_FMT_RGB24</span>, w, h);
<span class="gmail-hljs-keyword">int</span> ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
<span class="gmail-hljs-keyword">if</span> (ret < <span class="gmail-hljs-number">0</span>) {
tError() << <span class="gmail-hljs-string">"Error encoding video frame!"</span>;
<span class="gmail-hljs-keyword">return</span> <span class="gmail-hljs-literal">false</span>;
}
<span class="gmail-hljs-keyword">if</span> (got_packet) {
pkt.stream_index = video_st->index;
ret = av_interleaved_write_frame(oc, &pkt);
} <span class="gmail-hljs-keyword">else</span> {
ret = <span class="gmail-hljs-number">0</span>;
}
</code></pre>
<p>Any suggestion about how to fix the FPS issue? Thanks!<br></p>
</div></div><div class="gmail_extra">-- <br><div class="gmail_signature">============================<br> Gustav Gonzalez<br> <a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a><br>============================</div>
</div></div>