Добавил вариант экспорта эмодзи
This commit is contained in:
45
script.ps1
45
script.ps1
@ -4,6 +4,28 @@ $ffprobePath = (Get-Command ffprobe -ErrorAction SilentlyContinue).Path
|
||||
$inputDir = "./input"
|
||||
$outputDir = "./output"
|
||||
|
||||
# Check if ffmpeg and ffprobe executables exist
|
||||
if (-not $ffmpegPath -or -not $ffprobePath) {
|
||||
Write-Host "ffmpeg or ffprobe is not installed on this system. Exiting..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Ask user if he wants to do stickers or emoji
|
||||
$choice = Read-Host "Do you want to create stickers or emoji? (s/e)"
|
||||
if ($choice -eq "s") {
|
||||
$stickerWidth = 512
|
||||
} elseif ($choice -eq "e") {
|
||||
$stickerWidth = 100
|
||||
} else {
|
||||
Write-Host "Invalid choice. Exiting..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if the output directory exists, if not, create it
|
||||
if (-not (Test-Path $outputDir)) {
|
||||
New-Item -Path $outputDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# Functions
|
||||
# Function to get the bitrate of a video file using ffprobe
|
||||
function Get-Bitrate {
|
||||
@ -70,7 +92,7 @@ function Compress-File {
|
||||
Write-Host Trying bitrate: ${bitrate}k
|
||||
|
||||
# Compress with the current bitrate
|
||||
& $ffmpegPath -loglevel quiet -i $inputFilePath -t 3 -r 25 -filter:v "setpts=PTS/$speedFactor,scale=-1:512" -c:v libvpx-vp9 -b:v ${bitrate}k $outputFilePathTemp -y
|
||||
& $ffmpegPath -loglevel quiet -i $inputFilePath -t 3 -r 25 -filter:v "setpts=PTS/$speedFactor,scale=-1:$stickerWidth" -c:v libvpx-vp9 -b:v ${bitrate}k $outputFilePathTemp -y
|
||||
|
||||
# Check the size of the compressed file
|
||||
$fileSize = (Get-Item $outputFilePathTemp).Length
|
||||
@ -100,17 +122,6 @@ function Compress-File {
|
||||
}
|
||||
}
|
||||
|
||||
# Check if ffmpeg and ffprobe executables exist
|
||||
if (-not $ffmpegPath -or -not $ffprobePath) {
|
||||
Write-Host "ffmpeg or ffprobe is not installed on this system. Exiting..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if the output directory exists, if not, create it
|
||||
if (-not (Test-Path $outputDir)) {
|
||||
New-Item -Path $outputDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# Process each file in the input directory
|
||||
foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
||||
$outputFile = "$outputDir/$($file.BaseName).webm"
|
||||
@ -124,7 +135,7 @@ foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
||||
|
||||
# Convert the file to WebM format
|
||||
if ($file.Extension -eq ".png") {
|
||||
& $ffmpegPath -loglevel quiet -i $file.FullName -r 25 -vf "scale=-1:512" -c:v libvpx-vp9 -pix_fmt rgba $outputFile -y
|
||||
& $ffmpegPath -loglevel quiet -i $file.FullName -r 25 -vf "scale=-1:$stickerWidth" -c:v libvpx-vp9 -pix_fmt rgba $outputFile -y
|
||||
}
|
||||
|
||||
if ($file.Extension -eq ".gif") {
|
||||
@ -139,7 +150,7 @@ foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
||||
}
|
||||
|
||||
# Convert the file to WebM format
|
||||
& $ffmpegPath -loglevel quiet -i $file.FullName -t 3 -r 25 -filter:v "setpts=PTS/$speedFactor,scale=-1:512" -c:v libvpx-vp9 $outputFile -y
|
||||
& $ffmpegPath -loglevel quiet -i $file.FullName -t 3 -r 25 -filter:v "setpts=PTS/$speedFactor,scale=-1:$stickerWidth" -c:v libvpx-vp9 $outputFile -y
|
||||
} else {
|
||||
Write-Host "Invalid duration for GIF $($file.FullName). Skipping..."
|
||||
continue
|
||||
@ -148,14 +159,14 @@ foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
||||
# Check if the file size exceeds 256 KB (262144 bytes)
|
||||
$fileSize = (Get-Item $outputFile).Length
|
||||
|
||||
if ($fileSize -gt 262144) {
|
||||
if ($fileSize -gt 255 * 1024) {
|
||||
Write-Host "File $($outputFile) exceeds 256 KB, compressing..."
|
||||
|
||||
# Get the initial bitrate of the WebM file
|
||||
$initialBitrate = Get-Bitrate -filePath $outputFile
|
||||
|
||||
# Compress the file until it is below 256 KB
|
||||
Compress-File -inputFilePath $file.FullName -outputFilePath $outputFile -initialBitrate $initialBitrate -maxSizeKB 256
|
||||
# Compress the file until it is below 255 KB
|
||||
Compress-File -inputFilePath $file.FullName -outputFilePath $outputFile -initialBitrate $initialBitrate -maxSizeKB 255
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user