forked from bartvdbraak/blender
Patch from Xavier Thomas, tweaks/fixes to FFMPEG YUV conversion code
This commit is contained in:
parent
fbf8287ed1
commit
7d98982295
@ -94,8 +94,13 @@
|
||||
#define FFMPEG_CODEC_IS_POINTER 1
|
||||
#endif
|
||||
|
||||
#if (LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 29) && \
|
||||
(LIBSWSCALE_VERSION_MAJOR >= 0) && (LIBSWSCALE_VERSION_MINOR >= 10)
|
||||
#define FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
|
||||
#endif
|
||||
|
||||
#endif //WITH_FFMPEG
|
||||
|
||||
#ifdef WITH_REDCODE
|
||||
#ifdef _WIN32 /* on windows we use the ones in extern instead */
|
||||
#include "libredcode/format.h"
|
||||
@ -520,6 +525,13 @@ static int startffmpeg(struct anim * anim) {
|
||||
AVFormatContext *pFormatCtx;
|
||||
AVCodecContext *pCodecCtx;
|
||||
|
||||
#ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
|
||||
/* The following for color space determination */
|
||||
int srcRange, dstRange, brightness, contrast, saturation;
|
||||
int *table;
|
||||
const int *inv_table;
|
||||
#endif
|
||||
|
||||
if (anim == 0) return(-1);
|
||||
|
||||
do_init_ffmpeg();
|
||||
@ -648,6 +660,25 @@ static int startffmpeg(struct anim * anim) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
|
||||
/* Try do detect if input has 0-255 YCbCR range (JFIF Jpeg MotionJpeg) */
|
||||
if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int**)&inv_table, &srcRange,
|
||||
&table, &dstRange, &brightness, &contrast, &saturation)) {
|
||||
|
||||
srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG;
|
||||
inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace);
|
||||
|
||||
if(sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange,
|
||||
table, dstRange, brightness, contrast, saturation)) {
|
||||
|
||||
printf("Warning: Could not set libswscale colorspace details.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Warning: Could not set libswscale colorspace details.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -659,27 +690,8 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
|
||||
int pos_found = 1;
|
||||
int filter_y = 0;
|
||||
|
||||
#if (LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 29) && \
|
||||
(LIBSWSCALE_VERSION_MAJOR >= 10) && (LIBSWSCALE_VERSION_MINOR >= 0)
|
||||
/* The following for color space determination */
|
||||
int srcRange, dstRange, brightness, contrast, saturation;
|
||||
int *inv_table, *table;
|
||||
|
||||
if (anim == 0) return (0);
|
||||
|
||||
/* The magic to assert we get full range for YUV to RGB, instead of
|
||||
mapping into 16-235 (only supported by newer ffmpeg versions) */
|
||||
if (!sws_getColorspaceDetails(anim->img_convert_ctx, &inv_table, &srcRange,
|
||||
&table, &dstRange, &brightness, &contrast, &saturation)) {
|
||||
srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG;
|
||||
inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace);
|
||||
sws_setColorspaceDetails(anim->img_convert_ctx, inv_table, srcRange,
|
||||
table, dstRange, brightness, contrast, saturation);
|
||||
}
|
||||
#else
|
||||
if (anim == 0) return (0);
|
||||
#endif
|
||||
|
||||
ibuf = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect, 0);
|
||||
|
||||
avpicture_fill((AVPicture*) anim->pFrameRGB,
|
||||
@ -801,7 +813,7 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
|
||||
unsigned char* top;
|
||||
|
||||
sws_scale(anim->img_convert_ctx,
|
||||
input->data,
|
||||
(const uint8_t * const *)input->data,
|
||||
input->linesize,
|
||||
0,
|
||||
anim->pCodecCtx->height,
|
||||
@ -860,7 +872,7 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
|
||||
unsigned char* r;
|
||||
|
||||
sws_scale(anim->img_convert_ctx,
|
||||
input->data,
|
||||
(const uint8_t * const *)input->data,
|
||||
input->linesize,
|
||||
0,
|
||||
anim->pCodecCtx->height,
|
||||
|
Loading…
Reference in New Issue
Block a user