+ GIFContext *gif = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ AVCodecContext *enc, *video_enc;
+ int i, width, height, loop_count /*, rate*/;
+
+/* XXX: do we reject audio streams or just ignore them ?
+ if(s->nb_streams > 1)
+ return -1;
+*/
+ gif->time = 0;
+ gif->file_time = 0;
+
+ video_enc = NULL;
+ for(i=0;i<s->nb_streams;i++) {
+ enc = s->streams[i]->codec;
+ if (enc->codec_type != CODEC_TYPE_AUDIO)
+ video_enc = enc;
+ }
+
+ if (!video_enc) {
+ av_free(gif);
+ return -1;
+ } else {
+ width = video_enc->width;
+ height = video_enc->height;
+ loop_count = s->loop_output;
+// rate = video_enc->time_base.den;
+ }
+
+ if (video_enc->pix_fmt != PIX_FMT_RGB24) {
+ av_log(s, AV_LOG_ERROR, "ERROR: gif only handles the rgb24 pixel format. Use -pix_fmt rgb24.\n");
+ return AVERROR(EIO);
+ }
+
+ gif_image_write_header(pb, width, height, loop_count, NULL);
+
+ put_flush_packet(s->pb);
+ return 0;
+}
+
+static int gif_write_video(AVFormatContext *s,
+ AVCodecContext *enc, const uint8_t *buf, int size)
+{
+ ByteIOContext *pb = s->pb;
+ GIFContext *gif = s->priv_data;
+ int jiffies;
+ int64_t delay;
+
+ /* graphic control extension block */
+ put_byte(pb, 0x21);
+ put_byte(pb, 0xf9);
+ put_byte(pb, 0x04); /* block size */
+ put_byte(pb, 0x04); /* flags */
+
+ /* 1 jiffy is 1/70 s */
+ /* the delay_time field indicates the number of jiffies - 1 */
+ delay = gif->file_time - gif->time;
+
+ /* XXX: should use delay, in order to be more accurate */
+ /* instead of using the same rounded value each time */
+ /* XXX: don't even remember if I really use it for now */
+ jiffies = (70*enc->time_base.num/enc->time_base.den) - 1;
+
+ put_le16(pb, jiffies);
+
+ put_byte(pb, 0x1f); /* transparent color index */
+ put_byte(pb, 0x00);
+
+ gif_image_write_image(pb, 0, 0, enc->width, enc->height,
+ buf, enc->width * 3, PIX_FMT_RGB24);
+
+ put_flush_packet(s->pb);
+ return 0;
+}
+
+static int gif_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVCodecContext *codec = s->streams[pkt->stream_index]->codec;