Skip to content

Instantly share code, notes, and snippets.

@Ertavf
Last active June 17, 2023 00:56
Show Gist options
  • Save Ertavf/33682ac07bd38bce7f33430792ada7a0 to your computer and use it in GitHub Desktop.
Save Ertavf/33682ac07bd38bce7f33430792ada7a0 to your computer and use it in GitHub Desktop.
This PowerShell code is designed to gather information about Video files in a specified folder using the ffprobe tool. # It generates a table containing details such as the file name, modified date, duration, and jump location. # The jump location indicates the start time of each MKV file in the combined video.
function Get-MkvFileInfo {
# This PowerShell code is designed to gather information about Video files in a specified folder using the ffprobe tool.
# It generates a table containing details such as the file name, modified date, duration, and jump location.
# The jump location indicates the start time of each MKV file in the combined video.
# https://chat.openai.com/share/4210cce5-0d4d-4bc9-aa1f-a8fe072a3052
param(
[string]$ffprobeCmd = 'ffprobe',
[string]$folderPath = $([Environment]::GetFolderPath([Environment+SpecialFolder]::MyVideos))
)
# Check if ffprobeCmd is accessible
$command = Get-Command -Name $ffprobeCmd -ErrorAction SilentlyContinue
if (-not $command) {
Write-Host "ffprobe is not accessible. Please ensure ffprobe is installed or provide the correct path to the ffprobe executable."
return
}
# Get all MKV files in the folder
$mkvFiles = Get-ChildItem -Path $folderPath -Filter *.mkv
# Initialize the start location counter
$startLocation = [TimeSpan]::Zero
# Loop through each MKV file
$tableData = foreach ($file in $mkvFiles) {
$ffprobeOutput = & $ffprobeCmd -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file.FullName
$durationSeconds = [double]$ffprobeOutput.Trim()
$duration = [TimeSpan]::FromSeconds($durationSeconds)
# Create the jump location string
$jumpLocation = ($startLocation, $duration).ForEach({ $_.ToString('hh\:mm\:ss') }) -join ' - '
# Increment the start location counter
$startLocation += $duration
[PSCustomObject]@{
Jump = $jumpLocation
Filename = $file.Name
ModifiedDate = $file.LastWriteTime
Duration = $duration.ToString('hh\:mm\:ss')
}
}
# Display the table
$tableData | Format-Table -AutoSize
$totalDuration = $startLocation
# Display the total duration
Write-Host "Total Duration: $($totalDuration.ToString('hh\:mm\:ss'))"
# Display the table in a graphical grid window
$tableData | Out-GridView
}
# Usage:
Get-MkvFileInfo -folderPath $([Environment]::GetFolderPath([Environment+SpecialFolder]::MyVideos) + "\")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment