Skip to content

Commit

Permalink
Set frame properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Asd-g committed Oct 13, 2020
1 parent ddcf97c commit 30508c3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##### 1.1.0:
Set frame properties - _DurationNum, _DurationDen, _FieldBased, _AspectRatio, _GOPNumber, _GOPPosition, _GOPClosed, _EncodedFrameTop, _EncodedFrameBottom, _PictType, _Matrix, _QuantsAverage, _QuantsAverage, _QuantsMax.

##### 1.0.0:
Renamed the plugin and function to D2VSource.
4 changes: 2 additions & 2 deletions build/D2VSource.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<BufferSecurityCheck>false</BufferSecurityCheck>
<BufferSecurityCheck>true</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<FloatingPointModel>Precise</FloatingPointModel>
</ClCompile>
Expand All @@ -119,7 +119,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<BufferSecurityCheck>false</BufferSecurityCheck>
<BufferSecurityCheck>true</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<OpenMP>GenerateParallelCode</OpenMP>
</ClCompile>
Expand Down
56 changes: 56 additions & 0 deletions src/AVISynthAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ MPEG2Source::MPEG2Source(const char* d2v, int idct, bool showQ,
luminanceTable[i] = static_cast<uint8_t>(value);
}
}

has_at_least_v8 = true;
try { env->CheckVersion(8); }
catch (const AvisynthError&) { has_at_least_v8 = false; }
}


Expand Down Expand Up @@ -277,6 +281,58 @@ PVideoFrame __stdcall MPEG2Source::GetFrame(int n, IScriptEnvironment* env)
if (d.info != 0)
show_info(n, d, frame, vi, env);

if (has_at_least_v8)
{
AVSMap* props = env->getFramePropsRW(frame);

/* Sample duration */
env->propSetInt(props, "_DurationNum", d.VF_FrameRate_Num, 0);
env->propSetInt(props, "_DurationDen", d.VF_FrameRate_Den, 0);
/* BFF or TFF */
uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top);
if (raw < d.BadStartingFrames)
raw = d.BadStartingFrames;

uint32_t gop = 0;
do {
if (raw >= d.GOPList[gop].number)
if (raw < d.GOPList[static_cast<int64_t>(gop) + 1].number)
break;
} while (++gop < d.GOPList.size() - 1);

const auto& rgop = d.GOPList[gop];

int field_based = 0;
if (!rgop.progressive)
field_based = d.Field_Order == 1 ? 2 : 1;
env->propSetInt(props, "_FieldBased", field_based, 0);
/* AR */
env->propSetData(props, "_AspectRatio", d.Aspect_Ratio, *(d.Aspect_Ratio), 0);
/* GOP */
int64_t gop_number[2] = { gop, rgop.number };
env->propSetIntArray(props, "_GOPNumber", gop_number, 2);
env->propSetInt(props, "_GOPPosition", rgop.position, 0);

int closed_gop = rgop.closed ? 1 : 0;
env->propSetInt(props, "_GOPClosed", closed_gop, 0);
/* Encoded frame */
const auto& fn = d.FrameList[n];

env->propSetInt(props, "_EncodedFrameTop", fn.top, 0);
env->propSetInt(props, "_EncodedFrameBottom", fn.bottom, 0);
/* Picture type */
const auto& fraw = d.FrameList[raw];
const char* pct = fraw.pct == I_TYPE ? "I" : fraw.pct == B_TYPE ? "B" : "P";

env->propSetData(props, "_PictType", pct, 1, 0);
/* Matrix */
env->propSetInt(props, "_Matrix", rgop.matrix, 0);
/* Quants */
env->propSetInt(props, "_QuantsAverage", d.avgquant, 0);
env->propSetInt(props, "_QuantsMin", d.minquant, 0);
env->propSetInt(props, "_QuantsMax", d.maxquant, 0);
}

return frame;
}

Expand Down
1 change: 1 addition & 0 deletions src/AVISynthAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MPEG2Source: public IClip {
CMPEG2Decoder* decoder;
bool luminanceFlag;
uint8_t luminanceTable[256];
bool has_at_least_v8;

public:
MPEG2Source(const char* d2v, int idct, bool showQ, int _info, int _upConv, bool _i420, int iCC, IScriptEnvironment* env);
Expand Down
8 changes: 4 additions & 4 deletions src/d2vsource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <ntdef.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEVERSION 1,1,0,0
PRODUCTVERSION 1,1,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0x0L
FILEOS VOS__WINDOWS32
Expand All @@ -16,11 +16,11 @@ BEGIN
BEGIN
VALUE "Comments", "Modified DGDecode."
VALUE "FileDescription", "D2VSource for AviSynth 2.6 / AviSynth+"
VALUE "FileVersion", "1.0.0"
VALUE "FileVersion", "1.1.0"
VALUE "InternalName", "D2VSource"
VALUE "OriginalFilename", "D2VSource.dll"
VALUE "ProductName", "D2VSource"
VALUE "ProductVersion", "1.0.0"
VALUE "ProductVersion", "1.1.0"
END
END
BLOCK "VarFileInfo"
Expand Down

0 comments on commit 30508c3

Please sign in to comment.