Line Animation Sticker

30fps Gif to 20fps apng

這應該是最重要的目標

  1. 透過ffmpeg砍fps
    ffmpeg -i input.gif -r 20 -vframes 20 frame_%d.png

  2. APNG Assembler
    apngasm output.png frame*.png -l4

  • bat
    @echo off
    setlocal enabledelayedexpansion
    
    rem Check if files were dragged onto the script
    if "%~1"=="" (
        echo Please drag and drop GIF files onto this script.
        pause
        exit /b 1
    )
    
    rem Loop through all dragged files
    :process_files
    if "%~1"=="" goto end_process
    
    rem Get the full path of the dragged file
    set "gif_path=%~1"
    
    rem Extract file name and directory
    set "file_name=%~n1"
    set "gif_folder=%~dp1"
    
    rem Change to the GIF folder
    cd /d "%gif_folder%"
    
    rem Step 1: Convert GIF to PNG frames with 20fps
    ffmpeg -i "%gif_path%" -r 20 -vframes 20 "%file_name%_frame_%%d.png"
    
    rem Step 2: Assemble PNG frames into APNG
    apngasm "%file_name%.apng" "%file_name%_frame_*.png" -l4
    
    rem Clean up PNG frames
    del "%file_name%_frame_*.png"
    
    shift
    goto process_files
    
    :end_process
    echo Conversion complete!
    pause
    

Update Line 貼圖只吃 300x270 其中一邊限定270

-filter_complex

  • padding
    • "[0:v] pad=w=300:h=270:x=(ow-iw)/2:y=(oh-ih)/2:color=#00000000, split [a][b]; [a] palettegen=max_colors=32 [p]; [b][p] paletteuse"
  • scale
    • "[0:v] scale=-1:270, split [a][b]; [a] palettegen=max_colors=32 [p]; [b][p] paletteuse"

palettegen=max_colors=32 (色彩深度? 反正就是顏色幾種 用越多越大 )

REF
https://superuser.com/questions/1049606/reduce-generated-gif-size-using-ffmpeg https://stackoverflow.com/questions/35603464/transparency-is-gone-while-resizing-scaling-gif-using-ffmpeg

這我沒試過 都是GPT寫的

  • PS1
    param (
        [string[]]$gif_paths
    )
    
    if (-not $gif_paths) {
        Write-Output "Please drag and drop GIF files onto this script."
        pause
        exit
    }
    
    foreach ($gif_path in $gif_paths) {
        # Extract file name without extension and directory
        $file_name = [System.IO.Path]::GetFileNameWithoutExtension($gif_path)
        $gif_folder = [System.IO.Path]::GetDirectoryName($gif_path)
    
        # Change to the GIF folder
        Set-Location $gif_folder
    
        # Step 1: Convert GIF to PNG frames with 20fps
        $frame_pattern = "$file_name`_frame_`%d.png"
        Start-Process ffmpeg -ArgumentList "-i", $gif_path, "-r", "20", $frame_pattern -NoNewWindow -Wait
    
        # Step 2: Assemble PNG frames into APNG
        $output_apng = "$file_name.apng"
        Start-Process apngasm -ArgumentList $output_apng, "$file_name`_frame_*.png", "-l4" -NoNewWindow -Wait
    
        # Clean up PNG frames
        Remove-Item "$file_name`_frame_*.png"
    }
    
    Write-Output "Conversion complete!"
    pause
    

以後可能用的到 https://www.npmjs.com/package/sharp-apng#encoderoptions

updatedupdated2024-08-192024-08-19
載入評論