2 * compatibility macros to make every ffmpeg installation appear
3 * like the most current installation (wrapping some functionality sometimes)
4 * it also includes all ffmpeg header files at once, no need to do it
7 * Copyright (c) 2011 Peter Schlaile
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #ifndef __FFMPEG_COMPAT_H__
22 #define __FFMPEG_COMPAT_H__
24 #include <libavformat/avformat.h>
26 /* check our ffmpeg is new enough, avoids user complaints */
27 #if (LIBAVFORMAT_VERSION_MAJOR < 52) || ((LIBAVFORMAT_VERSION_MAJOR == 52) && (LIBAVFORMAT_VERSION_MINOR <= 64))
28 # error "FFmpeg 0.7 or newer is needed, Upgrade your FFmpeg or disable it"
30 /* end sanity check */
33 #include <libavcodec/avcodec.h>
34 #include <libavutil/rational.h>
35 #include <libavutil/opt.h>
36 #include <libavutil/mathematics.h>
38 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101))
39 #define FFMPEG_HAVE_PARSE_UTILS 1
40 #include <libavutil/parseutils.h>
43 #include <libswscale/swscale.h>
45 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 105))
46 #define FFMPEG_HAVE_AVIO 1
49 #if (LIBAVCODEC_VERSION_MAJOR > 53) || ((LIBAVCODEC_VERSION_MAJOR == 53) && (LIBAVCODEC_VERSION_MINOR > 1)) || ((LIBAVCODEC_VERSION_MAJOR == 53) && (LIBAVCODEC_VERSION_MINOR == 1) && (LIBAVCODEC_VERSION_MICRO >= 1)) || ((LIBAVCODEC_VERSION_MAJOR == 52) && (LIBAVCODEC_VERSION_MINOR >= 121))
50 #define FFMPEG_HAVE_DEFAULT_VAL_UNION 1
53 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101))
54 #define FFMPEG_HAVE_AV_DUMP_FORMAT 1
57 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 45))
58 #define FFMPEG_HAVE_AV_GUESS_FORMAT 1
61 #if (LIBAVCODEC_VERSION_MAJOR > 52) || ((LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 23))
62 #define FFMPEG_HAVE_DECODE_AUDIO3 1
63 #define FFMPEG_HAVE_DECODE_VIDEO2 1
66 #if (LIBAVCODEC_VERSION_MAJOR > 52) || ((LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 64))
67 #define FFMPEG_HAVE_AVMEDIA_TYPES 1
70 #if ((LIBAVCODEC_VERSION_MAJOR > 52) || (LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 29)) && \
71 ((LIBSWSCALE_VERSION_MAJOR > 0) || (LIBSWSCALE_VERSION_MAJOR >= 0) && (LIBSWSCALE_VERSION_MINOR >= 10))
72 #define FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
75 #if ((LIBAVUTIL_VERSION_MAJOR > 51) || (LIBAVUTIL_VERSION_MAJOR == 51) && (LIBAVUTIL_VERSION_MINOR >= 32))
76 #define FFMPEG_FFV1_ALPHA_SUPPORTED
79 #if ((LIBAVUTIL_VERSION_MAJOR < 51) || (LIBAVUTIL_VERSION_MAJOR == 51) && (LIBAVUTIL_VERSION_MINOR < 22))
81 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
83 const AVOption *rv = NULL;
84 av_set_string3(obj, name, val, 1, &rv);
89 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
91 const AVOption *rv = NULL;
92 rv = av_set_int(obj, name, val);
97 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
99 const AVOption *rv = NULL;
100 rv = av_set_double(obj, name, val);
104 #define AV_OPT_TYPE_INT FF_OPT_TYPE_INT
105 #define AV_OPT_TYPE_INT64 FF_OPT_TYPE_INT64
106 #define AV_OPT_TYPE_STRING FF_OPT_TYPE_STRING
107 #define AV_OPT_TYPE_CONST FF_OPT_TYPE_CONST
108 #define AV_OPT_TYPE_DOUBLE FF_OPT_TYPE_DOUBLE
109 #define AV_OPT_TYPE_FLOAT FF_OPT_TYPE_FLOAT
112 #if ((LIBAVFORMAT_VERSION_MAJOR < 53) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR < 24)) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR < 24) && (LIBAVFORMAT_VERSION_MICRO < 2)))
113 #define avformat_close_input(x) av_close_input_file(*(x))
116 #if ((LIBAVCODEC_VERSION_MAJOR < 53) || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR < 35))
118 int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
120 /* TODO: no options are taking into account */
121 return avcodec_open(avctx, codec);
125 #if ((LIBAVFORMAT_VERSION_MAJOR < 53) || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR < 21))
127 AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)
129 /* TODO: no codec is taking into account */
130 return av_new_stream(s, 0);
134 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
136 /* TODO: no options are taking into account */
137 return av_find_stream_info(ic);
141 #if ((LIBAVFORMAT_VERSION_MAJOR > 53) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR > 32)) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR == 24) && (LIBAVFORMAT_VERSION_MICRO >= 100)))
143 void my_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
147 for (i = 0; i < s->nb_streams; i++) {
148 AVStream *st = s->streams[i];
150 st->cur_dts = av_rescale(timestamp,
151 st->time_base.den * (int64_t)ref_st->time_base.num,
152 st->time_base.num * (int64_t)ref_st->time_base.den);
157 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
159 my_update_cur_dts(s, ref_st, timestamp);
163 #ifndef FFMPEG_HAVE_AVIO
164 #define AVIO_FLAG_WRITE URL_WRONLY
165 #define avio_open url_fopen
166 #define avio_tell url_ftell
167 #define avio_close url_fclose
168 #define avio_size url_fsize
171 /* there are some version inbetween, which have avio_... functions but no
173 #ifndef AVIO_FLAG_WRITE
174 #define AVIO_FLAG_WRITE URL_WRONLY
177 #ifndef AV_PKT_FLAG_KEY
178 #define AV_PKT_FLAG_KEY PKT_FLAG_KEY
181 #ifndef FFMPEG_HAVE_AV_DUMP_FORMAT
182 #define av_dump_format dump_format
185 #ifndef FFMPEG_HAVE_AV_GUESS_FORMAT
186 #define av_guess_format guess_format
189 #ifndef FFMPEG_HAVE_PARSE_UTILS
190 #define av_parse_video_rate av_parse_video_frame_rate
193 #ifdef FFMPEG_HAVE_DEFAULT_VAL_UNION
194 #define FFMPEG_DEF_OPT_VAL_INT(OPT) OPT->default_val.i64
195 #define FFMPEG_DEF_OPT_VAL_DOUBLE(OPT) OPT->default_val.dbl
197 #define FFMPEG_DEF_OPT_VAL_INT(OPT) OPT->default_val
198 #define FFMPEG_DEF_OPT_VAL_DOUBLE(OPT) OPT->default_val
201 #ifndef FFMPEG_HAVE_AVMEDIA_TYPES
202 #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
203 #define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
206 #ifndef FFMPEG_HAVE_DECODE_AUDIO3
208 int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
209 int *frame_size_ptr, AVPacket *avpkt)
211 return avcodec_decode_audio2(avctx, samples,
212 frame_size_ptr, avpkt->data,
217 #ifndef FFMPEG_HAVE_DECODE_VIDEO2
219 int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
220 int *got_picture_ptr,
223 return avcodec_decode_video(avctx, picture, got_picture_ptr,
224 avpkt->data, avpkt->size);
229 int64_t av_get_pts_from_frame(AVFormatContext *avctx, AVFrame * picture)
231 int64_t pts = picture->pkt_pts;
233 if (pts == AV_NOPTS_VALUE) {
234 pts = picture->pkt_dts;
236 if (pts == AV_NOPTS_VALUE) {