Skip to content

Commit

Permalink
Update to 1.3.0; close #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Asd-g committed May 15, 2022
1 parent a4b690e commit 3bbe326
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
##### 1.3.0:
Changed `_SARDen`, `_SARNum` to display MPEG-4 PAR. (videoh)
Changed `_AspectRatio` type to array int.

##### 1.2.6:
Restored previous behavior of frame property `_FieldBased`.
Fixed frame properties `_DurationNum` and `_DurationDen`.
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ This is a project (previously named as MPEG2DecPlus) to modify DGDecode.dll for

### Exported variables:

FFSAR_NUM, FFSAR_DEN, FFSAR.
FFSAR_NUM, FFSAR_DEN, FFSAR (these indicate Generic PAR).

### Frame properties

_AbsoluteTime [float]\
The frame’s absolute timestamp in seconds.

_AspectRatio [data]\
A string giving the display aspect ratio.
_AspectRatio [int]\
An array giving the display aspect ratio.

_ChromaLocation [int]\
Chroma sample position in YUV formats:
Expand Down Expand Up @@ -148,6 +148,14 @@ The minimum quantizer value for the frame.
_RFF [int]\
If _FieldOperation is 2 (ignore pulldown) then _RFF describes whether the stream specifies that a repeat field operation is to be performed on this frame. If _FieldOperation is 0 (honor pulldown) or 1 (force film) then _RFF describes whether the frame was composed with field repetition.

_SARDen [int]
The denominator of the "pixel size" (MPEG-4 PAR), also called the\
Sample Aspect Ratio (SAR).

_SARNum [int]
The numerator of the "pixel size" (MPEG-4 PAR), also called the\
Sample Aspect Ratio (SAR).

_TFF [int]\
If _FieldOperation is 2 (ignore pulldown) and _RFF is set, then _TFF\
describes whether the stream specifies that the top field is to be repeated, otherwise the bottom field is to be repeated. If _FieldOperation is 0 (honor pulldown) or 1 (force film) then _TFF is inapplicable and is set to -1.
Expand Down
2 changes: 1 addition & 1 deletion msvc/D2VSource.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>C:\Users\asdq\Downloads\AviSynthPlus\avs_core\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\AviSynthPlus\avs_core\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
85 changes: 80 additions & 5 deletions src/AVISynthAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ D2VSource::D2VSource(const char* d2v, int idct, bool showQ,
}


unsigned int gcd(unsigned int a, unsigned int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}


bool __stdcall D2VSource::GetParity(int)
{
return decoder->Field_Order == 1;
Expand Down Expand Up @@ -367,11 +375,78 @@ PVideoFrame __stdcall D2VSource::GetFrame(int n, IScriptEnvironment* env)
env->propSetInt(props, "_FieldBased", field_based, 0);
env->propSetInt(props, "_FieldOrder", d.Field_Order, 0);
/* AR */
env->propSetData(props, "_AspectRatio", d.Aspect_Ratio, strlen(d.Aspect_Ratio), 0);
unsigned int sar_num, sar_den;
static_cast<void>(sscanf(d.Aspect_Ratio, "%d:%d", &sar_num, &sar_den));
env->propSetInt(props, "_SARNum", sar_num, 0);
env->propSetInt(props, "_SARDen", sar_den, 0);
int64_t dar[2];
static_cast<void>(sscanf(d.Aspect_Ratio, "%lld:%lld", &dar[0], &dar[1]));
env->propSetIntArray(props, "_AspectRatio", dar, 2);

auto par_num = 0;
auto par_den = 0;
if (d.D2V_Height > 576)
{
// HD. Use PAR 1:1.
par_num = 1;
par_den = 1;
}
else
{
// SD. We have 4 cases.
if (d.aspect_ratio_information == 2 && d.D2V_Height == 480)
{
par_num = 10;
par_den = 11;
}
else if (d.aspect_ratio_information == 2 && d.D2V_Height == 576)
{
par_num = 12;
par_den = 11;
}
else if (d.aspect_ratio_information == 3 && d.D2V_Height == 480)
{
par_num = 40;
par_den = 33;
}
else if (d.aspect_ratio_information == 3 && d.D2V_Height == 576)
{
par_num = 16;
par_den = 11;
}
else
{
// Not a standard SD case. Calculate the PAR.
switch (d.aspect_ratio_information)
{
case 0:
par_num = 0;
par_den = 0;
break;
case 1:
par_num = 1;
par_den = 1;
break;
case 2:
par_num = 4 * d.D2V_Height;
par_den = 3 * d.D2V_Width;
break;
case 3:
par_num = 16 * d.D2V_Height;
par_den = 9 * d.D2V_Width;
break;
case 4:
par_num = 221 * d.D2V_Height;
par_den = 100 * d.D2V_Width;
break;
default:
par_num = 0;
par_den = 0;
break;
}
int divisor = gcd(par_num, par_den);
par_num /= divisor;
par_den /= divisor;
}
}
env->propSetInt(props, "_SARNum", par_num, 0);
env->propSetInt(props, "_SARDen", par_den, 0);
/* GOP */
int64_t gop_number[2] = { gop, rgop.number };
env->propSetIntArray(props, "_GOPNumber", gop_number, 2);
Expand Down
2 changes: 1 addition & 1 deletion src/MPEG2Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class CMPEG2Decoder
uint32_t VF_FrameRate_Num;
uint32_t VF_FrameRate_Den;

int horizontal_size, vertical_size, mb_width, mb_height;
int horizontal_size, vertical_size, mb_width, mb_height, aspect_ratio_information;
//int iPP;
int iCC;
bool showQ;
Expand Down
8 changes: 4 additions & 4 deletions src/d2vsource.rc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <winver.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,6,0
PRODUCTVERSION 1,2,6,0
FILEVERSION 1,3,0,0
PRODUCTVERSION 1,3,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0x0L
FILEOS VOS__WINDOWS32
Expand All @@ -15,11 +15,11 @@ BEGIN
BEGIN
VALUE "Comments", "Modified DGDecode."
VALUE "FileDescription", "D2VSource for AviSynth 2.6 / AviSynth+"
VALUE "FileVersion", "1.2.6"
VALUE "FileVersion", "1.3.0"
VALUE "InternalName", "D2VSource"
VALUE "OriginalFilename", "D2VSource.dll"
VALUE "ProductName", "D2VSource"
VALUE "ProductVersion", "1.2.6"
VALUE "ProductVersion", "1.3.0"
END
END
BLOCK "VarFileInfo"
Expand Down
5 changes: 2 additions & 3 deletions src/gethdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,15 @@ void CMPEG2Decoder::Sequence_Header()

horizontal_size = Get_Bits(12);
vertical_size = Get_Bits(12);
aspect_ratio_information = Get_Bits(4);
#if 0
Get_Bits(4); //aspect_ratio_information
Get_Bits(4); //frame_rate_code
Get_Bits(18); //bit_rate_value
Flush_Buffer(1); // marker bit
Get_Bits(10); //vbv_buffer_size
Get_Bits(1); //constrained_parameters_flag
#else
Flush_Buffer(32);
Flush_Buffer(6);
Flush_Buffer(34);
#endif

if ((load_intra_quantizer_matrix = Get_Bits(1)))
Expand Down

0 comments on commit 3bbe326

Please sign in to comment.