1
0
mirror of https://github.com/jojo61/vdr-plugin-softhdcuvid.git synced 2023-10-10 13:37:41 +02:00

Reworked the aspect function. Now we calculate the display aspect from the pixel width and

pixel height (and not from the physical size, which was the root cause for rounding errors).
Cropping calculation is reworking, now the rounding is correct. I introduce a new aspect mode
"original" which displays the output with the original size (but after correction the
pixel aspect ratio). Tested with vaapi(X11) and vaapi(DRM) with and without libplacebo.
This commit is contained in:
Dirk Nehring 2020-04-13 18:04:57 +02:00
parent 36c208967e
commit 23651104f2
8 changed files with 99 additions and 159 deletions

View File

@ -283,11 +283,13 @@ Setup: /etc/vdr/setup.conf
0 pan and scan 0 pan and scan
1 letter box 1 letter box
2 center cut-out 2 center cut-out
3 original
softhddevice.VideoOtherDisplayFormat = 1 softhddevice.VideoOtherDisplayFormat = 1
0 pan and scan 0 pan and scan
1 pillar box 1 pillar box
2 center cut-out 2 center cut-out
3 original
softhddevice.pip.X = 79 softhddevice.pip.X = 79
softhddevice.pip.Y = 78 softhddevice.pip.Y = 78
@ -378,6 +380,3 @@ Running:
Known Bugs: Known Bugs:
----------- -----------
SD Streams not working very well on vaapi SD Streams not working very well on vaapi

View File

@ -1,3 +1,4 @@
/* /*
* This file is part of mpv. * This file is part of mpv.
* *

View File

@ -1,3 +1,4 @@
/* /*
* This file is part of libplacebo. * This file is part of libplacebo.
* *

5
drm.c
View File

@ -475,9 +475,8 @@ void VideoInitDrm()
void get_drm_aspect(int *num,int *den) void get_drm_aspect(int *num,int *den)
{ {
Debug(3,"mmHeight %d mmWidth %d VideoHeight %d VideoWidth %d\n",render->mmHeight,render->mmWidth,VideoWindowHeight,VideoWindowWidth); *num = VideoWindowWidth;
*num = VideoWindowWidth * render->mmHeight; *den = VideoWindowHeight;
*den = VideoWindowHeight * render->mmWidth;
} }
struct gbm_bo *bo = NULL, *next_bo=NULL; struct gbm_bo *bo = NULL, *next_bo=NULL;

View File

@ -1,3 +1,4 @@
/* /*
* Copyright 1993-2013 NVIDIA Corporation. All rights reserved. * Copyright 1993-2013 NVIDIA Corporation. All rights reserved.
* *

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: VDR \n" "Project-Id-Version: VDR \n"
"Report-Msgid-Bugs-To: <see README>\n" "Report-Msgid-Bugs-To: <see README>\n"
"POT-Creation-Date: 2019-10-26 18:41+0200\n" "POT-Creation-Date: 2020-04-13 16:26+0200\n"
"PO-Revision-Date: blabla\n" "PO-Revision-Date: blabla\n"
"Last-Translator: blabla\n" "Last-Translator: blabla\n"
"Language-Team: blabla\n" "Language-Team: blabla\n"
@ -263,9 +263,6 @@ msgstr ""
msgid "codec: can't allocate video codec context\n" msgid "codec: can't allocate video codec context\n"
msgstr "" msgstr ""
msgid "VAAPI Refcounts invalid\n"
msgstr ""
msgid "codec: can't set option deint to video codec!\n" msgid "codec: can't set option deint to video codec!\n"
msgstr "" msgstr ""
@ -306,24 +303,6 @@ msgstr ""
msgid "codec/audio: decoded data smaller than encoded\n" msgid "codec/audio: decoded data smaller than encoded\n"
msgstr "" msgstr ""
msgid "codec/audio: resample setup error\n"
msgstr ""
msgid "codec/audio: overwrite resample\n"
msgstr ""
msgid "codec/audio: AvResample setup error\n"
msgstr ""
msgid "codec: latm\n"
msgstr ""
msgid "codec: error audio data\n"
msgstr ""
msgid "codec: error more than one frame data\n"
msgstr ""
msgid "codec/audio: can't setup resample\n" msgid "codec/audio: can't setup resample\n"
msgstr "" msgstr ""
@ -642,7 +621,7 @@ msgid " Frames missed(%d) duped(%d) dropped(%d) total(%d)"
msgstr " Frames verloren(%d) verdoppelt(%d) übersprungen(%d) Gesamt(%d)" msgstr " Frames verloren(%d) verdoppelt(%d) übersprungen(%d) Gesamt(%d)"
#, c-format #, c-format
msgid " Frame Process time %2.2fms" msgid " Video %dx%d Color: %s Gamma: %s"
msgstr "" msgstr ""
msgid "pass-through disabled" msgid "pass-through disabled"
@ -807,10 +786,6 @@ msgstr ""
msgid "video/glx: no GLX support\n" msgid "video/glx: no GLX support\n"
msgstr "" msgstr ""
#, c-format
msgid "video/glx: glx version %d.%d\n"
msgstr ""
msgid "did not get FBconfig" msgid "did not get FBconfig"
msgstr "" msgstr ""
@ -898,11 +873,10 @@ msgid "Failed rendering frame!\n"
msgstr "" msgstr ""
#, c-format #, c-format
msgid "video/vdpau: output buffer full, dropping frame (%d/%d)\n" msgid "video/cuvid: output buffer full, dropping frame (%d/%d)\n"
msgstr "" msgstr ""
#, c-format msgid "Could not dynamically load CUDA\n"
msgid "video/vdpau: pixel format %d not supported\n"
msgstr "" msgstr ""
msgid "Kein Cuda device gefunden" msgid "Kein Cuda device gefunden"
@ -943,12 +917,6 @@ msgstr ""
msgid "video/egl: can't create thread egl context\n" msgid "video/egl: can't create thread egl context\n"
msgstr "" msgstr ""
msgid "video: can't queue cancel video display thread\n"
msgstr ""
msgid "video: can't cancel video display thread\n"
msgstr ""
#, c-format #, c-format
msgid "video: repeated pict %d found, but not handled\n" msgid "video: repeated pict %d found, but not handled\n"
msgstr "" msgstr ""

View File

@ -1096,10 +1096,10 @@ void cMenuSetupSoft::Create(void)
"auto", "1920x1080", "1280x720", "custom", "auto", "1920x1080", "1280x720", "custom",
}; };
static const char *const video_display_formats_4_3[] = { static const char *const video_display_formats_4_3[] = {
"pan&scan", "letterbox", "center cut-out", "pan&scan", "letterbox", "center cut-out", "original"
}; };
static const char *const video_display_formats_16_9[] = { static const char *const video_display_formats_16_9[] = {
"pan&scan", "pillarbox", "center cut-out", "pan&scan", "pillarbox", "center cut-out", "original"
}; };
#ifdef YADIF #ifdef YADIF
static const char *const deinterlace[] = { static const char *const deinterlace[] = {
@ -1182,9 +1182,9 @@ void cMenuSetupSoft::Create(void)
Add(new cMenuEditBoolItem(tr("Enable Screensaver(DPMS) at black screen"), &EnableDPMSatBlackScreen, Add(new cMenuEditBoolItem(tr("Enable Screensaver(DPMS) at black screen"), &EnableDPMSatBlackScreen,
trVDR("no"), trVDR("yes"))); trVDR("no"), trVDR("yes")));
#endif #endif
Add(new cMenuEditStraItem(trVDR("4:3 video display format"), &Video4to3DisplayFormat, 3, Add(new cMenuEditStraItem(trVDR("4:3 video display format"), &Video4to3DisplayFormat, 4,
video_display_formats_4_3)); video_display_formats_4_3));
Add(new cMenuEditStraItem(trVDR("16:9+other video display format"), &VideoOtherDisplayFormat, 3, Add(new cMenuEditStraItem(trVDR("16:9+other video display format"), &VideoOtherDisplayFormat, 4,
video_display_formats_16_9)); video_display_formats_16_9));
#if 0 #if 0

125
video.c
View File

@ -253,7 +253,7 @@ typedef enum _video_zoom_modes_
VideoNormal, ///< normal VideoNormal, ///< normal
VideoStretch, ///< stretch to all edges VideoStretch, ///< stretch to all edges
VideoCenterCutOut, ///< center and cut out VideoCenterCutOut, ///< center and cut out
VideoAnamorphic, ///< anamorphic scaled (unsupported) VideoNone, ///< no scaling
} VideoZoomModes; } VideoZoomModes;
/// ///
@ -679,44 +679,35 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width, in
AVRational display_aspect_ratio; AVRational display_aspect_ratio;
AVRational tmp_ratio; AVRational tmp_ratio;
// input not initialized yet, return immediately
if (!input_aspect_ratio.num || !input_aspect_ratio.den) { if (!input_aspect_ratio.num || !input_aspect_ratio.den) {
input_aspect_ratio.num = 1; output_width = video_width;
input_aspect_ratio.den = 1; output_height = video_height;
Debug(3, "video: aspect defaults to %d:%d\n", input_aspect_ratio.num, input_aspect_ratio.den); return;
}
av_reduce(&input_aspect_ratio.num, &input_aspect_ratio.den, input_width * input_aspect_ratio.num,
input_height * input_aspect_ratio.den, 1024 * 1024);
// InputWidth/Height can be zero = uninitialized
if (!input_aspect_ratio.num || !input_aspect_ratio.den) {
input_aspect_ratio.num = 1;
input_aspect_ratio.den = 1;
} }
#ifdef USE_DRM #ifdef USE_DRM
get_drm_aspect(&display_aspect_ratio.num, &display_aspect_ratio.den); get_drm_aspect(&display_aspect_ratio.num, &display_aspect_ratio.den);
#else #else
Debug(3, "mmHeight %d mm Width %d VideoHeight %d VideoWidth %d\n", VideoScreen->height_in_millimeters, display_aspect_ratio.num = VideoScreen->width_in_pixels;
VideoScreen->width_in_millimeters, VideoScreen->height_in_pixels, VideoScreen->width_in_pixels); display_aspect_ratio.den = VideoScreen->height_in_pixels;
display_aspect_ratio.num = VideoScreen->width_in_pixels * VideoScreen->height_in_millimeters;
display_aspect_ratio.den = VideoScreen->height_in_pixels * VideoScreen->width_in_millimeters;
#endif #endif
display_aspect_ratio = av_mul_q(input_aspect_ratio, display_aspect_ratio); av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den,
Debug(3, "video: aspect %d:%d Resolution %d\n", display_aspect_ratio.num, display_aspect_ratio.den, resolution); 1024 * 1024);
Debug(3, "video: input %dx%d (%d:%d)\n", input_width, input_height, input_aspect_ratio.num,
input_aspect_ratio.den);
Debug(3, "video: display aspect %d:%d Resolution %d\n", display_aspect_ratio.num, display_aspect_ratio.den,
resolution);
Debug(3, "video: video %+d%+d %dx%d\n", video_x, video_y, video_width, video_height);
*crop_x = VideoCutLeftRight[resolution]; *crop_x = VideoCutLeftRight[resolution];
*crop_y = VideoCutTopBottom[resolution]; *crop_y = VideoCutTopBottom[resolution];
*crop_width = input_width - VideoCutLeftRight[resolution] * 2; *crop_width = input_width - VideoCutLeftRight[resolution] * 2;
*crop_height = input_height - VideoCutTopBottom[resolution] * 2; *crop_height = input_height - VideoCutTopBottom[resolution] * 2;
CuvidMessage(2, "video: crop to %+d%+d %dx%d\n", *crop_x, *crop_y, *crop_width, *crop_height);
// FIXME: store different positions for the ratios
tmp_ratio.num = 4; tmp_ratio.num = 4;
tmp_ratio.den = 3; tmp_ratio.den = 3;
#ifdef DEBUG
Debug(4, "ratio: %d:%d %d:%d\n", input_aspect_ratio.num, input_aspect_ratio.den, display_aspect_ratio.num,
display_aspect_ratio.den);
#endif
if (!av_cmp_q(input_aspect_ratio, tmp_ratio)) { if (!av_cmp_q(input_aspect_ratio, tmp_ratio)) {
switch (Video4to3ZoomMode) { switch (Video4to3ZoomMode) {
case VideoNormal: case VideoNormal:
@ -725,9 +716,8 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width, in
goto stretch; goto stretch;
case VideoCenterCutOut: case VideoCenterCutOut:
goto center_cut_out; goto center_cut_out;
case VideoAnamorphic: case VideoNone:
// FIXME: rest should be done by hardware goto video_none;
goto stretch;
} }
} }
switch (VideoOtherZoomMode) { switch (VideoOtherZoomMode) {
@ -737,28 +727,24 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width, in
goto stretch; goto stretch;
case VideoCenterCutOut: case VideoCenterCutOut:
goto center_cut_out; goto center_cut_out;
case VideoAnamorphic: case VideoNone:
// FIXME: rest should be done by hardware goto video_none;
goto stretch;
} }
normal: normal:
*output_x = video_x; *output_x = video_x;
*output_y = video_y; *output_y = video_y;
*output_width = *output_height = video_height;
(video_height * display_aspect_ratio.num + display_aspect_ratio.den - 1) / display_aspect_ratio.den; *output_width = (*crop_width * *output_height * input_aspect_ratio.num) / (input_aspect_ratio.den * *crop_height);
*output_height =
(video_width * display_aspect_ratio.den + display_aspect_ratio.num - 1) / display_aspect_ratio.num;
if (*output_width > video_width) { if (*output_width > video_width) {
*output_width = video_width; *output_width = video_width;
*output_height =
(*crop_height * *output_width * input_aspect_ratio.den) / (input_aspect_ratio.num * *crop_width);
*output_y += (video_height - *output_height) / 2; *output_y += (video_height - *output_height) / 2;
} else if (*output_height > video_height) { } else if (*output_width < video_width) {
*output_height = video_height;
*output_x += (video_width - *output_width) / 2; *output_x += (video_width - *output_width) / 2;
} }
CuvidMessage(2, "video: normal aspect output %dx%d%+d%+d\n", *output_width, *output_height, *output_x, *output_y);
CuvidMessage(2, "video: normal aspect output %dx%d%+d%+d Video %dx%d\n", *output_width, *output_height, *output_x,
*output_y, video_width, video_height);
return; return;
stretch: stretch:
@ -766,49 +752,34 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width, in
*output_y = video_y; *output_y = video_y;
*output_width = video_width; *output_width = video_width;
*output_height = video_height; *output_height = video_height;
Debug(3, "video: stretch output %dx%d%+d%+d\n", *output_width, *output_height, *output_x, *output_y); CuvidMessage(2, "video: stretch output %dx%d%+d%+d\n", *output_width, *output_height, *output_x, *output_y);
return; return;
center_cut_out: center_cut_out:
*output_x = video_x; *output_x = video_x;
*output_y = video_y; *output_y = video_y;
*output_height = video_height; *output_height = video_height;
*output_width = (*crop_width * *output_height * input_aspect_ratio.num) / (input_aspect_ratio.den * *crop_height);
if (*output_width > video_width) {
// fix height cropping
*crop_width = (int)((*crop_width * video_width) / (*output_width * 2.0) + 0.5) * 2;
*crop_x = (input_width - *crop_width) / 2;
*output_width = video_width;
} else if (*output_width < video_width) {
// fix width cropping
*crop_height = (int)((*crop_height * *output_width) / (video_width * 2.0) + 0.5) * 2;
*crop_y = (input_height - *crop_height) / 2;
*output_width = video_width; *output_width = video_width;
*crop_width = (video_height * display_aspect_ratio.num + display_aspect_ratio.den - 1) / display_aspect_ratio.den;
*crop_height = (video_width * display_aspect_ratio.den + display_aspect_ratio.num - 1) / display_aspect_ratio.num;
// look which side must be cut
if (*crop_width > video_width) {
int tmp;
*crop_height = input_height - VideoCutTopBottom[resolution] * 2;
// adjust scaling
tmp = ((*crop_width - video_width) * input_width) / (2 * video_width);
// FIXME: round failure?
if (tmp > *crop_x) {
*crop_x = tmp;
} }
*crop_width = input_width - *crop_x * 2; CuvidMessage(2, "video: aspect crop %dx%d%+d%+d\n", *crop_width, *crop_height, *crop_x, *crop_y);
} else if (*crop_height > video_height) { return;
int tmp;
*crop_width = input_width - VideoCutLeftRight[resolution] * 2; video_none:
*output_height = *crop_height;
// adjust scaling *output_width = (*crop_width * input_aspect_ratio.num) / input_aspect_ratio.den; // normalize pixel aspect ratio
tmp = ((*crop_height - video_height) * input_height) *output_x = video_x + (video_width - *output_width) / 2;
/ (2 * video_height); *output_y = video_y + (video_height - *output_height) / 2;
// FIXME: round failure? CuvidMessage(2, "video: original aspect output %dx%d%+d%+d\n", *output_width, *output_height, *output_x, *output_y);
if (tmp > *crop_y) {
*crop_y = tmp;
}
*crop_height = input_height - *crop_y * 2;
} else {
*crop_width = input_width - VideoCutLeftRight[resolution] * 2;
*crop_height = input_height - VideoCutTopBottom[resolution] * 2;
}
Debug(3, "video: aspect crop %dx%d%+d%+d\n", *crop_width, *crop_height, *crop_x, *crop_y);
return; return;
} }
@ -2649,7 +2620,7 @@ int init_filters(AVCodecContext * dec_ctx, CuvidDecoder * decoder, AVFrame * fra
enum AVPixelFormat format = PIXEL_FORMAT; enum AVPixelFormat format = PIXEL_FORMAT;
#ifdef VAAPI #ifdef VAAPI
const char *filters_descr = "deinterlace_vaapi=rate=field:auto=1"; // const char *filters_descr = "deinterlace_vaapi=rate=field:auto=1";
#endif #endif
#ifdef YADIF #ifdef YADIF
const char *filters_descr = "yadif_cuda=1:0:1"; // mode=send_field,parity=tff,deint=interlaced"; const char *filters_descr = "yadif_cuda=1:0:1"; // mode=send_field,parity=tff,deint=interlaced";
@ -6515,13 +6486,13 @@ void VideoSetDeinterlace(int mode[VideoResolutionMax])
VideoDeinterlace[1] = 1; //mode[1]; // 720p VideoDeinterlace[1] = 1; //mode[1]; // 720p
VideoDeinterlace[2] = mode[2]; // fake 1080 VideoDeinterlace[2] = mode[2]; // fake 1080
VideoDeinterlace[3] = mode[3]; // 1080 VideoDeinterlace[3] = mode[3]; // 1080
VideoDeinterlace[4] = 1, //mode[4]; 2160p VideoDeinterlace[4] = 1; //mode[4]; 2160p
#else #else
VideoDeinterlace[0] = 1; // 576i VideoDeinterlace[0] = 1; // 576i
VideoDeinterlace[1] = 0; //mode[1]; // 720p VideoDeinterlace[1] = 0; //mode[1]; // 720p
VideoDeinterlace[2] = 1; // fake 1080 VideoDeinterlace[2] = 1; // fake 1080
VideoDeinterlace[3] = 1; // 1080 VideoDeinterlace[3] = 1; // 1080
VideoDeinterlace[4] = 0, //mode[4]; 2160p VideoDeinterlace[4] = 0; //mode[4]; 2160p
#endif #endif
VideoSurfaceModesChanged = 1; VideoSurfaceModesChanged = 1;
} }