Skip to content

Commit

Permalink
Parse config file
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickenfuego committed Aug 15, 2022
1 parent fd2ea52 commit 7464067
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion modules/FFTools/Public/Invoke-FFMpeg.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using namespace System.IO
using namespace System.Collections

<#
.SYNOPSIS
Expand Down Expand Up @@ -165,7 +166,7 @@ function Invoke-FFMpeg {
# Additional ffmpeg options
[Parameter(Mandatory = $false)]
[Alias('FE', 'FFExtra')]
[array]$FFMpegExtra,
[Generic.List[object]]$FFMpegExtra,

# Additional encoder-specific options
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -402,10 +403,58 @@ function Invoke-FFMpeg {
<#
BUILD FINAL ARGUMENT ARRAYS
Pull configuration file contents
Set the base arguments
Pass arguments to Set-FFMpegArgs or Set-DvArgs functions to prepare for encoding
#>


# Try to parse the config files
try {
# Read config file for additional options
$config = Read-Config -Encoder $Encoder

# Add multi-valued ffmpeg config options to existing hash
if ($config['FFMpegHash']) {
if ($FFMpegExtra) {
$index = $ffmpegExtra.FindIndex( {
$args[0] -is [hashtable]
} )

if ($index -ne -1) {
# Catch error if duplicate keys are present
$FFMpegExtra[$index] += $config['FFMpegHash']
}
else { $FFMpegExtra.Add($config['FFMpegHash']) }
}
else {
$FFMpegExtra = @()
$FFMpegExtra.Add($config['FFMpegHash'])
}
}

# Add single valued ffmpeg config options
if ($config['FFMpegArray']) {
if ($FFMpegExtra) { $ffmpegExtra.AddRange($config['FFMpegArray']) }
else {
$FFMpegExtra = @()
$FFMpegExtra.AddRange($config['FFMpegArray'])
}
}

# Add encoder settings from config file
if ($config['Encoder']) {
if ($EncoderExtra) {
$EncoderExtra += $config['Encoder']
}
else { $EncoderExtra = $config['Encoder'] }
}
}
catch {
$e = $_.Exception.Message
Write-Error "Failed to parse the configuration file(s): $e"
}

$baseArgs = @{
Encoder = $Encoder
Audio = $audio
Expand Down

0 comments on commit 7464067

Please sign in to comment.