ffmpeg: restore compatibility with pre-5.0 versions
Only do threaded sws_scale_frame when using ffmpeg 5.0 or later. On earlier versions continue using the single threaded path. Pull Request: https://projects.blender.org/blender/blender/pulls/116226
This commit is contained in:
parent
13148cdf39
commit
5eb5712329
@ -16,6 +16,7 @@
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libswscale/swscale.h>
|
||||
|
||||
/* Check if our ffmpeg is new enough, avoids user complaints.
|
||||
* Minimum supported version is currently 3.2.0 which mean the following library versions:
|
||||
@ -46,6 +47,11 @@
|
||||
# define FFMPEG_USE_OLD_CHANNEL_VARS
|
||||
#endif
|
||||
|
||||
/* Threaded sws_scale_frame was added in ffmpeg 5.0 (swscale version 6.1). */
|
||||
#if (LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(6, 1, 100))
|
||||
# define FFMPEG_SWSCALE_THREADING
|
||||
#endif
|
||||
|
||||
/* AV_CODEC_CAP_AUTO_THREADS was renamed to AV_CODEC_CAP_OTHER_THREADS with
|
||||
* upstream commit
|
||||
* github.com/FFmpeg/FFmpeg/commit/7d09579190def3ef7562399489e628f3b65714ce
|
||||
|
@ -420,8 +420,17 @@ static AVFrame *generate_video_frame(FFMpegContext *context, const uint8_t *pixe
|
||||
/* Convert to the output pixel format, if it's different that Blender's internal one. */
|
||||
if (context->img_convert_frame != nullptr) {
|
||||
BLI_assert(context->img_convert_ctx != NULL);
|
||||
/* Note: `sws_scale` is single threaded, have to use `sws_scale_frame` instead. */
|
||||
# if defined(FFMPEG_SWSCALE_THREADING)
|
||||
sws_scale_frame(context->img_convert_ctx, context->current_frame, rgb_frame);
|
||||
# else
|
||||
sws_scale(context->img_convert_ctx,
|
||||
(const uint8_t *const *)rgb_frame->data,
|
||||
rgb_frame->linesize,
|
||||
0,
|
||||
codec->height,
|
||||
context->current_frame->data,
|
||||
context->current_frame->linesize);
|
||||
# endif
|
||||
}
|
||||
|
||||
return context->current_frame;
|
||||
@ -673,6 +682,7 @@ static SwsContext *get_threaded_sws_context(int width,
|
||||
AVPixelFormat src_format,
|
||||
AVPixelFormat dst_format)
|
||||
{
|
||||
# if defined(FFMPEG_SWSCALE_THREADING)
|
||||
/* sws_getContext does not allow passing flags that ask for multi-threaded
|
||||
* scaling context, so do it the hard way. */
|
||||
SwsContext *c = sws_alloc_context();
|
||||
@ -692,6 +702,18 @@ static SwsContext *get_threaded_sws_context(int width,
|
||||
sws_freeContext(c);
|
||||
return nullptr;
|
||||
}
|
||||
# else
|
||||
SwsContext *c = sws_getContext(width,
|
||||
height,
|
||||
src_format,
|
||||
width,
|
||||
height,
|
||||
dst_format,
|
||||
SWS_BICUBIC,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr);
|
||||
# endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user