Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old April 6th, 2008   #1
tpp
First Cup of Ubuntu
 
Join Date: Aug 2006
Beans: 2
HOW-TO: Convert a video on youtube to animated gif

Hi, I don't know if people still use animated gifs at all but I see them used on forums etc. I just wanted to make one and found that the other guides out there didn't get me quite what I wanted. I.e. it wasn't easy to select the exact frames I wanted with mplayer and the other guides seem to use all the frames which can be bulky and slow. I've found this worked well and just wanted to write it up in case I ever want to do it again.

# Youtube to animated gif HOW-TO:

1) Download youtube-dl (http://www.arrakis.es/~rggi3/youtube-dl/). Run the youtube-dl to rip the video from Youtube into flash video format:

./youtube-dl -o example.flv "http://www.youtube.com/watch?v=cdaAWFoWr2c"

2) Convert the flash video format into an avi:

ffmpeg -i example.flv example.avi


3) Launch avidemux (sudo apt-get it first) and open the avi file you just created, select the range of frames you want to rip from the avi using the 'A' and 'B' buttons at the bottom, then go to File->Save->Save Selection As jpeg Images and save the images into a new directory.

4) Now this step is optional, but I have found that including all the frames in the gif will make it too large and it will also look slow. I found a rather hacky way around this by writing a perl script to remove frames. Create a new file in a text editor called 'chop.pl' in the same directory of the images. Copy and paste the following into it, changing the variables for youself:

#!/usr/local/bin/perl
# start_frame should be the smallest number in the filenames of the jpegs e.g example0000.jpg
$start_frame = 0000;
# end_frame should be the largest number in the filenames of the jpegs e.g example1855.jpg
$end_frame = 1855;
# scaling factor is how many frames you want to remove, 5 for example will remove 4/5's of the frames
$scaling_factor = 5;
# name should be the string appearing in the filenames of the jpegs before the numbers
$name = "example";

# Compute number of digits needed to display number
use POSIX;
$width = floor(log10($end_frame))+1;

# Remove frames
for ($i = $start_frame; $i <= $end_frame; ++$i)
{
$str = sprintf("%04d", $i);

$check = $i % $scaling_factor;
if($check != 0) {
system("rm $name$str.jpg");
}
}

5) Execute the script:

perl chop.pl

6) Open up GIMP and open the first jpeg in the series. Go to File->Open As Layers and select the rest of the series. Now go to Filters->Animation->Optimize For Gif. And then save the thing as a gif and enabled animation and voila.
tpp is offline   Reply With Quote
Old April 8th, 2008   #2
Six_Digits
Gee! These Aren't Roasted!
 
Six_Digits's Avatar
 
Join Date: Oct 2007
Location: /home
My beans are hidden!
Ubuntu 7.10 Gutsy Gibbon
Send a message via AIM to Six_Digits
Re: HOW-TO: Convert a video on youtube to animated gif

Thank you!
__________________
- Dell XPS 410 - Intel Core 2 @ 2x2.6 - 6gb RAM - 250GB HD -Nvidia 8600GTS | Ubuntu 9.04

Six_Digits is offline   Reply With Quote
Old May 14th, 2008   #3
spo0neybard
5 Cups of Ubuntu
 
spo0neybard's Avatar
 
Join Date: Feb 2008
Beans: 18
Re: HOW-TO: Convert a video on youtube to animated gif

For those who think "Oh my gosh,
I have to import all those images
as layers one by one! Highlight the images
then just click and drag them into the layers
box. (Dialogs > Layers)
__________________
One word you don't want to hear during an operation?
HEY WHAT'S THAT
spo0neybard is offline   Reply With Quote
Old September 26th, 2008   #4
theaceoffire
5 Cups of Ubuntu
 
Join Date: May 2007
Beans: 38
Re: HOW-TO: Convert a video on youtube to animated gif

I would suggest the Phatch Photo Batch Processor for reducing size, changing resolution, etc.

^_^ Took me *forever to figure this out, thanks for the post!
theaceoffire is offline   Reply With Quote
Old August 15th, 2009   #5
dopple
Just Give Me the Beans!
 
dopple's Avatar
 
Join Date: Aug 2007
Location: Edinburgh, Scotland
Beans: 72
Ubuntu 8.10 Intrepid Ibex
Re: HOW-TO: Convert a video on youtube to animated gif

You the man. I've been having problems with the "extract video range" feature and this has solved my problem> Wish I'd seen this post 2 days ago.
dopple is offline   Reply With Quote
Old September 9th, 2009   #6
BassKozz
Dipped in Ubuntu
 
BassKozz's Avatar
 
Join Date: Jun 2007
Beans: 600
Ubuntu 9.10 Karmic Koala
Re: HOW-TO: Convert a video on youtube to animated gif

Thanks for the post, but I am having trouble using your perl script.
I get the following error when I run it:
Quote:
Illegal octal digit '9' at chop.pl line 5, at end of line
BEGIN not safe after errors--compilation aborted at chop.pl line 12
Here is what the script looks like.
Code:
#!/usr/local/bin/perl
# start_frame should be the smallest number in the filenames of the jpegs e.g example0000.jpg
$start_frame = 0003;
# end_frame should be the largest number in the filenames of the jpegs e.g example1855.jpg
$end_frame = 0480;
# scaling factor is how many frames you want to remove, 5 for example will remove 4/5's of the frames
$scaling_factor = 5;
# name should be the string appearing in the filenames of the jpegs before the numbers
$name = "AG";

# Compute number of digits needed to display number
use POSIX;
$width = floor(log10($end_frame))+1;

# Remove frames
for ($i = $start_frame; $i <= $end_frame; ++$i)
{
$str = sprintf("%04d", $i);

$check = $i % $scaling_factor;
if($check != 0) {
system("rm $name$str.jpg");
}
}
EDIT:
Nevermind, I figured it out, I just had to remove the 0 from 0480, so now the line reads:
Code:
$end_frame = 480;
And it worked
Thanks !
__________________
Ubuntu 9.10 64-bit - IP35-Pro | Q6600@3.3ghz(TRUE [lapped]) | G.Skill 2x2GB | MSI NX8600GT | 150GB WD Raptor ||| NAS - Ubuntu 9.04 - Intel D865GBF | P4 3.0GHz | G.Skill 4x1GB | FX5200-AGP | 3x250GB mdadm Raid5 | 200GB OS

Last edited by BassKozz; September 10th, 2009 at 12:38 AM..
BassKozz is offline   Reply With Quote
Old September 27th, 2009   #7
strAlan
May the Ubuntu Be With You!
 
strAlan's Avatar
 
Join Date: Apr 2007
Location: Stay thirsty, my friends.
Beans: 1,706
Ubuntu 9.10 Karmic Koala
Send a message via AIM to strAlan Send a message via MSN to strAlan Send a message via Yahoo to strAlan Send a message via Skype™ to strAlan
Re: HOW-TO: Convert a video on youtube to animated gif

Nice thread! Too bad you aren't a regular - 2 beans +1 for you.
strAlan is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:59 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry