MPEG Transport Streams and Program Streams usually contain time stamp information with regard to the currently decoding frame. The PTS clock frequency is 90 khz. The binary representation of the PTS is a bit weird though.
Here is a tiny snippet which will convert a PTS inside a PES packet into a .NET TimeSpan type.
public static TimeSpan DecodePTS( byte data, Int32 start )
Int64 pts = data[ start + 0 ] & 0x0E;
pts <<= 7;
pts |= data[ start + 1 ];
pts <<= 8;
pts |= (UInt32)data[ start + 2 ] & 0xFE;
pts <<= 7;
pts |= data[ start + 3 ];
pts <<= 7;
pts |= ( (UInt32)data[ start + 4 ] >> 1 );
return TimeSpan.FromMilliseconds( pts / 90D );
Note that the PES parsing logic needs to ensure there are at least 5 bytes available after “start” before calling this function.
Many high resolution digital video cameras record their data as .MTS files, which are containers for H.264 encoded video and audio. However many video editors are not able to open these files directly for further processing. If you have a codec that can play the file in a DirectShow compatible video player you can also open it with another program such as VirtualDub. All you have to do is to install AviSynth and then paste the text below into a batch file in a directory containing MTS videos. All the files will then be made available through an .avs file as a single, virtual video. Resizing and other pre-processing through AviSynth is optional. Before executing the batch file, you should make sure that all the .mts videos are of the same resolution and frame rate.
SET COMMAND=video_splice = AlignedSplice(
IF EXIST %AVSFILE% DEL %AVSFILE%
FOR %%a IN (*.mts) DO (
SET /a COUNT=!COUNT! + 1
ECHO video_!COUNT! = DirectShowSource^("%%~fa"^)
ECHO video_!COUNT! = DirectShowSource^("%%~fa"^) >> %AVSFILE%
IF !COUNT! NEQ 1 SET COMMAND=!COMMAND!,
ECHO %COMMAND% >> %AVSFILE%
ECHO ReduceBy2^(video_splice^) >> %AVSFILE%
START "" /MAX "VirtualDubPortable.exe" "%AVSFILE%"
Categories: Post Processing, Videography AlignedSplice(), AviSynth, AVS, Canon, DirectShow, DirectShowSource(), H.264, HF100, MTS, Video Editing, VirtualDub