Last active
January 5, 2024 03:40
-
-
Save ajmas/63b40dee8e52958ef2b9d1f6839193c2 to your computer and use it in GitHub Desktop.
Convert WEBP to MP4
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
#!/bin/sh | |
## Quick script to convert webp files to mp4. Makes use of webpmux, ImageMagick and ffmpeg | |
input=$1 | |
output_base=/tmp | |
output_file=output.mp4 | |
regex="Number of frames: ([0-9]+)" | |
info=`webpmux -info "$1"` | |
if [[ $info =~ $regex ]] | |
then | |
rm "$output_base/frame_*.png" | |
frame_count="${BASH_REMATCH[1]}" | |
frame_count=$(($frame_count)) | |
for idx in $(seq -f '%02g' 01 $frame_count); do | |
# Extract the frames from the webp | |
webpmux -get frame $idx "$1" -o "$output_base/frame_$idx.png" | |
# Use ImageMagick to convert the PNG to PNG, since the one outputted by webpmux seems unsupported by ffmpeg | |
convert "$output_base/frame_$idx.png" "$output_base/frame_$idx.png" | |
done | |
# Take the frames and assemble the MP4. We need to tune the FPS, since right now it is hardcoded | |
ffmpeg -framerate 5 -pattern_type glob -i "$output_base/"'frame_*.png' -c:v libx264 -pix_fmt yuv420p "$output_file" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment