News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Get video duration with wmplayer

Started by Mikl__, May 15, 2017, 12:32:24 PM

Previous topic - Next topic

Mikl__

Hi, All!
How to get video duration with wmplayer? Or how to get information about duration in wmv-files? Thanks...

jj2007

https://msdn.microsoft.com/en-us/library/windows/desktop/ee663575(v=vs.85).aspx

Not easy, though. Check in particular GetSampleDuration.

TWell

#2
The lower Microsoft Web site link works for a older document.
https://msdn.microsoft.com/en-us/library/windows/desktop/dd757562(v=vs.85).aspxThe Header Object is represented using the following structure.

Field name Field type Size (bits)
Object ID GUID 128
Object Size QWORD 64
Number of Header Objects DWORD 32
Reserved1 BYTE 8
Reserved2 BYTE 8

The File Properties Object is represented using the following structure.

Field name Field typeSize (bits)
Object ID GUID 128
Object Size QWORD 64
File ID GUID 128
File Size QWORD 64
Creation Date QWORD 64
Data Packets Count QWORD 64
Play Duration QWORD 64 100-nanosecond units
Send Duration QWORD 64
Preroll QWORD 64
Flags DWORD 32
Broadcast Flag 1 (LSB)
Seekable Flag 1
Reserved 30
Minimum Data Packet Size DWORD 32
Maximum Data Packet Size DWORD 32
Maximum Bitrate DWORD 32



adeyblue

You can always take the scenic route. This works with any media type that Explorer will give you the duration of. There are a multitude of properties available but not all of them are present in every file, depending on the metadata or how they were produced etc. This is Vista+

#define _WIN32_WINNT 0x0600
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ole2.h>
#include <shobjidl.h>
#include <propkey.h>
#include <propvarutil.h>
#include <stdio.h>

#pragma comment(lib, "uuid.lib")
#pragma comment(lib, "propsys.lib")

int __cdecl main()
{
    CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
    IPropertyStore* pStore = NULL;
    PCWSTR pFileName = L"F:\\MyFilm.wmv";
    SHGetPropertyStoreFromParsingName(pFileName, NULL, GPS_DEFAULT, IID_PPV_ARGS(&pStore));
    PROPVARIANT var = {0};
    pStore->GetValue(PKEY_Media_Duration, &var);
    wprintf(L"%s has a duration of %I64u 100ns\n", pFileName, var.uhVal.QuadPart);
    PropVariantClear(&var);
    pStore->Release();
    CoUninitialize();
    return 0;
}

// this will list all available properties in a store, lookup the "System." name on
// https://msdn.microsoft.com/en-us/library/windows/desktop/ff521702(v=vs.85).aspx
// to find the named PKEY_ constant to use
void EnumProps(IPropertyStore* pStore)
{
    DWORD numProps = 0;
    HRESULT hr = pStore->GetCount(&numProps);
    for(DWORD i = 0; i < numProps; ++i)
    {
        PROPERTYKEY key = {0};
        PROPVARIANT var = {};
        PWSTR pPropName = NULL;
        hr = pStore->GetAt(i, &key);
        hr = pStore->GetValue(key, &var);
        hr = PSGetNameFromPropertyKey(key, &pPropName);
        PWSTR pValue = NULL;
        PropVariantToStringAlloc(var, &pValue);
        wprintf(L"Found property %lu: %s = %s\n", i + 1, pPropName, pValue);
        CoTaskMemFree(pValue);
        CoTaskMemFree(pPropName);
        PropVariantClear(&var);
    }
}

Mikl__

jj2007, TWell, adeyblue,
thank you very much for the help!

Mikl__

Hi, All!
Maybe someone else this information will helpFile: D:\masm56\Uncle Remus tales\37\avdump\movie3.wmv
Duration: 00:00:21 (20.56)
Track #1: video
  lang: Unknown (1)
  codc: WMV2 -> MS MP4x (18)
  reso: 450x360 -> Unknown (aka not common)
  fram: 0 fps
  rate: 1456 kbps (1456.14)
  dura: 00:00:00 (0)
  size: 0.00 B (0)
Track #2: audio
  lang: Unknown (1)
  codc: 161 -> WMA (DivX Audio) (3)
  chan: 2 -> Stereo
  samp: 44100 Hz
  rate: 160 kbps (160.00)
  dura: 00:00:00 (0.00)
  size: 0.00 B (0)
Sizes: (check sanity)
  disk: 4.04 MB (4237575)
  trac: 0.00 B (0) [based on track size]
  bitr: 3.96 MB (4153490) [based on bitrate]
  tdif: 4.04 MB (4237575) 100.00%
  bdif: 82.11 KB (84084) 1.98%

066: 00 35 41 0C 00 00 00 00 |205600000 in 100 ns
102: C2 01 00 00             |450
106: 68 01 00 00             |360
11D: 57 4D 56 32             |'VMV2'
18B: 44 AC 00 00             |44100 Hz