Skip to content

Commit

Permalink
2023-11-19 17:42:04
Browse files Browse the repository at this point in the history
  • Loading branch information
uidHUB committed Nov 19, 2023
1 parent b6f06a0 commit 4bb3554
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
14 changes: 7 additions & 7 deletions PkgStore.FFmpeg.psm1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ModuleManifest = (Get-ChildItem -Path $PSScriptRoot | Where-Object {$_.Extension -eq '.psd1'})
$ModuleManifest = (Get-ChildItem -Path $PSScriptRoot | Where-Object { $_.Extension -eq '.psd1' })
$CurrentManifest = (Test-ModuleManifest $ModuleManifest)

$Aliases = @()
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') | Where-Object {$_.Extension -eq '.ps1'})
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Where-Object {$_.Extension -eq '.ps1'})
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') | Where-Object { $_.Extension -eq '.ps1' })
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Where-Object { $_.Extension -eq '.ps1' })

(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object {
try {
Expand All @@ -25,10 +25,10 @@ $PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Whe
}
}

$FunctionsAdded = ($PublicFunctions | Where-Object {$_.BaseName -notin $CurrentManifest.ExportedFunctions.Keys})
$FunctionsRemoved = ($CurrentManifest.ExportedFunctions.Keys | Where-Object {$_ -notin $PublicFunctions.BaseName})
$AliasesAdded = ($Aliases | Where-Object {$_ -notin $CurrentManifest.ExportedAliases.Keys})
$AliasesRemoved = ($CurrentManifest.ExportedAliases.Keys | Where-Object {$_ -notin $Aliases})
$FunctionsAdded = ($PublicFunctions | Where-Object { $_.BaseName -notin $CurrentManifest.ExportedFunctions.Keys })
$FunctionsRemoved = ($CurrentManifest.ExportedFunctions.Keys | Where-Object { $_ -notin $PublicFunctions.BaseName })
$AliasesAdded = ($Aliases | Where-Object { $_ -notin $CurrentManifest.ExportedAliases.Keys })
$AliasesRemoved = ($CurrentManifest.ExportedAliases.Keys | Where-Object { $_ -notin $Aliases })

if ($FunctionsAdded -or $FunctionsRemoved -or $AliasesAdded -or $AliasesRemoved) {
try {
Expand Down
2 changes: 2 additions & 0 deletions Private/Start-FFmpeg.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function Start-FFmpeg {
<#
.SYNOPSIS
Running FFmpeg.
.DESCRIPTION
Checking the location of the program files and launching the program.
#>

param(
Expand Down
45 changes: 39 additions & 6 deletions Public/Compress-Video.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
function Compress-Video() {
<#
.SYNOPSIS
Video compression script based on FFmpeg.
.DESCRIPTION
FFmpeg is a free and open-source software project consisting of a suite of libraries and programs for handling video, audio, and other multimedia files and streams.
.PARAMETER In
An array of input files.
.PARAMETER vCodec
The video codec.
.PARAMETER aCodec
The audio codec.
.PARAMETER Framerate
FFmpeg can be used to change the frame rate of an existing video, such that the output frame rate is lower or higher than the input frame rate. The output duration of the video will stay the same.
This is useful when working with, for example, high-framerate input video that needs to be temporally scaled down for devices that do not support high FPS.
When the frame rate is changed, FFmpeg will drop or duplicate frames as necessary to achieve the targeted output frame rate.
.PARAMETER CRF
Constant Rate Factor.
Use this rate control mode if you want to keep the best quality and care less about the file size. This is the recommended rate control mode for most uses.
This method allows the encoder to attempt to achieve a certain output quality for the whole file when output file size is of less importance. This provides maximum compression efficiency with a single pass. By adjusting the so-called quantizer for each frame, it gets the bitrate it needs to keep the requested quality level. The downside is that you can't tell it to get a specific filesize or not go over a specific size or bitrate, which means that this method is not recommended for encoding videos for streaming.
.PARAMETER Preset
A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.
.PARAMETER Extension
The extension of the resulting files.
.EXAMPLE
Compress-Video -In 'File_01.MOV', 'File_02.MOV', 'File_03.MOV'
.EXAMPLE
Compress-Video -In '*.MOV'
#>

param(
Expand All @@ -16,17 +49,17 @@ function Compress-Video() {
)

(Get-Item $In) | ForEach-Object {
$I = "$($_.FullName)" # Input data.
$I = "$($_.FullName)" # Input data.
$O = "$($_.FullName.TrimEnd($_.Extension)).${Extension}" # Output data.

$Param = @('-hide_banner') # Hide FFmpeg banner.
$Param += @('-i', "${I}") # Input data.
$Param += @('-c:v', "${vCodec}") # Video codec.
$Param = @('-hide_banner') # Hide FFmpeg banner.
$Param += @('-i', "${I}") # Input data.
$Param += @('-c:v', "${vCodec}") # Video codec.
if ($CRF) { $Param += @('-crf', "${CRF}") } # Constant Rate Factor.
if ($Preset) { $Param += @('-preset', "${Preset}") } # Video preset.
if ($Framerate) { $Param += @('-r', "${Framerate}") } # Video frame rate.
$Param += @('-c:a', "${aCodec}") # Audio codec.
$Param += @("${O}") # Output data.
$Param += @('-c:a', "${aCodec}") # Audio codec.
$Param += @("${O}") # Output data.

& $(Start-FFmpeg) $Param
}
Expand Down

0 comments on commit 4bb3554

Please sign in to comment.