maxan
Posts: 4
Joined: Fri Feb 15, 2013 3:37 pm

Re: OpenMAX: How to decode a JPEG (example source code)

Thu Apr 04, 2013 9:33 pm

Sorry if this is a bit off-topic.

I see that Matt Ownby and Anthong Sale's jpeg.c code made it into the userland repository. In the transition, I see that the file header's license changed from
" * You are free to use this for educational/non-commercial use"
to a more permissive boilerplate BSDish-style license. Was this a deliberate change sanctioned by the original authors?

I'm just trying to determine if the code is suitable for my use. Thanks.

Danara
Posts: 13
Joined: Mon Dec 31, 2012 8:12 pm
Location: Ottawa Canada

Re: OpenMAX: How to decode a JPEG (example source code)

Sat Apr 20, 2013 8:46 pm

bbond007 wrote: Thanks Dan!

I should have mentioned that my images are very small to begin with (thumbnails from YouTube) and then I'm further downsizing them even smaller. I think around 88x75 how I have my settings now.

Seems like, in my program, the libjpeg version (with fast integer re-sizer) is fastest, and reliable.

The the cpp version is still pretty fast with occasional timeouts and segfaults.

The c (ilclient) version is the slowest and tends to stall. I have experimented with the various sleep intervals. Maybe the constant resizer EOS error is also causing the slowdown.

I'm not so sure that using the hardware jpeg decoding is best option for me.

Perhaps, maybe, its a little like driving to the airport, parking, going through TSA, getting on plane, loosing luggage, etc... when my destination is only 50 miles away.
Sorry for the late reply -- I was sure I had replied already, but when I went back to this thread, I don't see it. In any case, I've learned a few things that might help.
  • When filling the buffer for image_decode, don't send more than one jpeg to the buffer at the time (especially for small images). This is the reason why my earlier code had trouble with smaller JPEGs.
  • For better performance on larger images, increase the buffer size to be greater than the size of your JPEG. The default size on my system seems to be around 80KB, and I increase that to 250KB, which means the entire JPEG fits in the image decode input buffer 99.99% of the time.
  • Set the flag OMX_BUFFERFLAG_ENDOFFRAME and OMX_BUFFERFLAG_EOS before the call to EmptyThisBuffer. Without the end of frame flag, the frame doesn't get forwarded to the video_render / egl_render (so the output stalls).
This is done in a thread in my code, which is about 200 lines of C. The biggest part of that is setting up the OMX pipeline. Once that is done, each JPEG is processed in about 20 lines of code, most of which is spent getting the next JPEG from a linked list (which is populate in another thread). It is very reliable now for JPEGs of any size, and uses almost none of the arm CPU.

bbond007
Posts: 73
Joined: Sun Nov 04, 2012 6:10 pm

Re: OpenMAX: How to decode a JPEG (example source code)

Thu Apr 25, 2013 12:50 am

Danara wrote:
  • When filling the buffer for image_decode, don't send more than one jpeg to the buffer at the time (especially for small images). This is the reason why my earlier code had trouble with smaller JPEGs.
  • For better performance on larger images, increase the buffer size to be greater than the size of your JPEG. The default size on my system seems to be around 80KB, and I increase that to 250KB, which means the entire JPEG fits in the image decode input buffer 99.99% of the time.
  • Set the flag OMX_BUFFERFLAG_ENDOFFRAME and OMX_BUFFERFLAG_EOS before the call to EmptyThisBuffer. Without the end of frame flag, the frame doesn't get forwarded to the video_render / egl_render (so the output stalls).
I'm only calling with one image at a time. like so:

static OPENMAX_JPEG_DECODER * OMXDecoder = NULL;
// if(OMXDecoder == NULL)
OpenMaxJPEG_setupDecoder(&OMXDecoder);
OpenMaxJPEG_decodeImage(OMXDecoder, (char *) buf, bufSize, outputWidth, outputHeight);
vgImage = vgCreateImage(rgbaFormat, outputWidth, outputHeight, VG_IMAGE_QUALITY_BETTER);
vgImageSubData(vgImage, &OMXDecoder->pOutputBufferHeader->pBuffer[stStride * (outputHeight)], stStride * -1, rgbaFormat, 0, 0, outputWidth, outputHeight);
OpenMaxJPEG_cleanup(OMXDecoder);

not sure I understand what you are saying about the flags...

I tried changing this line https://github.com/bbond007/raspytube/b ... max.c#L470

from:

pBufHeader->nFlags =0;
if(toread <= 0)
{
pBufHeader->nFlags = OMX_BUFFERFLAG_EOS;
}

to :


if(toread <= 0)
pBufHeader->nFlags = OMX_BUFFERFLAG_EOS | OMX_BUFFERFLAG_ENDOFFRAME;
else
pBufHeader->nFlags =0;

also, do i need to keep calling OpenMaxJPEG_setupDecoder(&OMXDecoder); & OpenMaxJPEG_cleanup(OMXDecoder) or can I do that once, decode a bunch of images, etc...

so far OMX_BUFFERFLAG_ENDOFFRAM did not seem to help.

thanks

bharath222
Posts: 1
Joined: Thu Apr 25, 2013 5:55 am

Re: OpenMAX: How to decode a JPEG (example source code)

Thu Apr 25, 2013 6:08 am

Hi,

I am trying to decode mjpg stream of a network camera using OpenMax jpeg decoder.
The stream is of resolution 640 x 480 @ 30fps. This stream runs and decodes properly for few minutes i can say approimately for 15 minutes. Later I get time out exception from the below line of code.

Code: Select all

IEventSptr ev = m_pCompDecoder->WaitForEventOrEmpty(OMX_EventPortSettingsChanged, m_iOutPortDecode,0,pBufHeader, TIMEOUT_MS);
can anyone please help me in getting the mjpg stream run continuously for long hours?
Help will be greatly appreciated.

Thanks,
Bharath

MattOwnby
Posts: 58
Joined: Thu Aug 16, 2012 7:22 pm

Re: OpenMAX: How to decode a JPEG (example source code)

Tue May 07, 2013 5:38 pm

maxan wrote:Sorry if this is a bit off-topic.

I see that Matt Ownby and Anthong Sale's jpeg.c code made it into the userland repository. In the transition, I see that the file header's license changed from
" * You are free to use this for educational/non-commercial use"
to a more permissive boilerplate BSDish-style license. Was this a deliberate change sanctioned by the original authors?

I'm just trying to determine if the code is suitable for my use. Thanks.
Yes, I approved this licensing change.

MattOwnby
Posts: 58
Joined: Thu Aug 16, 2012 7:22 pm

Re: OpenMAX: How to decode a JPEG (example source code)

Tue May 07, 2013 6:07 pm

Danara wrote:
  • When filling the buffer for image_decode, don't send more than one jpeg to the buffer at the time (especially for small images). This is the reason why my earlier code had trouble with smaller JPEGs.
  • For better performance on larger images, increase the buffer size to be greater than the size of your JPEG. The default size on my system seems to be around 80KB, and I increase that to 250KB, which means the entire JPEG fits in the image decode input buffer 99.99% of the time.
  • Set the flag OMX_BUFFERFLAG_ENDOFFRAME and OMX_BUFFERFLAG_EOS before the call to EmptyThisBuffer. Without the end of frame flag, the frame doesn't get forwarded to the video_render / egl_render (so the output stalls).
Excellent! I was wondering if one could increase the buffer size but I never tried it. Great find!

Skinkie
Posts: 18
Joined: Sat Sep 15, 2012 8:18 am

Re: OpenMAX: How to decode a JPEG (example source code)

Mon May 27, 2013 4:44 pm

So which code controls the buffer that should be increased from 80kb -> 250kb? I'm trying to display 1920x1080 images. hello_jpeg, doesn't complain, but when I try to implement something that shows the images I get the magic:

Width: 1920 Height: 1080 Output Color Format: 0x7f000001 Buffer Size: 8355840
No EOS event on image decoder -1
No EOS event on image resizer -1

I have now also tried a smaller file of only 32kb. But decoding waits for ever...

Skinkie
Posts: 18
Joined: Sat Sep 15, 2012 8:18 am

Re: OpenMAX: How to decode a JPEG (example source code)

Mon May 27, 2013 10:22 pm

I have figured out that it is of critial importance to have the definitions of the Makefile.include in my project. With them the only EOS I get is in resizer on too small images. I hope this helps others later.

Code: Select all

gcc   -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -Wno-deprecated-declarations
My original question is still: where to enlarge the buffer. It takes a few seconds to show an image on the screen of 1920x1080 using the GPU pipeline. I am under the impression that it is faster when doing it with CPU libjpeg.
Last edited by Skinkie on Mon May 27, 2013 11:20 pm, edited 1 time in total.

Skinkie
Posts: 18
Joined: Sat Sep 15, 2012 8:18 am

Re: OpenMAX: How to decode a JPEG (example source code)

Mon May 27, 2013 11:18 pm

Getting the JPEG variant working, I wondered if I could just replace OMX_IMAGE_CodingJPEG in OMX_IMAGE_CodingAutoDetect and get a universal image display program.

Call me naive but that didn't work; neither did replacing it by OMX_IMAGE_CodingPNG and opening a PNG file instead. The output is blank, but the terminal actually shows more: Width: 1920 Height: 1080 Output Color Format: 0x7f000001 Buffer Size: 8355840 (similar to the JPEG version).

Why isn't this just working?

pathwalker
Posts: 3
Joined: Tue May 07, 2013 4:54 am

Re: OpenMAX: How to decode a JPEG (example source code)

Fri Jun 14, 2013 2:48 am

I am experiencing blank screen. The only message showing is,

Width: 1620 Height: 1080 Output Color Format: 0x7f000001 Buffer Size: 7102464

The RPi is connect through a converter from HDMI to DVI to my screen. As far as I know, I can see all the boot my message from the screen. So the converter is not an issue.
I have no problem running hello_teaport, hello_triangle, .. etc

Is there anything I am missing out? Appreciate if anyone can give me a pointer. Thank you.

Cheers,
walker

Thaddy
Posts: 174
Joined: Wed Mar 06, 2013 11:28 am

Re: OpenMAX: How to decode a JPEG (example source code)

Sun Jun 16, 2013 12:10 pm

Swap the includes for the EGL and Gles2 libraries.
Make sure BCM_init is called first.

cmarty
Posts: 38
Joined: Thu Jul 19, 2012 7:23 am
Location: Czech Republic

Re: OpenMAX: How to decode a JPEG (example source code)

Mon Jun 17, 2013 9:08 am

I have also problem to display any jpeg image with jpeg.c example. The program just shows
./hello_jpeg.bin 001.jpg
Did not receive executing stat -1
Width: 1024 Height: 681 Output Color Format: 0x7f000001 Buffer Size: 2818048

or
./hello_jpeg.bin wooden-house.jpg
Did not receive executing stat -1
Width: 480 Height: 360 Output Color Format: 0x7f000001 Buffer Size: 706560
No EOS event on image decoder -1
and no image on output.
I'm working with the latest updated & upgraded raspiban image.

flo35
Posts: 5
Joined: Tue Jun 04, 2013 8:51 am

Re: OpenMAX: How to decode a JPEG (example source code)

Wed Jul 10, 2013 9:58 am

UP

How use hello_jpeg and omxplayer for displaying image JPEG.
I don't understand the process ;)

THX

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

Re: OpenMAX: How to decode a JPEG (example source code)

Wed Jul 10, 2013 11:32 am

flo35 wrote:UP

How use hello_jpeg and omxplayer for displaying image JPEG.
I don't understand the process ;)

THX
If you just want to display a JPEG

Code: Select all

sudo apt-get install fbi

fbi [imagename]
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

flo35
Posts: 5
Joined: Tue Jun 04, 2013 8:51 am

Re: OpenMAX: How to decode a JPEG (example source code)

Wed Jul 10, 2013 10:04 pm

OK i test this application tomorrow ;)

Have you a beautiful Makefile for cross-compile the source package ?? I prefer !

THX

flo35
Posts: 5
Joined: Tue Jun 04, 2013 8:51 am

Re: OpenMAX: How to decode a JPEG (example source code)

Thu Jul 11, 2013 2:38 pm

'apt-get install fbi' is OK and i'm display jpeg file;

Now i want to cross-compile fbida-2.09.tar.gz

but my Makefile don't runnning

Have you an example of Makefile for Raspberry ??

THX

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

Re: OpenMAX: How to decode a JPEG (example source code)

Tue Oct 29, 2013 3:28 pm

I've also had problem figuring out this example (both from /opt/vc/src/... and the userland repo). Cannot find the fwrite quoted in messages above, so not sure what the example actually does. I wonder if there has been a regression in the code somewhere.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

papalukas
Posts: 8
Joined: Fri Jan 17, 2014 9:22 pm

Re: OpenMAX: How to decode a JPEG (example source code)

Fri Jan 17, 2014 9:30 pm

I have figured out that it is of critial importance to have the definitions of the Makefile.include in my project. With them the only EOS I get is in resizer on too small images. I hope this helps others later.

CODE: SELECT ALL
gcc -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -Wno-deprecated-declarations
Great thanks! Spent a bunch of sleepless nights trying to find out what's wrong am I doing. The suggestion helps. :D
For small images (smaller than a size of a single buffer) I've got a workaround - when calling OMX_EmptyThisBuffer set the nFilledLen field to nAllocLen, not the length of an image. Works for me. (Don't be tempted to set nFilledLen like this for the last buffer of a big image - it will break everything!)

Return to “C/C++”