Skip to content

Commit 64343d4

Browse files
committed
Используем Frame Properties "_SARNum" и "_SARDen" для вычисления dwPictAspectRatioX и dwPictAspectRatioY.
1 parent 6361af6 commit 64343d4

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

Source/AviSynthStream.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,15 @@ CAviSynthStream::CAviSynthStream(const WCHAR* name, CSource* pParent, HRESULT* p
157157
val_Int = m_ScriptEnvironment->propGetInt(&avsMap, keyName, 0, &err);
158158
if (!err) {
159159
streamInfo += fmt::format(L" = {}", val_Int);
160-
SetColorInfoFromFrameFrops(color_info, keyName, val_Int);
160+
if (strcmp(keyName, "_SARNum") == 0) {
161+
m_Sar.num = val_Int;
162+
}
163+
else if (strcmp(keyName, "_SARDen") == 0) {
164+
m_Sar.den = val_Int;
165+
}
166+
else {
167+
SetColorInfoFromFrameFrops(color_info, keyName, val_Int);
168+
}
161169
}
162170
break;
163171
case PROPTYPE_FLOAT:
@@ -186,7 +194,7 @@ CAviSynthStream::CAviSynthStream(const WCHAR* name, CSource* pParent, HRESULT* p
186194

187195
SetColorInfoFromVUIOptions(color_info, name);
188196
if (color_info && VInfo.IsYUV()) {
189-
ColorInfo = color_info | (AMCONTROL_USED | AMCONTROL_COLORINFO_PRESENT);
197+
m_ColorInfo = color_info | (AMCONTROL_USED | AMCONTROL_COLORINFO_PRESENT);
190198
}
191199

192200
DLog(streamInfo);
@@ -204,6 +212,7 @@ CAviSynthStream::CAviSynthStream(const WCHAR* name, CSource* pParent, HRESULT* p
204212
m_Pitch = m_Width * 4;
205213
m_PitchBuff = m_Pitch;
206214
m_BufferSize = m_PitchBuff * m_Height * m_Format.buffCoeff / 2;
215+
m_Sar = {};
207216

208217
m_fpsNum = 1;
209218
m_fpsDen = 1;
@@ -242,7 +251,17 @@ CAviSynthStream::CAviSynthStream(const WCHAR* name, CSource* pParent, HRESULT* p
242251
vih2->bmiHeader.biCompression = m_Format.fourcc;
243252
vih2->bmiHeader.biSizeImage = m_BufferSize;
244253

245-
vih2->dwControlFlags = ColorInfo;
254+
vih2->dwControlFlags = m_ColorInfo;
255+
256+
if (m_Sar.num && m_Sar.den && m_Sar.num < INT16_MAX && m_Sar.den < INT16_MAX) {
257+
auto parX = m_Sar.num * m_Width;
258+
auto parY = m_Sar.den * m_Height;
259+
const auto gcd = std::gcd(parX, parY);
260+
parX /= gcd;
261+
parY /= gcd;
262+
vih2->dwPictAspectRatioX = parX;
263+
vih2->dwPictAspectRatioY = parY;
264+
}
246265
}
247266

248267
*phr = hr;

Source/AviSynthStream.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) 2020 see Authors.txt
2+
* (C) 2020-2022 see Authors.txt
33
*
44
* This file is part of MPC-BE.
55
*
@@ -50,13 +50,18 @@ class CAviSynthStream
5050
BOOL m_bFlushing = FALSE;
5151

5252
FmtParams_t m_Format = {};
53-
UINT ColorInfo = 0;
5453
UINT m_Width = 0;
5554
UINT m_Height = 0;
5655
UINT m_Pitch = 0;
5756
UINT m_PitchBuff = 0;
5857
UINT m_BufferSize = 0;
5958

59+
UINT m_ColorInfo = 0;
60+
struct {
61+
int64_t num = 0;
62+
int64_t den = 0;
63+
} m_Sar;
64+
6065
int m_NumFrames = 0;
6166
unsigned m_fpsNum = 1;
6267
unsigned m_fpsDen = 1;

Source/VapourSynthStream.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,16 @@ CVapourSynthStream::CVapourSynthStream(const WCHAR* name, CSource* pParent, HRES
183183
val_Int = m_vsAPI->propGetInt(vsMap, keyName, 0, &err);
184184
if (!err) {
185185
streamInfo += fmt::format(L" = {}", val_Int);
186-
SetColorInfoFromFrameFrops(color_info, keyName, val_Int);
186+
streamInfo += fmt::format(L" = {}", val_Int);
187+
if (strcmp(keyName, "_SARNum") == 0) {
188+
m_Sar.num = val_Int;
189+
}
190+
else if (strcmp(keyName, "_SARDen") == 0) {
191+
m_Sar.den = val_Int;
192+
}
193+
else {
194+
SetColorInfoFromFrameFrops(color_info, keyName, val_Int);
195+
}
187196
}
188197
break;
189198
case ptFloat:
@@ -213,7 +222,7 @@ CVapourSynthStream::CVapourSynthStream(const WCHAR* name, CSource* pParent, HRES
213222

214223
SetColorInfoFromVUIOptions(color_info, name);
215224
if (color_info) {
216-
ColorInfo = color_info | (AMCONTROL_USED | AMCONTROL_COLORINFO_PRESENT);
225+
m_ColorInfo = color_info | (AMCONTROL_USED | AMCONTROL_COLORINFO_PRESENT);
217226
}
218227

219228
DLog(streamInfo);
@@ -232,6 +241,7 @@ CVapourSynthStream::CVapourSynthStream(const WCHAR* name, CSource* pParent, HRES
232241
m_Pitch = m_Width * 4;
233242
m_PitchBuff = m_Pitch;
234243
m_BufferSize = m_PitchBuff * m_Height * m_Format.buffCoeff / 2;
244+
m_Sar = {};
235245

236246
m_fpsNum = 1;
237247
m_fpsDen = 1;
@@ -270,7 +280,17 @@ CVapourSynthStream::CVapourSynthStream(const WCHAR* name, CSource* pParent, HRES
270280
vih2->bmiHeader.biCompression = m_Format.fourcc;
271281
vih2->bmiHeader.biSizeImage = m_BufferSize;
272282

273-
vih2->dwControlFlags = ColorInfo;
283+
vih2->dwControlFlags = m_ColorInfo;
284+
285+
if (m_Sar.num && m_Sar.den && m_Sar.num < INT16_MAX && m_Sar.den < INT16_MAX) {
286+
auto parX = m_Sar.num * m_Width;
287+
auto parY = m_Sar.den * m_Height;
288+
const auto gcd = std::gcd(parX, parY);
289+
parX /= gcd;
290+
parY /= gcd;
291+
vih2->dwPictAspectRatioX = parX;
292+
vih2->dwPictAspectRatioY = parY;
293+
}
274294
}
275295

276296
*phr = hr;

Source/VapourSynthStream.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) 2020 see Authors.txt
2+
* (C) 2020-2022 see Authors.txt
33
*
44
* This file is part of MPC-BE.
55
*
@@ -64,13 +64,18 @@ class CVapourSynthStream
6464
BOOL m_bFlushing = FALSE;
6565

6666
FmtParams_t m_Format = {};
67-
UINT ColorInfo = 0;
6867
UINT m_Width = 0;
6968
UINT m_Height = 0;
7069
UINT m_Pitch = 0;
7170
UINT m_PitchBuff = 0;
7271
UINT m_BufferSize = 0;
7372

73+
UINT m_ColorInfo = 0;
74+
struct {
75+
int64_t num = 0;
76+
int64_t den = 0;
77+
} m_Sar;
78+
7479
int m_NumFrames = 0;
7580
int64_t m_fpsNum = 1;
7681
int64_t m_fpsDen = 1;

0 commit comments

Comments
 (0)