-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,23 @@ | ||
<#PSScriptInfo | ||
.VERSION 0.1.0 | ||
.GUID 82549e1a-69f4-407b-baff-4f97d75b9852 | ||
.AUTHOR Kitsune Solar | ||
.AUTHOREMAIL [email protected] | ||
.COMPANYNAME iHub.TO | ||
.COPYRIGHT 2023 Kitsune Solar. All rights reserved. | ||
.LICENSEURI https://github.com/pkgstore/pwsh-ffmpeg/blob/main/LICENSE | ||
.PROJECTURI https://github.com/pkgstore/pwsh-ffmpeg | ||
#> | ||
|
||
$App = @('ffmpeg.exe') | ||
$AppExe = @{LiteralPath = "${PSScriptRoot}"; Filter = "$($App[0])"; Recurse = $true; File = $true} | ||
$AppExe = ((Get-ChildItem @AppExe) | Select-Object -First 1) | ||
$NL = "$([Environment]::NewLine)" | ||
|
||
function Compress-Video() { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory)][Alias('I')][string[]]$P_In, | ||
[Alias('CV')][string]$P_vCodec = 'libx265', | ||
[Alias('CA')][string]$P_aCodec = 'copy', | ||
[Alias('R')][int]$P_Framerate, | ||
[Alias('C')][int]$P_CRF, | ||
[Alias('PS')][string]$P_Preset, | ||
[Alias('EXT')][string]$P_Extension = 'mp4' | ||
) | ||
|
||
# Checking FFmpeg location. | ||
Test-FFmpeg | ||
|
||
(Get-Item $P_In) | ForEach-Object { | ||
$I = "$($_.FullName)" # Input data. | ||
$O = "$($_.FullName.TrimEnd($_.Extension)).${P_Extension}" # Output data. | ||
|
||
$Param = @('-hide_banner') # Hide FFmpeg banner. | ||
$Param += @('-i', "${I}") # Input data. | ||
$Param += @('-c:v', "${P_vCodec}") # Video codec. | ||
if ($P_CRF) { $Param += @('-crf', "${P_CRF}") } # Constant Rate Factor. | ||
if ($P_Preset) { $Param += @('-preset', "${P_Preset}") } # Video preset. | ||
if ($P_Framerate) { $Param += @('-r', "${P_Framerate}") } # Video frame rate. | ||
$Param += @('-c:a', "${P_aCodec}") # Audio codec. | ||
$Param += @("${O}") # Output data. | ||
|
||
& "${AppExe}" $Param | ||
$Aliases = @() | ||
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Include '*.ps1' -File -Recurse) | ||
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Include '*.ps1' -File -Recurse) | ||
|
||
(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object { | ||
try { | ||
Write-Verbose "Loading '$($_.FullName)'." | ||
. $_.FullName | ||
} catch { | ||
Write-Warning $_.Exception.Message | ||
} | ||
} | ||
|
||
function Test-FFmpeg { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
# Getting 'curl.exe' directory. | ||
$Dir = "$($AppExe.DirectoryName)" | ||
@($PublicFunctions) | ForEach-Object { | ||
$Alias = (Get-Alias -Definition $_.BaseName -ErrorAction 'SilentlyContinue') | ||
|
||
# Checking the location of files. | ||
$App | ForEach-Object { | ||
if (-not (Test-Data -T 'F' -P "${Dir}\${_}")) { | ||
Write-Msg -T 'W' -A 'Stop' -M ("'${_}' not found!${NL}${NL}" + | ||
"1. Download '${_}' from 'https://www.gyan.dev/ffmpeg/builds/'.${NL}" + | ||
"2. Extract all the contents of the archive into a directory '${PSScriptRoot}'.") | ||
} | ||
if ($Alias) { | ||
$Aliases += $Alias | ||
Export-ModuleMember -Function $_.BaseName -Alias $Alias | ||
} else { | ||
Export-ModuleMember -Function $_.BaseName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function Start-FFmpeg { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
Param( | ||
[Alias('AD')][string[]]$AppData = @('ffmpeg.exe') | ||
) | ||
|
||
$AppPath = (Split-Path -Path "${PSScriptRoot}" -Parent) | ||
$App = @{LiteralPath = "${AppPath}"; Filter = "$($AppData[0])"; Recurse = $true; File = $true} | ||
$App = ((Get-ChildItem @App) | Select-Object -First 1) | ||
$NL = [Environment]::NewLine | ||
|
||
$AppData | ForEach-Object { | ||
if (-not (Test-Data -T 'F' -P "$($App.DirectoryName)\${_}")) { | ||
Write-Msg -T 'W' -A 'Stop' -M ("'${_}' not found!${NL}${NL}" + | ||
"1. Download '${_}' from 'https://www.gyan.dev/ffmpeg/builds/'.${NL}" + | ||
"2. Extract all the contents of the archive into a directory '${AppPath}'.") | ||
} | ||
} | ||
|
||
$App | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function Compress-Video() { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory)][Alias('I')][string[]]$P_In, | ||
[Alias('CV')][string]$P_vCodec = 'libx265', | ||
[Alias('CA')][string]$P_aCodec = 'copy', | ||
[Alias('R')][int]$P_Framerate, | ||
[Alias('C')][int]$P_CRF, | ||
[Alias('PS')][string]$P_Preset, | ||
[Alias('EXT')][string]$P_Extension = 'mp4' | ||
) | ||
|
||
(Get-Item $P_In) | ForEach-Object { | ||
$I = "$($_.FullName)" # Input data. | ||
$O = "$($_.FullName.TrimEnd($_.Extension)).${P_Extension}" # Output data. | ||
|
||
$Param = @('-hide_banner') # Hide FFmpeg banner. | ||
$Param += @('-i', "${I}") # Input data. | ||
$Param += @('-c:v', "${P_vCodec}") # Video codec. | ||
if ($P_CRF) { $Param += @('-crf', "${P_CRF}") } # Constant Rate Factor. | ||
if ($P_Preset) { $Param += @('-preset', "${P_Preset}") } # Video preset. | ||
if ($P_Framerate) { $Param += @('-r', "${P_Framerate}") } # Video frame rate. | ||
$Param += @('-c:a', "${P_aCodec}") # Audio codec. | ||
$Param += @("${O}") # Output data. | ||
|
||
& $(Start-FFmpeg) $Param | ||
} | ||
} |