LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-29-2017, 03:49 PM   #1
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,959

Rep: Reputation: 271Reputation: 271Reputation: 271
Find the number of frames in a GIF; fetch the last one


I want to find the number of frames in a GIF then fetch the last one. For reference, my test file is:

Code:
https://media.newyorker.com/cartoons/5a3d99a75e8c9840cf254750/master/+w_1626,c_limit/DC122717.gif
I used imagemagick; it took 15 minutes to count the number of frames; it took 16 minutes to extract the last one. In both cases it used most of the disk's access: it has to inspect every single frame, creating an 8 MB temporary file for each. The test file has 149 frames.

Someone asked at https://sourceforge.net/p/giflib/mai...sage/35255030/ last year, never got a response.

I just read the spec: I don't see a frame count in the header. GIF wasn't invented to handle animation, as earlier docs note.

I extracted the first frame, then divided the file size by its size, but frames are of such varying size that didn't work.
 
Old 12-29-2017, 05:58 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
https://linux.die.net/man/1/gifview
 
Old 12-29-2017, 06:25 PM   #3
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Opening the gif in GIMP will assign a layer for each frame. The Layers window will show a count of these and allow you to extract whichever frame you want. However, this will work less well if the gif has not been constructed with a full image per frame.
 
Old 12-30-2017, 04:09 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
gifview looks good.

also gimp - probably the best solution, because you don't really want the last frame, but the full image you see at the last frame, correct?

but still, check out gifsicle, esp. --explode and --unoptimize.
 
2 members found this post helpful.
Old 12-30-2017, 07:53 AM   #5
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Just for info, gifview is part of the gifsicle package.

https://www.lcdf.org/gifsicle/
 
1 members found this post helpful.
Old 12-30-2017, 03:10 PM   #6
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,959

Original Poster
Rep: Reputation: 271Reputation: 271Reputation: 271
python-pillow's explode.py extracts individual frames in a jiffy; gifbuild returns a count quickly.

I don't want to interact with the GIF but append a caption automatically when a crontab job picks up the cartoon, to add a caption. ImageMagick's convert appends all the frames then the caption - not what I want.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script: find how many times the first number is paired with the second number slufoot80 Linux - Newbie 5 05-11-2013 04:31 PM
Parse log file for errors and fetch variable number of lines before and after error jgm27 Linux - Newbie 4 07-18-2012 05:26 PM
Number of recieved frames can be held in system? nandac Linux - Networking 0 10-09-2007 06:06 AM
how to get number of frames or time from a vob (dvd-mpeg2 video) schneidz Programming 3 03-23-2007 03:40 AM
in knode how do i set number of headers to fetch? babag Linux - Software 0 01-18-2004 03:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration