sl33nyc
Posts: 3
Joined: Mon Apr 15, 2013 5:39 pm

JPEG Encoding Example

Mon Apr 15, 2013 6:00 pm

I've been hacking at the "hello_jpeg" example included in the Raspberry Pi firmware and am struggling with getting an "image_encode" example to work. I'm not an OpenMax IL expert, so it's been a miserable struggle. :? Can somebody help me with a simple C example of using the IL library to load an image file, modify it, and reencode it back to JPEG?

The motivation for this example is that I've been using a cheapo USB webcam with my Raspberry Pi, but the framerate is frankly miserable. I want to make a portable, WiFi enabled USB, like http://jeremyblythe.blogspot.com/2012/0 ... ebcam.html but faster.

I poked around the source code for http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome and https://code.google.com/p/mjpg-streamer/. Motion converts YUVY formatted frames to mjpeg but does so using the general CPU. mjpg-streamer can pull mjpg straight from the camera, but lacks Motion's ability to draw a timestamp on the frames.

I'm not sure if I care which webcam software I ultimately use, but I'd love to have timestamps on the frames but not at the expense of poor framerates. Should I even expect much better frame rates using OpenMax IL's image_encode library to do the YUVY to jpeg conversion outside of the general CPU?

Is it even possible to use the OpenMax IL JPEG encoder component (to use the framework's vernacular)? https://github.com/xbmc/xbmc/blob/maste ... XImage.cpp seems to imply use of the "image_encode" component for the Raspberry Pi, but I also had a terrible time applying that code to my use case.

I'd appreciate any thoughts, concerns, or heck, even words of encouragement.

ramosdavid2012
Posts: 8
Joined: Sun May 12, 2013 5:27 pm

Re: JPEG Encoding Example

Tue May 14, 2013 10:32 pm

Did you try with OpenCV?

Zinahe
Posts: 16
Joined: Sun Jan 29, 2012 11:56 pm

Re: JPEG Encoding Example

Tue Jul 23, 2013 4:12 pm

Hey sl33nyc,

Have you made any discoveries/progress on this topic by any chance ?

Cheers,

Zinahe A.

bbb
Posts: 55
Joined: Sat Jun 02, 2012 9:52 am

Re: JPEG Encoding Example

Tue Jul 23, 2013 9:44 pm

Strangely enough, I am just starting to code something like this up :) effectively I am after something with this pipeline: USB capture device or webcam -> Raspberry PI -> Motion JPEG -> RTP stream -> PC (running something like wirecast)

Just trying to get the 'image_fx' component to do the color-space / pixel format conversion AND de-interlacing and piping it into the 'image_encode' component to get JPEG image out.

Zinahe
Posts: 16
Joined: Sun Jan 29, 2012 11:56 pm

Re: JPEG Encoding Example

Wed Jul 24, 2013 3:47 am

bbb,

I suggest you get one of those el cheapo webcams that spit hardware based M-JPEG stream. (like a Logitech C250) Then you don't have about converting YUYV to JPEG, but focus on the h264 RTP stream instead.

Cheers,

bbb
Posts: 55
Joined: Sat Jun 02, 2012 9:52 am

Re: JPEG Encoding Example

Wed Jul 24, 2013 7:23 am

Zinahe wrote:bbb,

I suggest you get one of those el cheapo webcams that spit hardware based M-JPEG stream. (like a Logitech C250) Then you don't have about converting YUYV to JPEG, but focus on the h264 RTP stream instead.

Cheers,
Might think about that, didn't realise C250 was that cheap and did MJPEG. Will have to modify the webcam and remove the IR filter plus some sort of IR light, as need zero-lux capture (night vision). I already have some security cameras and USB capture devices ..

I already have h264 streaming working over udp in a mpegts container, but get around 5 seconds delay, and playback doesn't always start - and after a few attempts, not managed to stream h264 directly into RTP. Think I need to get the h264 video_encoder component into low latency / image capture mode so it outputs frames without any inter-dependency, but the documentation is not very good and I've not figured this out yet .. :( - Might start a new thread on this with my attempts and issues etc ..

Still going to see what image_fx + image_encode components can do - just for still JPEG capture to start with ..

Zinahe
Posts: 16
Joined: Sun Jan 29, 2012 11:56 pm

Re: JPEG Encoding Example

Fri Jul 26, 2013 8:45 pm

Yes. Below is the output of v4l2-ctl --list-formats on my C250.

ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUV 4:2:2 (YUYV)

Index : 1
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : MJPEG

Please let's know of your progress. I'm trying to do gpu based h264 streaming from an mjpeg based webcam.

Thanks.

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: JPEG Encoding Example

Wed Nov 13, 2013 7:55 pm

Hi with the help of this http://stackoverflow.com/questions/1271 ... am-to-file thread I got this gstreamer pipe and ammended a pipe i used for UDP streamer to VLC. It was about 0.5seconds lag but the stream get corrupted sometimes and causes iSpy to crash. MJPG is a nice solution because its stable and you can use almost any device to access the Pi and watch the stream. iSpy also like MPJPG allot.

Code: Select all

raspivid -t 999999 -h 720 -w 1080 -fps 5 -hf -b 1000000 -o - | gst-launch-1.0 fdsrc ! h264parse ! decodebin ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! multifilesink location=/tmp/img_%03d.jpeg
When i do this I get 80% cpu so that means the jpenc is running in CPU and not using openmax capabilities? I think?

Or something in that pipe is not correct. I tried various combinations but I get could not link h264parse to jpegenc, or whatever else i try.

Anu suggestions?

PS- Also here is a custom mjpg-streamer that has raspitsitll code built into the mjpg-streamer and the coder claims to get 8FPS. Not sure if its HD though. I could use compiled ffmpeg to dump jpg at 3~5fps at 640x480 but that was a bit rubbish quality @ 90% CPU.

https://github.com/jacksonliam/mjpg-streamer

pfmelamed
Posts: 4
Joined: Mon Aug 17, 2015 12:54 pm

Re: JPEG Encoding Example

Tue Sep 08, 2015 9:44 am

hi sl33nyc

Do you have any code for JPEG encoder using the IL library (or OpenOMX)?

Can somebody help me with a simple C example of using the IL library to load an image file (YUV420), modify it, and encode it to JPEG?

Any example ?

Tanks
PF

pfmelamed
Posts: 4
Joined: Mon Aug 17, 2015 12:54 pm

Re: JPEG Encoding Example

Tue Sep 08, 2015 1:09 pm

Hi

Can somebody give me the programme flow chart for jpeg encoding PLEASE:
What I am doing is :
bcm_host_init();
OMX_Init();
OMX_GetHandle();
/* Disable all the ports */
/* set port parameters */
/* Enable all the ports */
/*go to the StateIdle */ at this stage the programme is locked....

what is my BUG? please
PF

Return to “C/C++”