windy54
Posts: 86
Joined: Sat Dec 29, 2012 3:37 pm

Can't capture gif image with picamera

Mon May 12, 2014 1:18 pm

Hi,

I have been using example 4.1 from picamera read the docs to capture a JPEG file, this works. When I change the file extension to gif I just get a black image.

I can capture a gif image using raspistill .

I have just updated to the latest version of picamera ,1.4 and this has not solved the problem.

Does anyone know if this is an issue with picamera or am I missing an option.

import time
import picamera

with picamera.PiCamera() as camera:
camera.resolution = (1024, 768)
camera.start_preview()
# Camera warm-up time
time.sleep(2)
camera.capture('foo.jpg')

I have just been replacing jpg in the last line above with gif.

User avatar
R61zt
Posts: 65
Joined: Fri Feb 01, 2013 3:55 pm

Re: Can't capture gif image with picamera

Mon May 12, 2014 3:27 pm

Don't use gif. That format is so very Windoze 3.1. You might want to look at whether .png will do what you want. I realise that not every photo is of clouds and hedgerows best suited to .jpg. If you can do .png then unless you are writing a script to hack Netscape 1.0 that should do everything that you'd need.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26442
Joined: Sat Jul 30, 2011 7:41 pm

Re: Can't capture gif image with picamera

Mon May 12, 2014 5:10 pm

PNG will also compress better than GIF (Although GIF isn't necessarily a 'Windows' format). But JPEG is the only HW accelerated format, so will always be faster than the others.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8739
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Can't capture gif image with picamera

Mon May 12, 2014 5:43 pm

And JPEG is natively in the YUV domain whereas PNG and GIF are RGB formats, so we have to do a format conversion as well as encoding it.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't capture gif image with picamera

Mon May 12, 2014 10:22 pm

R61zt wrote:Don't use gif. That format is so very Windoze 3.1.
It wasn't Microsoft, it was Compuserve back in 1987 in the days of 300 & 1200/75 baud modems. GIF87 was a very small format for quite a lot of picture data.

GIF is quite interesting. It uses a reduced RGB palette (max 256 colours), it includes lossless LZW compression (hence the problem with Burroughs/Unisys holding that patent).

I wrote a REXX program that generated a single pixel GIF. It's 26 bytes of data

Code: Select all

000000 47 49 46 38 39 61 01 00 01 00 00 ff 00 2c 00 00  >GIF89a.......,..<
000010 00 00 01 00 01 00 00 02 00 3b                    >.........;<
00001a
it was in a home grown web server that simply returned that GIF for every HTTP GET request (don't ask why).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

ethanol100
Posts: 637
Joined: Wed Oct 02, 2013 12:28 pm

Re: Can't capture gif image with picamera

Tue May 13, 2014 6:30 am

Back to the original question, have you only changed the file extension in the capture command? You could need to set the format. Can you try to add format='gif' to the capture command?

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Can't capture gif image with picamera

Tue May 13, 2014 7:56 am

R61zt wrote:Don't use gif. That format is so very Windoze 3.1.
Yes gif is old and has a tiny 256 colour palette,
but is still the best supported format for small animations.
There's animated PNG variants, MNG and APNG but neither took off.
I don't see any point in GIFs for stills though.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

Return to “Camera board”