28 #ifndef OPENSHOT_FFMPEG_UTILITIES_H 29 #define OPENSHOT_FFMPEG_UTILITIES_H 33 #define INT64_C(c) (c ## LL) 34 #define UINT64_C(c) (c ## ULL) 38 #define IS_FFMPEG_3_2 (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 64, 101)) 43 #include <libavcodec/avcodec.h> 44 #include <libavformat/avformat.h> 45 #include <libswscale/swscale.h> 46 #include <libavresample/avresample.h> 47 #include <libavutil/mathematics.h> 48 #include <libavutil/pixfmt.h> 49 #include <libavutil/pixdesc.h> 52 #if LIBAVFORMAT_VERSION_MAJOR >= 53 53 #include <libavutil/opt.h> 55 #include <libavcodec/opt.h> 59 #if LIBAVFORMAT_VERSION_MAJOR >= 54 60 #include <libavutil/channel_layout.h> 64 #include "libavutil/imgutils.h" 69 #ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE 70 #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio 72 #ifndef AV_ERROR_MAX_STRING_SIZE 73 #define AV_ERROR_MAX_STRING_SIZE 64 75 #ifndef AUDIO_PACKET_ENCODING_SIZE 76 #define AUDIO_PACKET_ENCODING_SIZE 768000 // 48khz * S16 (2 bytes) * max channels (8) 80 static const std::string av_make_error_string(
int errnum)
84 std::string errstring(errbuf);
90 #define av_err2str(errnum) av_make_error_string(errnum).c_str() 94 #define PixelFormat AVPixelFormat 97 #define PIX_FMT_RGBA AV_PIX_FMT_RGBA 100 #define PIX_FMT_NONE AV_PIX_FMT_NONE 102 #ifndef PIX_FMT_RGB24 103 #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24 105 #ifndef PIX_FMT_YUV420P 106 #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P 110 #define AV_ALLOCATE_FRAME() av_frame_alloc() 111 #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) 112 #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) 113 #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) 114 #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) 115 #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) 116 #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type 117 #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codecpar->codec_id 119 AVCodecContext *context = avcodec_alloc_context3(av_codec); \
120 avcodec_parameters_to_context(context, av_stream->codecpar); \
123 #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_codec; 124 #define AV_GET_CODEC_FROM_STREAM(av_stream,codec_in) 125 #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_stream->codecpar 126 #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) (AVPixelFormat) av_stream->codecpar->format 127 #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_stream->codecpar->format 128 #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) av_image_get_buffer_size(pix_fmt, width, height, 1) 129 #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) av_image_fill_arrays(av_frame->data, av_frame->linesize, buffer, pix_fmt, width, height, 1) 130 #define AV_OUTPUT_CONTEXT(output_context, path) avformat_alloc_output_context2( output_context, NULL, NULL, path) 131 #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) 132 #define AV_OPTION_SET( av_stream, priv_data, name, value, avcodec) av_opt_set(priv_data, name, value, 0); avcodec_parameters_from_context(av_stream->codecpar, avcodec); 133 #define AV_FORMAT_NEW_STREAM(oc, st_codec, av_codec, av_st) av_st = avformat_new_stream(oc, NULL);\ 135 throw OutOfMemory("Could not allocate memory for the video stream.", path); \ 136 c = avcodec_alloc_context3(av_codec); \ 138 av_st->codecpar->codec_id = av_codec->id; 139 #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) avcodec_parameters_from_context(av_stream->codecpar, av_codec); 140 #elif LIBAVFORMAT_VERSION_MAJOR >= 55 141 #define AV_ALLOCATE_FRAME() av_frame_alloc() 142 #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) 143 #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) 144 #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) 145 #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) 146 #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) 147 #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type 148 #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codec->codec_id 149 #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) av_stream->codec 150 #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_stream->codec 151 #define AV_GET_CODEC_FROM_STREAM(av_stream, codec_in) codec_in = av_stream->codec; 152 #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_context 153 #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) av_context->pix_fmt 154 #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_context->sample_fmt 155 #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) avpicture_get_size(pix_fmt, width, height) 156 #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) avpicture_fill((AVPicture *) av_frame, buffer, pix_fmt, width, height) 157 #define AV_OUTPUT_CONTEXT(output_context, path) oc = avformat_alloc_context() 158 #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) 159 #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) av_opt_set (priv_data, name, value, 0) 160 #define AV_FORMAT_NEW_STREAM( oc, av_context, av_codec, av_st) av_st = avformat_new_stream(oc, av_codec); \ 162 throw OutOfMemory("Could not allocate memory for the video stream.", path); \ 163 avcodec_get_context_defaults3(av_st->codec, av_codec); \ 165 #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) 167 #define AV_ALLOCATE_FRAME() avcodec_alloc_frame() 168 #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) 169 #define AV_RESET_FRAME(av_frame) avcodec_get_frame_defaults(av_frame) 170 #define AV_FREE_FRAME(av_frame) avcodec_free_frame(av_frame) 171 #define AV_FREE_PACKET(av_packet) av_free_packet(av_packet) 172 #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) 173 #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type 174 #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codec->codec_id 175 #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) av_stream->codec 176 #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_stream->codec 177 #define AV_GET_CODEC_FROM_STREAM(av_stream, codec_in ) codec_in = av_stream->codec; 178 #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_context 179 #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) av_context->pix_fmt 180 #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_context->sample_fmt 181 #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) avpicture_get_size(pix_fmt, width, height) 182 #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) avpicture_fill((AVPicture *) av_frame, buffer, pix_fmt, width, height) 183 #define AV_OUTPUT_CONTEXT(output_context, path) oc = avformat_alloc_context() 184 #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) 185 #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) av_opt_set (priv_data, name, value, 0) 186 #define AV_FORMAT_NEW_STREAM( oc, av_context, av_codec, av_st) av_st = avformat_new_stream(oc, av_codec); \ 188 throw OutOfMemory("Could not allocate memory for the video stream.", path); \ 189 avcodec_get_context_defaults3(av_st->codec, av_codec); \ 191 #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) #define AV_ERROR_MAX_STRING_SIZE
auto AV_GET_CODEC_CONTEXT