Aspect ratio issues with Vapoursynth

Support forum for DGDecNV
Post Reply
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

DGDecodeNV's output .dgi reports the aspect ratio as 1:1. MediaInfo and FFprobe report it as 16:9, as well as other Vapoursynth source filters. This is causing playback of the output encoded video to be stretched. Could this also be SAR/DAR being swapped/inverted? Because editing "ASPECT 1 1" to "ASPECT 16 9" fixes the issue and changes the Vapoursynth info:
With "ASPECT 1 1": vpy [info]: 1920x1080 fps 24000/1001 i420p8 sar 9:16 frames 0 - 93403 of 93404
With "ASPECT 16 9": vpy [info]: 1920x1080 fps 24000/1001 i420p8 sar 1:1 frames 0 - 93403 of 93404

From .dgi:
DEVICE 0
DECODE_MODES 0,0,0,0,0
STREAM 2 0
RANGE 0 0 18446744073709551615 0
DEMUX 2
DEPTH 8
ASPECT 1 1
COLORIMETRY 2 2 2
--Snip--
SIZ 1920 x 1088
DISP 0,1920,0,1080
FPS 24000 / 1001
CODED 93404
PLAYBACK 93404
0.00% FILM
ORDER 0

OS: W10 Pro 1909
GPU: GTX 1080 Ti
DGIndexNV: 2053.0.0.224
Vapoursynth: R52

FFprobe: Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)

MediaInfo:
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
User avatar
tormento
DG Approved/Moose Approved
Posts: 428
Joined: Mon Sep 20, 2010 2:18 pm

Incorrect reporting of aspect ratio

Post by tormento »

Vraelon wrote:
Mon Feb 01, 2021 4:03 pm
DGDecodeNV's output .dgi incorrectly reports the aspect ratio.
Are you sure it hasn't been encoded or muxed with SAR not equal to 1?

A chunk of the video would be glad.
User avatar
Bullwinkle
Moose Approved
Posts: 210
Joined: Thu Sep 05, 2019 6:37 pm

Incorrect reporting of aspect ratio

Post by Bullwinkle »

Post a link to the unprocessed source video and give a flow that shows incorrect display. Without that I cannot help you.

I do not know of any player that uses that field from the DGI to direct playback.

Be aware that 'Aspect ratio' in the DGI is not the same as either SAR or DAR in Vapoursynth. The Aspect ratio numbers are read directly from the stream, I do not make them up. I report them in the DGI for you. From the DGIndexNV user manual:
Aspect Ratio - Displays the aspect ratio specified in the MPEG stream. In brackets, the raw value of the aspect_ratio_information field is given. By appropriately interpreting the Frame Size, Display Size, and Aspect Ratio according to the MPEG2 video specification, the sample aspect ratio (SAR) and display aspect ratio (DAR) can be inferred.
I'm going to write a nice FAQ about all these things. The terms are used in different ways by different tools and applications. Just because they differ does not mean there is a bug anywhere.
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

Here is a trim of the source made with ffmpeg -vcodec copy, it has the same issue. https://www.mediafire.com/file/9w548b0m ... m.mkv/file

Output and Source:

Command:
C:\Users\PC\Desktop\Random\Util\StaxRip-2.1.7.0\Apps\Encoders\x265\x265.exe --crf 18 --preset slow --profile main10 --output-depth 10 --deblock 1:1 --no-sao --output "D:\Testing\Test trim_temp\Test trim_new_out.hevc" "D:\Testing\Test trim_temp\Test trim_new.vpy"

Test trim_new.vpy:
import os, sys
import vapoursynth as vs
core = vs.get_core()

sys.path.append(r"C:\Users\PC\Desktop\Random\Util\StaxRip-2.1.7.0\Apps\Plugins\VS\Scripts")
core.std.LoadPlugin(r"C:\Users\PC\Desktop\Random\Util\StaxRip-2.1.7.0\Settings\Plugins\Dual\DGDecNV\DGDecodeNV.dll")
clip = core.dgdecodenv.DGSource(r"D:\Testing\Test trim_temp\Test trim.dgi")
clip.set_output()

Test trim.dgi:
DGAVCIndexFileNV22 DGIndexNV 2053.0.0.224 X64
C:\Users\PC\Desktop\Random\Util\StaxRip-2.1.7.0\Settings\Plugins\Dual\DGDecNV\

D:\Testing\Test trim.mkv 21720294

DEVICE 0
DECODE_MODES 0,0,0,0,0
STREAM 2 0
RANGE 0 0 18446744073709551615 0
DEMUX
DEPTH 8
ASPECT 1 1
COLORIMETRY 2 2 2
---Snip---
SIZ 1920 x 1088
DISP 0,1920,0,1080
FPS 24000 / 1001
CODED 268
PLAYBACK 268
0.00% FILM
ORDER 0

Info:
vpy [info]: using VapourSynth Video Processing Library Core R52
vpy [info]: Video colorspace: YUV420 (YV12)
vpy [info]: Video depth: 8
vpy [info]: Video resolution: 1920x1080
vpy [info]: Video framerate: 24000/1001
vpy [info]: Video framecount: 267
vpy [info]: 1920x1080 fps 24000/1001 i420p8 sar 9:16 frames 0 - 266 of 267
vpy [info]: using 32 parallel requests
raw [info]: output file: D:\Testing\Test trim_temp\Test trim_new_out.hevc
x265 [info]: HEVC encoder version x265M 3.4+28-419182243
x265 [info]: build info [Windows][GCC 10.2.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 32 threads
User avatar
Bullwinkle
Moose Approved
Posts: 210
Joined: Thu Sep 05, 2019 6:37 pm

Aspect ratio issues with Vapoursynth

Post by Bullwinkle »

Could be an x265.exe issue. Please link me to the exact x265.exe that you use, preferably with github code link so I can see what they are doing. A similar thread is active at Doom9.
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

The binary is located in StaxRip-2.1.7.0\Apps\Encoders\x265 from https://github.com/staxrip/staxrip/rele ... -Stable.7z
User avatar
Curly
Moose Approved
Posts: 127
Joined: Sun Mar 15, 2020 11:05 am

Aspect ratio issues with Vapoursynth

Post by Curly »

PAR = DAR / SAR

= (display width / display_height) / (coded horizontal resolution / coded vertical resolution)

For PAR 1/1 must have DAR = SAR. Something is foobed up. Huh!
User avatar
Bullwinkle
Moose Approved
Posts: 210
Joined: Thu Sep 05, 2019 6:37 pm

Aspect ratio issues with Vapoursynth

Post by Bullwinkle »

Oh yeah. Only Rocky can figure this out.
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

So you were able to reproduce the issue?
User avatar
Bullwinkle
Moose Approved
Posts: 210
Joined: Thu Sep 05, 2019 6:37 pm

Aspect ratio issues with Vapoursynth

Post by Bullwinkle »

I reproduced it in my all-powerful Moose psyche. A thought experiment so profound that mere hoomins are incapable of grasping the divine significance. It is not that hoomins are stupid, or deficient, they are simply insufficiently evolved.

They say I am highly evolved. Moose level!
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

Issue solved in slipstream 225: viewtopic.php?p=13229#p13229
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Good to hear. Thank you for your testing and status update.

Back in action, guys! Trying out my wings...

Image
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

It appears to be back somehow, but slightly different this time.

From log, VS input from DGDecNV: "vpy [info]: 3840x2160 fps 60/1 i420p8 sar 16:9 frames 0 - 601 of 602"

Mediainfo of source: Display aspect ratio : 16:9
Mediainfo of output: Display aspect ratio : 3.161

The bug in slipstream 224 output Display aspect ratio : 1.000 and was vertically stretched with "vpy [info]"'s log entry stating "sar 9:16" input from DGDecNV, at least it isn't backwards anymore. With slipstream 225 now the output has Display aspect ratio : 3.161 and is stretched horizontally.
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Reproduced with a UHD bluray stream. Could be due to syntax differences between AVC and HEVC video. Investigating...
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Got it. Gonna fix it tomorrow maybe with an explanation.

So hard to be perfect. Fall short and they'll be taking X-rays.
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Here is a candidate fix for all the aspect ratio stuff. We were doing different things for the different video types. Also, the stream syntax elements differ for the different video types. This candidate fix revises all the video types so that: 1) the Info dialog shows the PAR (pixel aspect ratio), and 2) the PAR is given as ASPECT in the DGI. There is special handling to get the PAR correct for MPEG2 SD.

Please advise your test results and any related suggestions.

http://rationalqm.us/misc/DGIndexNV_vraelon.rar
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

The output encode now has the correct aspect ratio but in the log I see:
"vpy [info]: 3840x2160 fps 60/1 i420p8 sar 136:135 frames 0 - 601 of 602"
As well as in the .dgi: "ASPECT 136 135"
Shouldn't that be 1:1? It's very close but not exact.
With the first fix attempt (on the videos it worked with) it was 1:1 and the output encode's aspect ratio was correct.
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Please link an unprocessed source sample that behaves that way.

Please don't make me ask every time for a sample.
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

Sorry my upload speed is slow and now that I look closer at the output encode it is actually vertically squished slightly, even though MediaInfo says 16:9.

Source video: https://www.mediafire.com/file/7hqgsxss ... y.mkv/file

Thin black bars on top and bottom:
Image
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Thank you. Downloading... Next time a smaller sample will be preferred.
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Please re-download the fix candidate and retest. Things should be OK with your sample.
DAE avatar
Vraelon
Posts: 12
Joined: Sat Oct 26, 2019 1:29 am

Aspect ratio issues with Vapoursynth

Post by Vraelon »

It's fixed for that sample. Testing other media now, will edit when done.

Edit: Everything seems to output in it's proper aspect ratio, thanks :D
User avatar
Rocky
Moose Approved
Posts: 1814
Joined: Fri Sep 06, 2019 12:57 pm

Aspect ratio issues with Vapoursynth

Post by Rocky »

Thank you for your testing. I'll mark this resolved and make a slipstream after addressing tormento's cropping issue.
Post Reply