![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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. |
|
|
|
|
|
#2 |
|
Gee! These Aren't Roasted!
![]() |
Re: HOW-TO: Convert a video on youtube to animated gif
Thank you!
|
|
|
|
|
|
#3 |
|
5 Cups of Ubuntu
![]() 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 |
|
|
|
|
|
#4 |
|
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! |
|
|
|
|
|
#5 |
|
Just Give Me the Beans!
![]() 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.
|
|
|
|
|
|
#6 | |
|
Dipped in Ubuntu
![]() 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:
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");
}
}
Nevermind, I figured it out, I just had to remove the 0 from 0480, so now the line reads: Code:
$end_frame = 480; 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.. |
|
|
|
|
|
|
#7 |
|
May the Ubuntu Be With You!
![]() |
Re: HOW-TO: Convert a video on youtube to animated gif
Nice thread! Too bad you aren't a regular - 2 beans
__________________
Gigabyte GA-MA785GM-US2H | nVidia XFX 9600 | 4 GB Memory | 1TB WD SATA II | Karmic 64 | Thinkpad T60 Hardy 32 | Registered User #482494 |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|