powershellmkvmediainfo

Powershell script to get the metadata field "writing application"


I am using a modified version of the GetMetaData script originally written by Ed Wilson at Microsoft (https://devblogs.microsoft.com/scripting/hey-scripting-guy-how-can-i-find-files-metadata/) and then modified by user wOxxOm here https://stackoverflow.com/a/42933461/5061596 . I'm trying to analyze all my DVD and BluRay rips and see what tool was used to create them. Mainly I want to check which ones I compressed with Handbrake and which ones came directly from MakeMKV. The problem is I can't find this field.

If I use the "stock" scrip and change the number of properties it looks for from 0 - 266 up to 0 - 330 I find the extra file info like movie length, resolution, etc. But I can't find the tool used. For example here is what the MediaInfo Lite tool reports:

MediaInfo Lite Example

But looking through the meta data I get something like this with no "Writing application" property:

Name              : Ad Astra (2019).mkv
Size              : 44.1 GB
Title             : Ad Astra
Length            : 02:03:02
Frame height      : 2160
Frame rate        : ‎23.98 frames/second
Frame width       : 3840
Total bitrate     : ‎51415kbps
Audio tracks      : TrueHD S24 7.1 [Eng]
Contains chapters : Yes
Subtitle tracks   : PGS [Eng], PGS [Eng]
Video tracks      : HEVC (H265 Main 10 @L5.1)

How do I go about finding that property or is it not something that I can pull through PowerShell?

Edit: The info I'm looking for IS in Windows Explorer looking at the properties of the file and the details tab so if Explorer can see it I would think I should be able to:

enter image description here


Solution

  • edit: actually, this seems more reliable. So far any file that mediainfo can read, this also works with.

    $FILE = "C:\test.mkv"
    $content = (Get-Content -Path $FILE -First 100) + (Get-Content -Path $FILE -Tail 100)
    if(($content -match '\*data')[0] -match '\*data\W*([\w\n\s\.]*)'){
        write-host "Writing Application:" $Matches[1]
        exit
    }elseif(($content -match 'M€.*WA(.*)s¤')[0] -match 'M€.*WA(.*)s¤'){
        write-host "Writing Application:" $Matches[1]
    }
    

    It looks like the last bytes in the file after *data that specify the writer, so try this:

    (Get-Content -Path "c:\video.mkv" -Tail 1) -match '\*data\W*(.*)$' | out-null
    write-host "Writing Application:" $Matches[1]
    

    On my test file that resulted in "HandBrake 1.5.1 2022011000"

    I'm not sure what standard specifies this sorry. There's also a host of useful info on the first line of data in the file as well, e.g:

    ftypmp42 mp42iso2avc1mp41 free6dÊmdat ôÿÿðÜEé½æÙH·–,Ø Ù#îïx264 - core 164 r3065 ae03d92 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadz one=21,11 fast_pskip=1 chroma_qp_offset=0 threads=18 lookahead_threads=5 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin =0 qpmax=69 qpstep=4 vbv_maxrate=14000 vbv_bufsize=14000 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00

    I couldn't replicate your success viewing the info with Windows Explorer, the field is invisible for me even though I can view it with MediaInfo etc