ffmpeg-compat.h (5338B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#ifndef GUACENC_FFMPEG_COMPAT_H 21#define GUACENC_FFMPEG_COMPAT_H 22 23#include "config.h" 24#include "video.h" 25 26#include <libavcodec/avcodec.h> 27 28/* 29 * For a full list of FFmpeg API changes over the years, see: 30 * 31 * https://github.com/FFmpeg/FFmpeg/blob/master/doc/APIchanges 32 */ 33 34/* For libavcodec < 55.28.1: av_frame_*() was avcodec_*_frame(). */ 35#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1) 36#define av_frame_alloc avcodec_alloc_frame 37#define av_frame_free avcodec_free_frame 38#endif 39 40/* For libavcodec < 54.28.0: old avcodec_free_frame() did not exist. */ 41#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,28,0) 42#define avcodec_free_frame av_freep 43#endif 44 45/* For libavcodec < 55.52.0: avcodec_free_context did not exist */ 46#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,52,0) 47#define avcodec_free_context av_freep 48#endif 49 50/* For libavcodec < 57.7.0: av_packet_unref() was av_free_packet() */ 51#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,7,0) 52#define av_packet_unref av_free_packet 53#endif 54 55/* For libavcodec <= 56.41.100: Global header flag didn't have AV_ prefix. 56 * Guacenc defines its own flag here to avoid conflicts with libavcodec 57 * macros. 58 */ 59#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(56,41,100) 60#define GUACENC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER 61#else 62#define GUACENC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER 63#endif 64 65/* For libavutil < 51.42.0: AV_PIX_FMT_* was PIX_FMT_* */ 66#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51,42,0) 67#define AV_PIX_FMT_RGB32 PIX_FMT_RGB32 68#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P 69#endif 70 71/** 72 * Writes the specied frame as a new frame of video. If pending frames of the 73 * video are being flushed, the given frame may be NULL (as required by 74 * avcodec_encode_video2()). If avcodec_encode_video2() does not exist, this 75 * function will transparently use avcodec_encode_video(). 76 * 77 * @param video 78 * The video to write the given frame to. 79 * 80 * @param frame 81 * The frame to write to the video, or NULL if previously-written frames 82 * are being flushed. 83 * 84 * @return 85 * A positive value if the frame was successfully written, zero if the 86 * frame has been saved for later writing / reordering, negative if an 87 * error occurs. 88 */ 89int guacenc_avcodec_encode_video(guacenc_video* video, AVFrame* frame); 90 91/** 92 * Creates and sets up the AVCodecContext for the appropriate version of 93 * libavformat installed. The AVCodecContext will be built, but the AVStream 94 * will also be affected by having its time_base field set to the value passed 95 * into this function. 96 * 97 * @param stream 98 * The open AVStream. 99 * 100 * @param codec 101 * The codec used on the AVStream. 102 * 103 * @param bitrate 104 * The target bitrate for the encoded video 105 * 106 * @param width 107 * The target width for the encoded video. 108 * 109 * @param height 110 * The target height for the encoded video. 111 * 112 * @param gop_size 113 * The size of the Group of Pictures. 114 * 115 * @param qmax 116 * The max value of the quantizer. 117 * 118 * @param qmin 119 * The min value of the quantizer. 120 * 121 * @param pix_fmt 122 * The target pixel format for the encoded video. 123 * 124 * @param time_base 125 * The target time base for the encoded video. 126 * 127 * @return 128 * The pointer to the configured AVCodecContext. 129 * 130 */ 131AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec, 132 int bitrate, int width, int height, int gop_size, int qmax, int qmin, 133 int pix_fmt, AVRational time_base); 134 135/** 136 * A wrapper for avcodec_open2(). Because libavformat ver 57.33.100 and greater 137 * use stream->codecpar rather than stream->codec to handle information to the 138 * codec, there needs to be an additional step in that version. So this 139 * wrapper handles that. Otherwise, it's the same as avcodec_open2(). 140 * 141 * @param avcodec_context 142 * The context to initialize. 143 * 144 * @param codec 145 * The codec to open this context for. If a non-NULL codec has been 146 * previously passed to avcodec_alloc_context3() or for this context, then 147 * this parameter MUST be either NULL or equal to the previously passed 148 * codec. 149 * 150 * @param options 151 * A dictionary filled with AVCodecContext and codec-private options. On 152 * return this object will be filled with options that were not found. 153 * 154 * @param stream 155 * The stream for the codec context. 156 * 157 * @return 158 * Zero on success, a negative value on error. 159 */ 160int guacenc_open_avcodec(AVCodecContext *avcodec_context, 161 AVCodec *codec, AVDictionary **options, 162 AVStream* stream); 163 164#endif 165