GithubHelp home page GithubHelp logo

tophf / parsemkv Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 2.0 86 KB

Matroska .mkv file parser in PowerShell, doesn't require external tools, produces a hierarchical object tree, optionally pretty-prints to console

License: MIT License

PowerShell 100.00%
mkv parsing powershell

parsemkv's Introduction

parsemkv

Powershell module that parses a matroska .mkv file into a hierarchical object tree, optionally pretty-printing to console

Usage examples:

  • Print the entire structure
    parseMKV 'c:\some\path\file.mkv' -print

screenshot

Some entries are skipped by default, see parameter descriptions in the code.

Unabridged output: parseMKV '....' -printRaw

  • Get the duration value

    $mkv = parseMKV 'c:\some\path\file.mkv' -get Info -binarySizeLimit 0
    $duration = $mkv.Segment.Info.Duration

    Parsing is stopped after 'Info' section is read and binary entries are skipped for speedup

  • Print video/audio info

    $mkv = parseMKV 'c:\some\path\file.mkv'`
    $mkv.Segment.Tracks.Video | %{
    	'Video: {0}x{1}, {2}' -f $_.Video.PixelWidth, $_.Video.PixelHeight, $_.CodecID
    }
    $isMultiAudio = $mkv.Segment.Tracks.Audio.Capacity -gt 1
    $mkv.Segment.Tracks.Audio | %{ $index=0 } {
    	'Audio{0}: {1}{2}' -f (++$index), $_.CodecID, $_.Audio.SamplingFrequency
    }
  • Extract all attachments

    $mkv = parseMKV 'c:\some\path\file.mkv' -keepStreamOpen -binarySizeLimit 0
    $outputDir = 'd:\'
    echo "Extracting to $outputDir"
    forEach ($att in $mkv.find('AttachedFile')) {
    	write-host "`t$($att.FileName)"
    	$file = [IO.File]::create((join-path $outputDir $att.FileName))
    	$mkv.reader.baseStream.position = $att.FileData._.datapos
    	$data = $mkv.reader.readBytes($att.FileData._.size)
    	$file.write($data, 0, $data.length)
    	$file.close()
    }
    $mkv.reader.close()
  • Find/access elements

    $mkv = parseMKV 'c:\some\path\file.mkv'
    $DisplayWidth = $mkv.find('DisplayWidth')
    $DisplayHeight = $mkv.find('DisplayHeight')
    $VideoCodecID = $DisplayWidth._.closest('TrackEntry').CodecID
    $DisplayWxH = $mkv.Segment.Tracks.Video._.find('', '^Display[WH]') -join 'x'
    $mkv.find('ChapterTimeStart')._.displayString -join ", "
    forEach ($chapter in $mkv.find('ChapterAtom')) {
    	'{0:h\:mm\:ss}' -f $chapter._.find('ChapterTimeStart') +
    	' - ' + $chapter._.find('ChapString')
    }

parsemkv's People

Contributors

tophf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.