Animated Gif/Movie object shifting

All your problems with Audio, Video and Images.

Animated Gif/Movie object shifting

Postby azraeal » Sat Oct 10, 2009 1:58 am

I'll get started by stating this isn't the "How do I render animated gif" request.

So I have my animated gif mostly working but here's the problem. On some of the gif's, the resulting image is skewed (see attached image).

I thought it had something to do with the framerate of the gif, but changing that did nothing to alleviate this. I also tried to confirm the width/height of the gif against internal metrics and they match as well. Which is confounding because it's obvious there's wrapping being done on the image and the result is 1 pixel thinner (causing the wrap and shifting image). Any suggestions, either in code or in photoshop/gimp, to fix this?

I've attached the result I'm getting (on 1.6) and the source gif file.

And for the inevitable "how do I make animated gif" requests:
It's in Google API examples under graphics.BitmapDecode.java
Attachments
c.gif
(1.49 MiB) Downloaded 82 times
Capture.JPG
Capture.JPG (26.96 KiB) Viewed 1124 times
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Top

Postby azraeal » Thu Oct 15, 2009 10:36 pm

I've found the cause of this problem.
The brief version is: incorrect GIF stream parsing internal to android.

Detailed version:
Animated GIF is just a frame animation. However, in the gif I've attached, the subsequent frames ARE NOT THE SAME SIZE as the original frame. While the whole gif (first frame) is 250x242, subsequent frames start drawing from (1,1) down to (248,240). Android parses ALL frames as 250x242 based on the first frame and draws pixels from (0,0) to (250x242). Now, with the decidedly lack of several hundred pixels in the subsequent frames, this causes one frame to bleed into another and for one row to bleed into the next(or previous).

Workaround: Fix the gif.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby gladish » Wed Nov 18, 2009 5:37 am

I think I have the same problem. When the gif displays, it looks ok, as soon as I start calling setTime() on the Movie to begin animation, it's all shifted. Not reading from proper offsets would make sense. I'm not familiar with working with gimp, etc. How do I tell if I have an animated gif with varying frame sizes, and if I do, how I "fix it".


azraeal wrote:I've found the cause of this problem.
The brief version is: incorrect GIF stream parsing internal to android.

Detailed version:
Animated GIF is just a frame animation. However, in the gif I've attached, the subsequent frames ARE NOT THE SAME SIZE as the original frame. While the whole gif (first frame) is 250x242, subsequent frames start drawing from (1,1) down to (248,240). Android parses ALL frames as 250x242 based on the first frame and draws pixels from (0,0) to (250x242). Now, with the decidedly lack of several hundred pixels in the subsequent frames, this causes one frame to bleed into another and for one row to bleed into the next(or previous).

Workaround: Fix the gif.
gladish
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 18, 2009 5:32 am

Postby azraeal » Wed Nov 18, 2009 7:56 pm

gladish wrote:I think I have the same problem. When the gif displays, it looks ok, as soon as I start calling setTime() on the Movie to begin animation, it's all shifted. Not reading from proper offsets would make sense. I'm not familiar with working with gimp, etc. How do I tell if I have an animated gif with varying frame sizes, and if I do, how I "fix it".


I'm not an expert in gimp or photoshop so I can't tell you exactly how to fix the problem. But I can tell you the process to diagnose it. This requires knowledge of HEX. Download any number of hex editors and open your gif with it.

The full binary definition of an animated GIF can be found here: http://en.wikipedia.org/wiki/Gif#Animated_.gif

Do a search (in HEX) of the following values: 21 F9 04. This value indicate the start of each frame.
Scan forward 6 bytes (each byte is 2 HEX) to get to 2C
The next 8 Bytes determine the drawing 'scan' range. The values are stored in Little-Endian, so it is stored in reverse byte order. So in the wikipedia example, 400 decimal is 01 90 HEX, but represented as 90 01 in the binary (spaces added for clarity). This is where you can determine if each frame is the same size. If they are not, Android screws it up similar to the above screenshot I've posted.


I guess how you can fix this is to crop everything down to the smallest frame's size.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby gladish » Thu Nov 19, 2009 1:37 am

I have the same problem. I'm not a media conversion expert. This seems to be a skill that you have to pick up if you're doing any multimedia on android.

I did manage to use gimp and resize the "layers" or frames to be of the same size as the first frame. It plays as a movie now, but is really bad looking. After further inspection, I noticed that the first frame is a full image whereas each subsequent frame looks like a mask of some sort. This is apparently some size optimization that nimated gif supports. It's a major headache. I'm going to try the route of converting the animated gif into an mpeg. I guess the bottom line is that support for animated gifs is limited at best utilizing the Movie class. Would be nice if someone put together an AnimatedGifView.
gladish
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 18, 2009 5:32 am

Postby gladish » Fri Nov 20, 2009 5:07 pm

I finally got this to work using an animation resource instead of the Movie class. I had to "unoptimize" the gif, and extract all the frame into individual gif files. At this point I guess you could convert into .png, but since my animation has 33 frames, I left them as gifs. I then used the animation resource as shown here:

http://developer.android.com/guide/topi ... -animation

Another very useful tool work extracting the frames from an animated gif file.

http://www.lcdf.org/gifsicle/
gladish
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 18, 2009 5:32 am

Top

Re: Animated Gif/Movie object shifting

Postby Nike » Wed Jul 14, 2010 1:00 pm

You can resize and create your animated avatar using Video Avatar.Also convert video to gif. It's really cool programm!
Nike
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jul 14, 2010 12:56 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 9 guests