5

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,479
  • 1
    On 20.04 imagemagick had no issues converting a simple webp image to gif. Simple command line I used was convert image.webp test.gif. Does this work on your system? If this does not work straight up try the following: sudo apt-get install webp before repeating the convert.... command again... – andrew.46 Sep 04 '20 at 06:54
  • my system doesn't have the convert command. i've tried sudo apt install convert and get the reply package convert does not exist what package is convert in? – rhubarbdog Sep 04 '20 at 10:31
  • 2
    It should be part of the imagemagick package... – andrew.46 Sep 05 '20 at 08:39
  • yes convert don't wotk for gif animations i need to use webpmux to remove each frame and then recontruct as a gif animation but i struggle wit h the commands – rhubarbdog Sep 19 '20 at 13:11
  • convert does not support webp, even with the webp package. – Cerin Oct 13 '20 at 20:36
  • does anyone know how to use webpmux. i have the man page, but there is something i'm missing when trying to extract a frame from an animation – rhubarbdog Oct 14 '20 at 22:29
  • 1
    convert DOES support webp, but you need to download and compile the latest version, with libwebp-dev package installed. – Maadinsh Jan 19 '22 at 11:05
  • The convert command works on 22.04. I'm pretty sure you need to install imagemagick-6.q16 in addition to imagemagick-6-common (and also the webp package if that makes any difference). – mchid Mar 29 '25 at 18:13

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,813
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()