Changeset View
Changeset View
Standalone View
Standalone View
intern/ffmpeg/ffmpeg_compat.h
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101)) | #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101)) | ||||
| # define FFMPEG_HAVE_PARSE_UTILS 1 | # define FFMPEG_HAVE_PARSE_UTILS 1 | ||||
| # include <libavutil/parseutils.h> | # include <libavutil/parseutils.h> | ||||
| #endif | #endif | ||||
| #include <libswscale/swscale.h> | #include <libswscale/swscale.h> | ||||
| /* Stupid way to distinguish FFmpeg from Libav: | |||||
| * - FFmpeg's MICRO version starts from 100 and goes up, while | |||||
| * - Libav's micro is always below 100. | |||||
| */ | |||||
| #if LIBAVCODEC_VERSION_MICRO >= 100 | |||||
| # define AV_USING_FFMPEG | |||||
| #else | |||||
| # define AV_USING_LIBAV | |||||
mont29: I’d expect this to be `AV_USING_LIBAV` ? | |||||
| #endif | |||||
| #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 105)) | #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 105)) | ||||
| # define FFMPEG_HAVE_AVIO 1 | # define FFMPEG_HAVE_AVIO 1 | ||||
| #endif | #endif | ||||
| #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)) | #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)) | ||||
| # define FFMPEG_HAVE_DEFAULT_VAL_UNION 1 | # define FFMPEG_HAVE_DEFAULT_VAL_UNION 1 | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 364 Lines • ▼ Show 20 Lines | |||||
| FFMPEG_INLINE | FFMPEG_INLINE | ||||
| void av_frame_free(AVFrame **frame) | void av_frame_free(AVFrame **frame) | ||||
| { | { | ||||
| av_freep(frame); | av_freep(frame); | ||||
| } | } | ||||
| #endif | #endif | ||||
| FFMPEG_INLINE | FFMPEG_INLINE | ||||
| AVRational av_get_r_frame_rate_compat(const AVStream *stream) | const char* av_get_metadata_key_value(AVDictionary *metadata, const char *key) | ||||
| { | |||||
| if (metadata == NULL) { | |||||
| return NULL; | |||||
| } | |||||
| AVDictionaryEntry *tag = NULL; | |||||
| while ((tag = av_dict_get(metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { | |||||
| if (!strcmp(tag->key, key)) { | |||||
| return tag->value; | |||||
| } | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| FFMPEG_INLINE | |||||
| bool av_check_encoded_with_ffmpeg(AVFormatContext *ctx) | |||||
| { | { | ||||
| const char* encoder = av_get_metadata_key_value(ctx->metadata, "ENCODER"); | |||||
| if (encoder != NULL && !strncmp(encoder, "Lavf", 4)) { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| FFMPEG_INLINE | |||||
| AVRational av_get_r_frame_rate_compat(AVFormatContext *ctx, | |||||
| const AVStream *stream) | |||||
| { | |||||
| /* If the video is encoded with FFmpeg and we are decoding with FFmpeg | |||||
| * as well it seems to be more reliable to use r_frame_rate (tbr). | |||||
| * | |||||
| * For other cases we fall back to avg_frame_rate (fps) when possible. | |||||
Not Done Inline Actions"fall back", not "toll back", I assume? mont29: "fall back", not "toll back", I assume? | |||||
| */ | |||||
| #ifdef AV_USING_FFMPEG | |||||
| if (av_check_encoded_with_ffmpeg(ctx)) { | |||||
| return stream->r_frame_rate; | |||||
| } | |||||
| #endif | |||||
| #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 23, 1) | #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 23, 1) | ||||
| /* For until r_frame_rate was deprecated use it. */ | /* For until r_frame_rate was deprecated use it. */ | ||||
| return stream->r_frame_rate; | return stream->r_frame_rate; | ||||
| #else | #else | ||||
| return stream->avg_frame_rate; | return stream->avg_frame_rate; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines | |||||
I’d expect this to be AV_USING_LIBAV ?