• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Convert video file into gif file through command line in linux

July 10, 2013 by Sharad Chhetri Leave a Comment

In this post, learn how to convert video file into gif file through command line in linux. For converting the video file into gif file there are many methods. We tried most of the methods. We used some software package like mplayer and image-magick.

Image-magick has one issue that is related to memory allocation. With image-magick we were able to convert jpg to gif files but the problem was occurring when we were using lot of files to convert.

Below is the sample of error

linux@tuxworld:~/Desktop$ convert -delay 5 output/*.jpg gif-example.gif
convert.im6: memory allocation failed `gif-example.gif’ @ error/quantize.c/QuantizeImage/2724.
convert.im6: memory allocation failed `gif-example.gif’ @ error/gif.c/WriteGIFImage/1636.
linux@tuxworld:~/Desktop

After getting this error many times, we finally decided to go with ffmpeg and gifsicle . Which we found very much effective.

Follow the steps to convert video file

Step 1: We assume you already have video file , here we have created a mp4 file with the help of kazam software in Ubuntu.

Install ffmpeg and gifsicle.

sudo apt-get install ffmpeg gifsicle

Step 2: Creating a output directory and using ffmpeg to create multiple gif files as frames.
In below given example, through ffmpeg command we are creating multiple file inside output directory

Here,
-r = frame rate
-i = input file

mkdir output
ffmpeg -i linux-tutorial.mp4 -r 10 output/out%04d.gif 

Step 3: Now aggregate all gif files into single gif file with the help of gifsicle command
Here,
-d = delay

#(This example is without loop)
gifsicle -d 10  output/*.gif > linux-example.gif

#(This example is with loop)
gifsicle -d 10 --loop  output/*.gif > linux-example2.gif

Optimize the file size of gif

After creating a gif file from above given steps. If you have noticed the file size of gif file is bigger.
You can optimize the gif file size by using below given command example

gifsicle -O2 linux-example.gif -o new_linux-example.gif

Now check the file size of newly created gif file by using command du -sh new_linux-example.gif

Given below sample is loop GIF image

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to convert rpm file into deb file
  2. Convert new line to space by using sed command
  3. convert space into new line using sed command
  4. How to see line numbers in file through cat command
  5. NOTICE: nagios.cmd file not found. Please specify the location of this file in your /etc/vshell.conf file
  6. Convert hyphen to underscore in between all filenames shell script
  7. How to convert float to integer number
  8. search keyword in file with line number using grep command
  9. How to zip the directory in linux with command line
  10. Eject Command: Eject DVD-ROM Or CD-ROM In Linux

Filed Under: Linux, Tips And Tricks Tagged With: gif

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to add/install Ubuntu fonts in CentOS/Red Hat Linux

Print double hyphen sign simultaneously in post of Octopress

Show visitor ip address php code

4 Different commands to find system uptime in linux

How to see system load average in terminal with graphical representation

Convert new line to space by using sed command

error could not configure a c compiler Linux

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy