4

I have downloaded a number of video clips they are in a format called .webp. How do I convert them to .gif? A chat room I use frequently only allows .gif and .jpeg files.

I've done something like this before but it was ages ago and I can't remember what to do.

andrew.46
  • 39,359
rhubarbdog
  • 422
  • 1
  • 4
  • 11

2 Answers2

2

I got this to work by modifying a script by Sean Mahan that appears to have been intended for Arch Linux I simply quoted the variables (otherwise it failed under Ubuntu 18.04.5 LTS). Here's the Ubuntu script I used. This could be further modified to include checking to insure all dependencies are installed (and optionally installing them if not).

#!/bin/bash

DELAY="${DELAY:-10}" LOOP="${LOOP:-0}" r=realpath "$1" d=dirname "$r" pushd "$d" > /dev/null f=basename "$r" n=webpinfo -summary "$f" | grep frames | sed -e 's/.* \([0-9]*\)$/\1/' dur=webpinfo -summary "$f" | grep Duration | head -1 | sed -e 's/.* \([0-9]*\)$/\1/'

if (( "$dur" > 0 )); then DELAY = "$dur" fi

pfx=echo -n $f | sed -e 's/^\(.*\).webp$/\1/' if [ -z "$pfx" ]; then pfx="$f" fi

echo "converting "$n" frames from "$f" working dir "$d" file stem "$pfx""

for i in $(seq -f "%05g" 1 "$n") do webpmux -get frame "$i" "$f" -o "$pfx"."$i".webp dwebp "$pfx"."$i".webp -o "$pfx"."$i".png done

convert "$pfx"..png -delay "$DELAY" -loop "$LOOP" "$pfx".gif rm "$pfx".[0-9].png "$pfx".[0-9]*.webp popd > /dev/null exit

Solution dependencies:

  1. webp package 2.imagemagick package 3.and of course bash
Elder Geek
  • 36,752
1

Python batch convert utility. Based on above contribution.
Requires creating a global webp-to-gif executable with Elder Geek's Sean Mahan code...

#!/usr/bin/env python3
# -*- coding: utf8 -*-
print( "####################################################" )
print( "Uses webp-to-gif to convert multiple..." )
print( "Converts all found if no regex provided             " )
print( "args: [group regex: optional] [path: optional]      " )
print( "                                                    " )
print( "####################################################" )

import sys, os, fnmatch, itertools import re

args = [x.replace('\', '') for x in list(sys.argv)]; args.pop(0) if len(args) == 1: args = args[0].split(' ')

print() print() print( "---------------------------------" ) print( " Begin... " ) print( "---------------------------------" ) print() print()

regex = r'(.*).webp' path = '.' if len(args): regex = args[0] if len(args)>1: path = args[1]

os.chdir(path) nn = 0 for f in os.listdir('.'): m = re.match(regex, f) if m: fn, e = os.path.splitext(f) os.system('webp-to-gif %s %s' % (f, '%s.gif' % (fn))) print( '- Done for "%s"' % f ) nn += 1

print() print() print( '---------------------------------' ) print( "%i matched" % nn ) print() print() print( "---------------------------------" ) print( " Done " ) print( "---------------------------------" ) print() print()