Commit d31e3f7c authored by Anton Khirnov's avatar Anton Khirnov

gif: add loop private option.

Deprecate AVFormatContext.loop_output.
parent 6002fdef
...@@ -723,12 +723,16 @@ typedef struct AVFormatContext { ...@@ -723,12 +723,16 @@ typedef struct AVFormatContext {
int preload; int preload;
int max_delay; int max_delay;
#if FF_API_LOOP_OUTPUT
#define AVFMT_NOOUTPUTLOOP -1 #define AVFMT_NOOUTPUTLOOP -1
#define AVFMT_INFINITEOUTPUTLOOP 0 #define AVFMT_INFINITEOUTPUTLOOP 0
/** /**
* number of times to loop output in formats that support it * number of times to loop output in formats that support it
*
* @deprecated use the 'loop' private option in the gif muxer.
*/ */
int loop_output; attribute_deprecated int loop_output;
#endif
int flags; int flags;
#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
*/ */
#include "avformat.h" #include "avformat.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
/* The GIF format uses reversed order for bitstreams... */ /* The GIF format uses reversed order for bitstreams... */
/* at least they don't use PDP_ENDIAN :) */ /* at least they don't use PDP_ENDIAN :) */
...@@ -245,8 +247,10 @@ static int gif_image_write_image(AVIOContext *pb, ...@@ -245,8 +247,10 @@ static int gif_image_write_image(AVIOContext *pb,
} }
typedef struct { typedef struct {
AVClass *class; /** Class for private options. */
int64_t time, file_time; int64_t time, file_time;
uint8_t buffer[100]; /* data chunks */ uint8_t buffer[100]; /* data chunks */
int loop;
} GIFContext; } GIFContext;
static int gif_write_header(AVFormatContext *s) static int gif_write_header(AVFormatContext *s)
...@@ -254,7 +258,7 @@ static int gif_write_header(AVFormatContext *s) ...@@ -254,7 +258,7 @@ static int gif_write_header(AVFormatContext *s)
GIFContext *gif = s->priv_data; GIFContext *gif = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
AVCodecContext *enc, *video_enc; AVCodecContext *enc, *video_enc;
int i, width, height, loop_count /*, rate*/; int i, width, height /*, rate*/;
/* XXX: do we reject audio streams or just ignore them ? /* XXX: do we reject audio streams or just ignore them ?
if(s->nb_streams > 1) if(s->nb_streams > 1)
...@@ -276,7 +280,6 @@ static int gif_write_header(AVFormatContext *s) ...@@ -276,7 +280,6 @@ static int gif_write_header(AVFormatContext *s)
} else { } else {
width = video_enc->width; width = video_enc->width;
height = video_enc->height; height = video_enc->height;
loop_count = s->loop_output;
// rate = video_enc->time_base.den; // rate = video_enc->time_base.den;
} }
...@@ -285,7 +288,12 @@ static int gif_write_header(AVFormatContext *s) ...@@ -285,7 +288,12 @@ static int gif_write_header(AVFormatContext *s)
return AVERROR(EIO); return AVERROR(EIO);
} }
gif_image_write_header(pb, width, height, loop_count, NULL); #if FF_API_LOOP_OUTPUT
if (s->loop_output)
gif->loop = s->loop_output;
#endif
gif_image_write_header(pb, width, height, gif->loop, NULL);
avio_flush(s->pb); avio_flush(s->pb);
return 0; return 0;
...@@ -340,6 +348,20 @@ static int gif_write_trailer(AVFormatContext *s) ...@@ -340,6 +348,20 @@ static int gif_write_trailer(AVFormatContext *s)
return 0; return 0;
} }
#define OFFSET(x) offsetof(GIFContext, x)
#define ENC AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{ "loop", "Number of times to loop the output.", OFFSET(loop), FF_OPT_TYPE_INT, {0}, 0, 65535, ENC },
{ NULL },
};
static const AVClass gif_muxer_class = {
.class_name = "GIF muxer",
.item_name = av_default_item_name,
.version = LIBAVUTIL_VERSION_INT,
.option = options,
};
AVOutputFormat ff_gif_muxer = { AVOutputFormat ff_gif_muxer = {
"gif", "gif",
NULL_IF_CONFIG_SMALL("GIF Animation"), NULL_IF_CONFIG_SMALL("GIF Animation"),
...@@ -351,4 +373,5 @@ AVOutputFormat ff_gif_muxer = { ...@@ -351,4 +373,5 @@ AVOutputFormat ff_gif_muxer = {
gif_write_header, gif_write_header,
gif_write_packet, gif_write_packet,
gif_write_trailer, gif_write_trailer,
.priv_class = &gif_muxer_class,
}; };
...@@ -80,5 +80,8 @@ ...@@ -80,5 +80,8 @@
#ifndef FF_API_LOOP_INPUT #ifndef FF_API_LOOP_INPUT
#define FF_API_LOOP_INPUT (LIBAVFORMAT_VERSION_MAJOR < 54) #define FF_API_LOOP_INPUT (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif #endif
#ifndef FF_API_LOOP_OUTPUT
#define FF_API_LOOP_OUTPUT (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
#endif /* AVFORMAT_VERSION_H */ #endif /* AVFORMAT_VERSION_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment