Добавил вариант экспорта эмодзи
This commit is contained in:
14
README.md
Normal file
14
README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# How to use script.ps1
|
||||||
|
|
||||||
|
This script is designed to convert any images and/or gifs to webm extension so that they can be used to create animated sticker/emoji packs in Telegram.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. Install ffmpeg and ffprobe on your system if they are not already installed.
|
||||||
|
2. Clone this repository and navigate to the directory containing script.ps1.
|
||||||
|
3. Create a directory named "input" and populate it with the images and/or gifs you want to convert.
|
||||||
|
4. Run the following command in your terminal: `& script.ps1`
|
||||||
|
|
||||||
|
## Output
|
||||||
|
|
||||||
|
The script will output the converted webm files to a directory named "output". The files will be named the same as the input files but with a .webm extension instead of their original extension.
|
||||||
45
script.ps1
45
script.ps1
@ -4,6 +4,28 @@ $ffprobePath = (Get-Command ffprobe -ErrorAction SilentlyContinue).Path
|
|||||||
$inputDir = "./input"
|
$inputDir = "./input"
|
||||||
$outputDir = "./output"
|
$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
|
# Functions
|
||||||
# Function to get the bitrate of a video file using ffprobe
|
# Function to get the bitrate of a video file using ffprobe
|
||||||
function Get-Bitrate {
|
function Get-Bitrate {
|
||||||
@ -70,7 +92,7 @@ function Compress-File {
|
|||||||
Write-Host Trying bitrate: ${bitrate}k
|
Write-Host Trying bitrate: ${bitrate}k
|
||||||
|
|
||||||
# Compress with the current bitrate
|
# 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
|
# Check the size of the compressed file
|
||||||
$fileSize = (Get-Item $outputFilePathTemp).Length
|
$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
|
# Process each file in the input directory
|
||||||
foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
||||||
$outputFile = "$outputDir/$($file.BaseName).webm"
|
$outputFile = "$outputDir/$($file.BaseName).webm"
|
||||||
@ -124,7 +135,7 @@ foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
|||||||
|
|
||||||
# Convert the file to WebM format
|
# Convert the file to WebM format
|
||||||
if ($file.Extension -eq ".png") {
|
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") {
|
if ($file.Extension -eq ".gif") {
|
||||||
@ -139,7 +150,7 @@ foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Convert the file to WebM format
|
# 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 {
|
} else {
|
||||||
Write-Host "Invalid duration for GIF $($file.FullName). Skipping..."
|
Write-Host "Invalid duration for GIF $($file.FullName). Skipping..."
|
||||||
continue
|
continue
|
||||||
@ -148,14 +159,14 @@ foreach ($file in Get-ChildItem -Path $inputDir -File) {
|
|||||||
# Check if the file size exceeds 256 KB (262144 bytes)
|
# Check if the file size exceeds 256 KB (262144 bytes)
|
||||||
$fileSize = (Get-Item $outputFile).Length
|
$fileSize = (Get-Item $outputFile).Length
|
||||||
|
|
||||||
if ($fileSize -gt 262144) {
|
if ($fileSize -gt 255 * 1024) {
|
||||||
Write-Host "File $($outputFile) exceeds 256 KB, compressing..."
|
Write-Host "File $($outputFile) exceeds 256 KB, compressing..."
|
||||||
|
|
||||||
# Get the initial bitrate of the WebM file
|
# Get the initial bitrate of the WebM file
|
||||||
$initialBitrate = Get-Bitrate -filePath $outputFile
|
$initialBitrate = Get-Bitrate -filePath $outputFile
|
||||||
|
|
||||||
# Compress the file until it is below 256 KB
|
# Compress the file until it is below 255 KB
|
||||||
Compress-File -inputFilePath $file.FullName -outputFilePath $outputFile -initialBitrate $initialBitrate -maxSizeKB 256
|
Compress-File -inputFilePath $file.FullName -outputFilePath $outputFile -initialBitrate $initialBitrate -maxSizeKB 255
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user