You can enhance the script by adding more command-line parameters to control various aspects of the video and audio processing. Here are some additional parameters you can add to the script:
-
Video Bitrate: Allow users to specify a custom video bitrate.
elseif ($arg -match '^-vb=(\d+[kKmMgG]?)$') {
$videoBitrate = $matches[1]
}
Add -b:v $videoBitrate to your ffmpeg command.
-
Output Format: Let users specify the output container format (e.g., mp4, mkv).
elseif ($arg -match '^-f=(\w+)$') {
$format = $matches[1]
}
Adjust the output filename or add -f $format to the ffmpeg command.
-
Framerate: Allow users to set a custom output framerate.
elseif ($arg -match '^-r=(\d+(\.\d+)?)$') {
$framerate = $matches[1]
}
Include -r $framerate in the ffmpeg command.
-
Resolution: Enable users to specify output resolution.
elseif ($arg -match '^-s=(\d+x\d+)$') {
$resolution = $matches[1]
}
Add -s $resolution to the ffmpeg command.
-
Audio Bitrate: Allow specification of the audio bitrate.
elseif ($arg -match '^-ab=(\d+[kKmMgG]?)$') {
$audioBitrate = $matches[1]
}
Update -b:a $audioBitrate in the command.
-
Audio Channels: Let users choose the number of audio channels.
elseif ($arg -match '^-ac=(\d+)$') {
$audioChannels = $matches[1]
}
Include -ac $audioChannels in your command.
-
Video Codec: Allow changing the video codec.
elseif ($arg -match '^-vcodec=(\w+)$') {
$videoCodec = $matches[1]
}
Replace -c:v libx265 with -c:v $videoCodec in the command.
-
Audio Volume Adjustment: Enable volume changes.
elseif ($arg -match '^-vol=(\d+)%$') {
$volume = $matches[1]
}
Add -filter:a "volume=$volume%" to the command.
-
Output Directory: Specify an output directory.
elseif ($arg -match '^-o=(.+)$') {
$outputDir = $matches[1]
}
Ensure $outputFile is set accordingly.
-
Overwrite Existing Files: Control overwrite behavior.
if ($arg -match '^-y$') {
$overwrite = $true
}
Use -y (overwrite without asking) or -n (never overwrite) in ffmpeg.
-
Output Filename Suffix/Prefix: Customize output filenames.
elseif ($arg -match '^-suffix=(.+)$') {
$suffix = $matches[1]
}
Append $suffix to $outputFile.
-
Select Specific Streams: Choose specific audio/subtitle streams.
elseif ($arg -match '^-map=(.+)$') {
$mapOptions = $matches[1]
}
Include -map $mapOptions in the command.
-
Exclude Subtitles: Option to exclude subtitles.
if ($arg -match '^-nosubs$') {
$includeSubtitles = $false
}
Remove -c:s copy if $includeSubtitles is $false.
-
Apply Video Filters: Add video filters like scaling, cropping, etc.
elseif ($arg -match '^-vf=(.+)$') {
$videoFilter = $matches[1]
}
Add -vf "$videoFilter" to the command.
-
Set Constant Rate Factor (CRF) Value: This controls quality.
elseif ($arg -match '^-crf=(\d+(\.\d+)?)$') {
$crf = [double]$matches[1]
}
Include -crf $crf in the ffmpeg command.
-
Specify Encoding Tune: Optimize settings for specific content types.
elseif ($arg -match '^-tune=(\w+)$') {
$tune = $matches[1]
}
Add -tune $tune to the command.
-
Hardware Acceleration: Enable hardware acceleration if available.
if ($arg -match '^-hwaccel$') {
$hwAccel = $true
}
Include -hwaccel auto if $hwAccel is $true.
-
Adjust GOP Size: Control keyframe interval.
elseif ($arg -match '^-g=(\d+)$') {
$gopSize = $matches[1]
}
Add -g $gopSize to the command.
-
Set Maximum Bitrate: Combine with buffer size for constrained encoding.
elseif ($arg -match '^-maxrate=(\d+[kKmMgG]?)$') {
$maxRate = $matches[1]
}
Include -maxrate $maxRate in the command.
-
Set Buffer Size: Used with maximum bitrate.
elseif ($arg -match '^-bufsize=(\d+[kKmMgG]?)$') {
$bufSize = $matches[1]
}
Add -bufsize $bufSize to the command.
By adding these parameters, users can have granular control over the encoding process directly from the command line, making your script versatile and powerful. Remember to update your ffmpeg command to include these variables where appropriate.
Make sure to handle the cases where optional parameters may not be set (i.e., check if the variable is not $null before including it in the command).