diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0af366d75..dc61e2e19 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -294,12 +294,17 @@ find_package(FFmpeg REQUIRED ) set(all_comps avcodec avformat avutil swscale) -if(TARGET FFmpeg::swresample) - list(APPEND all_comps swresample) +set(version_comps avcodec avformat avutil) + +# Pick a resampler. Prefer swresample if possible +if(TARGET FFmpeg::swresample AND ${FFmpeg_avformat_VERSION} VERSION_GREATER "57.0.0") + set(resample_lib swresample) + set(USE_SW TRUE) else() - list(APPEND all_comps avresample) + set(resample_lib avresample) + set(USE_SW FALSE) endif() -set(version_comps avcodec avformat avutil) +list(APPEND all_comps ${resample_lib}) foreach(ff_comp IN LISTS all_comps) if(TARGET FFmpeg::${ff_comp}) @@ -313,9 +318,15 @@ foreach(ff_comp IN LISTS all_comps) endif() endforeach() +# Indicate which resampler we linked with, and set a config header flag +add_feature_info("FFmpeg ${resample_lib}" TRUE "Audio resampling uses ${resample_lib}") +# Set the appropriate flag in OpenShotVersion.h +set(FFMPEG_USE_SWRESAMPLE ${USE_SW} CACHE BOOL "libswresample used for audio resampling" FORCE) +mark_as_advanced(FFMPEG_USE_SWRESAMPLE) + # Version check for hardware-acceleration code if(USE_HW_ACCEL AND FFmpeg_avcodec_VERSION) - if(${FFmpeg_avcodec_VERSION} VERSION_GREATER "57.107.100") + if(${FFmpeg_avcodec_VERSION} VERSION_GREATER "57.106") set(HAVE_HW_ACCEL TRUE) endif() endif() diff --git a/src/FFmpegUtilities.h b/src/FFmpegUtilities.h index fe46a212e..d8b1587fb 100644 --- a/src/FFmpegUtilities.h +++ b/src/FFmpegUtilities.h @@ -31,269 +31,302 @@ #ifndef OPENSHOT_FFMPEG_UTILITIES_H #define OPENSHOT_FFMPEG_UTILITIES_H - // Required for libavformat to build on Windows - #ifndef INT64_C - #define INT64_C(c) (c ## LL) - #define UINT64_C(c) (c ## ULL) - #endif +#include "OpenShotVersion.h" // For FFMPEG_USE_SWRESAMPLE - #ifndef IS_FFMPEG_3_2 - #define IS_FFMPEG_3_2 (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 64, 101)) - #endif +// Required for libavformat to build on Windows +#ifndef INT64_C +#define INT64_C(c) (c ## LL) +#define UINT64_C(c) (c ## ULL) +#endif - #ifndef USE_HW_ACCEL - #define USE_HW_ACCEL (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 107, 100)) - #endif +#ifndef IS_FFMPEG_3_2 +#define IS_FFMPEG_3_2 (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 64, 101)) +#endif - // Include the FFmpeg headers - extern "C" { - #include - #include - #if (LIBAVFORMAT_VERSION_MAJOR >= 57) - #include //PM - #endif - #include - // Change this to the first version swrescale works - #if (LIBAVFORMAT_VERSION_MAJOR >= 57) - #define USE_SW - #endif - #ifdef USE_SW - #include - #else - #include - #endif - #include - #include - #include +#ifndef USE_HW_ACCEL +#define USE_HW_ACCEL (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 107, 100)) +#endif - // libavutil changed folders at some point - #if LIBAVFORMAT_VERSION_MAJOR >= 53 - #include - #else - #include - #endif +#ifndef USE_SW +#define USE_SW FFMPEG_USE_SWRESAMPLE +#endif - // channel header refactored - #if LIBAVFORMAT_VERSION_MAJOR >= 54 - #include - #endif +// Include the FFmpeg headers +extern "C" { + #include + #include - #if IS_FFMPEG_3_2 - #include "libavutil/imgutils.h" - #endif - } +#if (LIBAVFORMAT_VERSION_MAJOR >= 57) + #include //PM +#endif + #include - // This was removed from newer versions of FFmpeg (but still used in libopenshot) - #ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE - #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio - #endif - #ifndef AV_ERROR_MAX_STRING_SIZE - #define AV_ERROR_MAX_STRING_SIZE 64 - #endif - #ifndef AUDIO_PACKET_ENCODING_SIZE - #define AUDIO_PACKET_ENCODING_SIZE 768000 // 48khz * S16 (2 bytes) * max channels (8) - #endif +#if USE_SW + #include +#else + #include +#endif - // This wraps an unsafe C macro to be C++ compatible function - inline static const std::string av_make_error_string(int errnum) - { - char errbuf[AV_ERROR_MAX_STRING_SIZE]; - av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE); - return (std::string)errbuf; - } + #include + #include + #include - // Redefine the C macro to use our new C++ function - #undef av_err2str - #define av_err2str(errnum) av_make_error_string(errnum).c_str() + // libavutil changed folders at some point +#if LIBAVFORMAT_VERSION_MAJOR >= 53 + #include +#else + #include +#endif - // Define this for compatibility - #ifndef PixelFormat - #define PixelFormat AVPixelFormat - #endif - #ifndef PIX_FMT_RGBA - #define PIX_FMT_RGBA AV_PIX_FMT_RGBA - #endif - #ifndef PIX_FMT_NONE - #define PIX_FMT_NONE AV_PIX_FMT_NONE - #endif - #ifndef PIX_FMT_RGB24 - #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24 - #endif - #ifndef PIX_FMT_YUV420P - #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P - #endif - #ifndef PIX_FMT_YUV444P - #define PIX_FMT_YUV444P AV_PIX_FMT_YUV444P - #endif + // channel header refactored +#if LIBAVFORMAT_VERSION_MAJOR >= 54 + #include +#endif - // Does ffmpeg pixel format contain an alpha channel? - inline static const bool ffmpeg_has_alpha(PixelFormat pix_fmt) { - const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(pix_fmt); - return bool(fmt_desc->flags & AV_PIX_FMT_FLAG_ALPHA); - } +#if IS_FFMPEG_3_2 + #include "libavutil/imgutils.h" +#endif +} - // FFmpeg's libavutil/common.h defines an RSHIFT incompatible with Ruby's - // definition in ruby/config.h, so we move it to FF_RSHIFT - #ifdef RSHIFT - #define FF_RSHIFT(a, b) RSHIFT(a, b) - #undef RSHIFT - #endif +// This was removed from newer versions of FFmpeg (but still used in libopenshot) +#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE + // 1 second of 48khz 32bit audio + #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 +#endif +#ifndef AV_ERROR_MAX_STRING_SIZE + #define AV_ERROR_MAX_STRING_SIZE 64 +#endif +#ifndef AUDIO_PACKET_ENCODING_SIZE + // 48khz * S16 (2 bytes) * max channels (8) + #define AUDIO_PACKET_ENCODING_SIZE 768000 +#endif - #ifdef USE_SW - #define SWR_CONVERT(ctx, out, linesize, out_count, in, linesize2, in_count) \ - swr_convert(ctx, out, out_count, (const uint8_t **)in, in_count) - #define SWR_ALLOC() swr_alloc() - #define SWR_CLOSE(ctx) {} - #define SWR_FREE(ctx) swr_free(ctx) - #define SWR_INIT(ctx) swr_init(ctx) - #define SWRCONTEXT SwrContext - #else - #define SWR_CONVERT(ctx, out, linesize, out_count, in, linesize2, in_count) \ - avresample_convert(ctx, out, linesize, out_count, (uint8_t **)in, linesize2, in_count) - #define SWR_ALLOC() avresample_alloc_context() - #define SWR_CLOSE(ctx) avresample_close(ctx) - #define SWR_FREE(ctx) avresample_free(ctx) - #define SWR_INIT(ctx) avresample_open(ctx) - #define SWRCONTEXT AVAudioResampleContext - #endif +// This wraps an unsafe C macro to be C++ compatible function +inline static const std::string av_make_error_string(int errnum) +{ + char errbuf[AV_ERROR_MAX_STRING_SIZE]; + av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE); + return (std::string)errbuf; +} +// Redefine the C macro to use our new C++ function +#undef av_err2str +#define av_err2str(errnum) av_make_error_string(errnum).c_str() - #if (LIBAVFORMAT_VERSION_MAJOR >= 58) - #define AV_REGISTER_ALL - #define AVCODEC_REGISTER_ALL - #define AV_FILENAME url - #define AV_SET_FILENAME(oc, f) oc->AV_FILENAME = av_strdup(f) - #define MY_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE - #define AV_ALLOCATE_FRAME() av_frame_alloc() - #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) - #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) - #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) - #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) - #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) - #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type - #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codecpar->codec_id - #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) \ - ({ AVCodecContext *context = avcodec_alloc_context3(av_codec); \ - avcodec_parameters_to_context(context, av_stream->codecpar); \ - context; }) - #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_codec; - #define AV_GET_CODEC_FROM_STREAM(av_stream,codec_in) - #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_stream->codecpar - #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) (AVPixelFormat) av_stream->codecpar->format - #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_stream->codecpar->format - #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) av_image_get_buffer_size(pix_fmt, width, height, 1) - #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) - #define AV_OUTPUT_CONTEXT(output_context, path) avformat_alloc_output_context2( output_context, NULL, NULL, path) - #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) - #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); - #define AV_FORMAT_NEW_STREAM(oc, st_codec_ctx, av_codec, av_st) av_st = avformat_new_stream(oc, NULL);\ - if (!av_st) \ - throw OutOfMemory("Could not allocate memory for the video stream.", path); \ - c = avcodec_alloc_context3(av_codec); \ - st_codec_ctx = c; \ - av_st->codecpar->codec_id = av_codec->id; - #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec_ctx) avcodec_parameters_from_context(av_stream->codecpar, av_codec_ctx); - #elif IS_FFMPEG_3_2 - #define AV_REGISTER_ALL av_register_all(); - #define AVCODEC_REGISTER_ALL avcodec_register_all(); - #define AV_FILENAME filename - #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) - #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE - #define AV_ALLOCATE_FRAME() av_frame_alloc() - #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) - #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) - #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) - #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) - #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) - #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type - #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codecpar->codec_id - #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) \ - ({ AVCodecContext *context = avcodec_alloc_context3(av_codec); \ - avcodec_parameters_to_context(context, av_stream->codecpar); \ - context; }) - #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_codec; - #define AV_GET_CODEC_FROM_STREAM(av_stream,codec_in) - #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_stream->codecpar - #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) (AVPixelFormat) av_stream->codecpar->format - #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_stream->codecpar->format - #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) av_image_get_buffer_size(pix_fmt, width, height, 1) - #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) - #define AV_OUTPUT_CONTEXT(output_context, path) avformat_alloc_output_context2( output_context, NULL, NULL, path) - #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) - #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); - #define AV_FORMAT_NEW_STREAM(oc, st_codec, av_codec, av_st) av_st = avformat_new_stream(oc, NULL);\ - if (!av_st) \ - throw OutOfMemory("Could not allocate memory for the video stream.", path); \ - _Pragma ("GCC diagnostic push"); \ - _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\""); \ - avcodec_get_context_defaults3(av_st->codec, av_codec); \ - c = av_st->codec; \ - _Pragma ("GCC diagnostic pop"); \ - st_codec = c; - #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) avcodec_parameters_from_context(av_stream->codecpar, av_codec); - #elif LIBAVFORMAT_VERSION_MAJOR >= 55 - #define AV_REGISTER_ALL av_register_all(); - #define AVCODEC_REGISTER_ALL avcodec_register_all(); - #define AV_FILENAME filename - #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) - #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE - #define AV_ALLOCATE_FRAME() av_frame_alloc() - #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) - #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) - #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) - #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) - #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) - #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type - #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codec->codec_id - #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) av_stream->codec - #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_stream->codec - #define AV_GET_CODEC_FROM_STREAM(av_stream, codec_in) codec_in = av_stream->codec; - #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_context - #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) av_context->pix_fmt - #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_context->sample_fmt - #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) avpicture_get_size(pix_fmt, width, height) - #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) avpicture_fill((AVPicture *) av_frame, buffer, pix_fmt, width, height) - #define AV_OUTPUT_CONTEXT(output_context, path) oc = avformat_alloc_context() - #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) - #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) av_opt_set (priv_data, name, value, 0) - #define AV_FORMAT_NEW_STREAM( oc, av_context, av_codec, av_st) av_st = avformat_new_stream(oc, av_codec); \ - if (!av_st) \ - throw OutOfMemory("Could not allocate memory for the video stream.", path); \ - avcodec_get_context_defaults3(av_st->codec, av_codec); \ - c = av_st->codec; - #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) - #else - #define AV_REGISTER_ALL av_register_all(); - #define AVCODEC_REGISTER_ALL avcodec_register_all(); - #define AV_FILENAME filename - #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) - #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE - #define AV_ALLOCATE_FRAME() avcodec_alloc_frame() - #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) - #define AV_RESET_FRAME(av_frame) avcodec_get_frame_defaults(av_frame) - #define AV_FREE_FRAME(av_frame) avcodec_free_frame(av_frame) - #define AV_FREE_PACKET(av_packet) av_free_packet(av_packet) - #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) - #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type - #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codec->codec_id - #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) av_stream->codec - #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_stream->codec - #define AV_GET_CODEC_FROM_STREAM(av_stream, codec_in ) codec_in = av_stream->codec; - #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_context - #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) av_context->pix_fmt - #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_context->sample_fmt - #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) avpicture_get_size(pix_fmt, width, height) - #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) avpicture_fill((AVPicture *) av_frame, buffer, pix_fmt, width, height) - #define AV_OUTPUT_CONTEXT(output_context, path) oc = avformat_alloc_context() - #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) - #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) av_opt_set (priv_data, name, value, 0) - #define AV_FORMAT_NEW_STREAM( oc, av_context, av_codec, av_st) av_st = avformat_new_stream(oc, av_codec); \ - if (!av_st) \ - throw OutOfMemory("Could not allocate memory for the video stream.", path); \ - avcodec_get_context_defaults3(av_st->codec, av_codec); \ - c = av_st->codec; - #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) - #endif +// Define this for compatibility +#ifndef PixelFormat + #define PixelFormat AVPixelFormat +#endif +#ifndef PIX_FMT_RGBA + #define PIX_FMT_RGBA AV_PIX_FMT_RGBA +#endif +#ifndef PIX_FMT_NONE + #define PIX_FMT_NONE AV_PIX_FMT_NONE +#endif +#ifndef PIX_FMT_RGB24 + #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24 +#endif +#ifndef PIX_FMT_YUV420P + #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P +#endif +#ifndef PIX_FMT_YUV444P + #define PIX_FMT_YUV444P AV_PIX_FMT_YUV444P +#endif + +// Does ffmpeg pixel format contain an alpha channel? +inline static const bool ffmpeg_has_alpha(PixelFormat pix_fmt) { + const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(pix_fmt); + return bool(fmt_desc->flags & AV_PIX_FMT_FLAG_ALPHA); +} + +// FFmpeg's libavutil/common.h defines an RSHIFT incompatible with Ruby's +// definition in ruby/config.h, so we move it to FF_RSHIFT +#ifdef RSHIFT + #define FF_RSHIFT(a, b) RSHIFT(a, b) + #undef RSHIFT +#endif + +// libswresample/libavresample API switching +#if USE_SW + #define SWR_CONVERT(ctx, out, linesize, out_count, in, linesize2, in_count) \ + swr_convert(ctx, out, out_count, (const uint8_t **)in, in_count) + #define SWR_ALLOC() swr_alloc() + #define SWR_CLOSE(ctx) {} + #define SWR_FREE(ctx) swr_free(ctx) + #define SWR_INIT(ctx) swr_init(ctx) + #define SWRCONTEXT SwrContext +#else + #define SWR_CONVERT(ctx, out, linesize, out_count, in, linesize2, in_count) \ + avresample_convert(ctx, out, linesize, out_count, (uint8_t **)in, linesize2, in_count) + #define SWR_ALLOC() avresample_alloc_context() + #define SWR_CLOSE(ctx) avresample_close(ctx) + #define SWR_FREE(ctx) avresample_free(ctx) + #define SWR_INIT(ctx) avresample_open(ctx) + #define SWRCONTEXT AVAudioResampleContext +#endif + + +#if (LIBAVFORMAT_VERSION_MAJOR >= 58) + #define AV_REGISTER_ALL + #define AVCODEC_REGISTER_ALL + #define AV_FILENAME url + #define AV_SET_FILENAME(oc, f) oc->AV_FILENAME = av_strdup(f) + #define MY_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE + #define AV_ALLOCATE_FRAME() av_frame_alloc() + #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) \ + av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) + #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) + #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) + #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) + #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) + #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type + #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codecpar->codec_id + #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) \ + ({ AVCodecContext *context = avcodec_alloc_context3(av_codec); \ + avcodec_parameters_to_context(context, av_stream->codecpar); \ + context; }) + #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_codec; + #define AV_GET_CODEC_FROM_STREAM(av_stream,codec_in) + #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_stream->codecpar + #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) (AVPixelFormat) av_stream->codecpar->format + #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_stream->codecpar->format + #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) \ + av_image_get_buffer_size(pix_fmt, width, height, 1) + #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) + #define AV_OUTPUT_CONTEXT(output_context, path) avformat_alloc_output_context2( output_context, NULL, NULL, path) + #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) + #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); + #define AV_FORMAT_NEW_STREAM(oc, st_codec_ctx, av_codec, av_st) \ + av_st = avformat_new_stream(oc, NULL);\ + if (!av_st) \ + throw OutOfMemory("Could not allocate memory for the video stream.", path); \ + c = avcodec_alloc_context3(av_codec); \ + st_codec_ctx = c; \ + av_st->codecpar->codec_id = av_codec->id; + #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec_ctx) \ + avcodec_parameters_from_context(av_stream->codecpar, av_codec_ctx); + +#elif IS_FFMPEG_3_2 + #define AV_REGISTER_ALL av_register_all(); + #define AVCODEC_REGISTER_ALL avcodec_register_all(); + #define AV_FILENAME filename + #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) + #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE + #define AV_ALLOCATE_FRAME() av_frame_alloc() + #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) \ + av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) + #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) + #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) + #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) + #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) + #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type + #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codecpar->codec_id + #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) \ + ({ AVCodecContext *context = avcodec_alloc_context3(av_codec); \ + avcodec_parameters_to_context(context, av_stream->codecpar); \ + context; }) + #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_codec; + #define AV_GET_CODEC_FROM_STREAM(av_stream,codec_in) + #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_stream->codecpar + #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) \ + (AVPixelFormat) av_stream->codecpar->format + #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_stream->codecpar->format + #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) av_image_get_buffer_size(pix_fmt, width, height, 1) + #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) + #define AV_OUTPUT_CONTEXT(output_context, path) \ + avformat_alloc_output_context2( output_context, NULL, NULL, path) + #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) + #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); + #define AV_FORMAT_NEW_STREAM(oc, st_codec, av_codec, av_st) \ + av_st = avformat_new_stream(oc, NULL);\ + if (!av_st) \ + throw OutOfMemory("Could not allocate memory for the video stream.", path); \ + _Pragma ("GCC diagnostic push"); \ + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\""); \ + avcodec_get_context_defaults3(av_st->codec, av_codec); \ + c = av_st->codec; \ + _Pragma ("GCC diagnostic pop"); \ + st_codec = c; + #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) \ + avcodec_parameters_from_context(av_stream->codecpar, av_codec); +#elif LIBAVFORMAT_VERSION_MAJOR >= 55 + #define AV_REGISTER_ALL av_register_all(); + #define AVCODEC_REGISTER_ALL avcodec_register_all(); + #define AV_FILENAME filename + #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) + #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE + #define AV_ALLOCATE_FRAME() av_frame_alloc() + #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) \ + avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) + #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) + #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) + #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) + #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) + #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type + #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codec->codec_id + #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) av_stream->codec + #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_stream->codec + #define AV_GET_CODEC_FROM_STREAM(av_stream, codec_in) codec_in = av_stream->codec; + #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_context + #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) av_context->pix_fmt + #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_context->sample_fmt + #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) avpicture_get_size(pix_fmt, width, height) + #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) \ + avpicture_fill((AVPicture *) av_frame, buffer, pix_fmt, width, height) + #define AV_OUTPUT_CONTEXT(output_context, path) oc = avformat_alloc_context() + #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) + #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) av_opt_set (priv_data, name, value, 0) + #define AV_FORMAT_NEW_STREAM( oc, av_context, av_codec, av_st) \ + av_st = avformat_new_stream(oc, av_codec); \ + if (!av_st) \ + throw OutOfMemory("Could not allocate memory for the video stream.", path); \ + avcodec_get_context_defaults3(av_st->codec, av_codec); \ + c = av_st->codec; + #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) + +#else + #define AV_REGISTER_ALL av_register_all(); + #define AVCODEC_REGISTER_ALL avcodec_register_all(); + #define AV_FILENAME filename + #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) + #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE + #define AV_ALLOCATE_FRAME() avcodec_alloc_frame() + #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) \ + avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) + #define AV_RESET_FRAME(av_frame) avcodec_get_frame_defaults(av_frame) + #define AV_FREE_FRAME(av_frame) avcodec_free_frame(av_frame) + #define AV_FREE_PACKET(av_packet) av_free_packet(av_packet) + #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) + #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type + #define AV_FIND_DECODER_CODEC_ID(av_stream) av_stream->codec->codec_id + #define AV_GET_CODEC_CONTEXT(av_stream, av_codec) av_stream->codec + #define AV_GET_CODEC_PAR_CONTEXT(av_stream, av_codec) av_stream->codec + #define AV_GET_CODEC_FROM_STREAM(av_stream, codec_in ) codec_in = av_stream->codec; + #define AV_GET_CODEC_ATTRIBUTES(av_stream, av_context) av_context + #define AV_GET_CODEC_PIXEL_FORMAT(av_stream, av_context) av_context->pix_fmt + #define AV_GET_SAMPLE_FORMAT(av_stream, av_context) av_context->sample_fmt + #define AV_GET_IMAGE_SIZE(pix_fmt, width, height) avpicture_get_size(pix_fmt, width, height) + #define AV_COPY_PICTURE_DATA(av_frame, buffer, pix_fmt, width, height) \ + avpicture_fill((AVPicture *) av_frame, buffer, pix_fmt, width, height) + #define AV_OUTPUT_CONTEXT(output_context, path) oc = avformat_alloc_context() + #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, NULL, 0, 0) + #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) av_opt_set (priv_data, name, value, 0) + #define AV_FORMAT_NEW_STREAM( oc, av_context, av_codec, av_st) \ + av_st = avformat_new_stream(oc, av_codec); \ + if (!av_st) \ + throw OutOfMemory("Could not allocate memory for the video stream.", path); \ + avcodec_get_context_defaults3(av_st->codec, av_codec); \ + c = av_st->codec; + #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) #endif + + +#endif // OPENSHOT_FFMPEG_UTILITIES_H diff --git a/src/OpenShotVersion.h.in b/src/OpenShotVersion.h.in index 197242d39..b6f418909 100644 --- a/src/OpenShotVersion.h.in +++ b/src/OpenShotVersion.h.in @@ -51,6 +51,7 @@ #cmakedefine01 HAVE_IMAGEMAGICK #cmakedefine01 HAVE_RESVG #cmakedefine01 HAVE_OPENCV +#cmakedefine01 FFMPEG_USE_SWRESAMPLE #cmakedefine01 APPIMAGE_BUILD #include