lagurus
Posts: 49
Joined: Wed Aug 07, 2013 8:02 am

Re: Encoding Video & Taking Stills

Mon Aug 26, 2013 1:34 pm

I have tried to modify RaspiVid.c to take stills,in modification is video and still encoders created and ports connected without any erros. Video is taken but when is for first time called function to take stills:
mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1)
is video stream stoped (callback doesn't receive anything new). Taking images continue without problems.

Have someone similiar experience and find any solution?

pbill
Posts: 31
Joined: Fri Oct 26, 2012 12:01 pm

Re: Encoding Video & Taking Stills

Mon Sep 16, 2013 1:45 am

lagurus> Great to hear you've attempted to get this working. I'm sorry to hear you're running into the same issues. I've not been able to solve this, nor do I believe have others on the board.

Is this simply not going to be possible?

I've tried, as mentioned previously, some varied hack-ish solutions, though even the full-resolution capturing with preview fails when not displaying through HDMI.

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

Re: Encoding Video & Taking Stills

Mon Sep 16, 2013 7:52 am

It should be possible, we can do it elsewhere, but there is the possibility that the code to do it hasn't made it to the Raspberry Pi codebase from the mainline code tree here at Broadcom. I need to find some time to look at this, but am very busy elsewhere at the moment.
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.

lagurus
Posts: 49
Joined: Wed Aug 07, 2013 8:02 am

Re: Encoding Video & Taking Stills

Mon Oct 07, 2013 12:15 pm

I still don't have any progress with writing video and taking stills (on still/capture port) at the same time.

But I bypass it when I misuse preview port from which directly take uncompressed data (using callback on preview port) copy them and use another thread to write data to disk/analyze image. Disadvantage is max. 1920x1080 resolution but for purposes is it enough.

pbill
Posts: 31
Joined: Fri Oct 26, 2012 12:01 pm

Re: Encoding Video & Taking Stills

Wed Nov 06, 2013 7:40 pm

lagarus - that's wonderful! That sounds like exactly what I had hoped to do.

Are you able to share the code? I've made multiple attempts, however I can't seem to get the preview port to return any data (typically I end up with a hard lock).

Would be most appreciated!

lagurus
Posts: 49
Joined: Wed Aug 07, 2013 8:02 am

Re: Encoding Video & Taking Stills

Fri Nov 08, 2013 4:01 pm

In attachment is simple modification of raspivid.c (RaspiVid_Resize.c) which create H264 video as usual and on preview port is connected resizer and callback. Callback on resizer do nothing - just show info about incoming frame, images are resized to 320x240, no preview is showed. Similar it should work directly on preview port, but now I don't have any handy example.

Hope this helps.
pbill wrote:lagarus - that's wonderful! That sounds like exactly what I had hoped to do.

Are you able to share the code? I've made multiple attempts, however I can't seem to get the preview port to return any data (typically I end up with a hard lock).

Would be most appreciated!
Attachments
raspivid_resize.tar.gz
(13 KiB) Downloaded 119 times

pbill
Posts: 31
Joined: Fri Oct 26, 2012 12:01 pm

Re: Encoding Video & Taking Stills

Mon Nov 11, 2013 4:16 pm

Excellent! Thank you.

It compiles, and with a few modifications I'm getting files that are 115,200 bytes in length. Seems to match up with the expectations for 320x240 resolution.

Thought this might be in YUV422P format, but that doesn't seem to work when trying to convert as a test from FFMPEG. Still working on aspect, but very happy to have output from the preview port in any format!

lagurus
Posts: 49
Joined: Wed Aug 07, 2013 8:02 am

Re: Encoding Video & Taking Stills

Mon Nov 11, 2013 8:50 pm

Output format is MMAL_ENCODING_I420, can be simple change in resizer component. But it looks that not all
encoding format defined in mmal_encodings.h are supported. E.g. for change to RGB try to define encoding format for resizer output as:

Code: Select all

format->encoding = MMAL_ENCODING_RGBA;
or

Code: Select all

format->encoding = MMAL_ENCODING_RGB16;


pbill wrote:Excellent! Thank you.

It compiles, and with a few modifications I'm getting files that are 115,200 bytes in length. Seems to match up with the expectations for 320x240 resolution.

Thought this might be in YUV422P format, but that doesn't seem to work when trying to convert as a test from FFMPEG. Still working on aspect, but very happy to have output from the preview port in any format!

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

Re: Encoding Video & Taking Stills

Mon Nov 11, 2013 10:04 pm

lagurus wrote:Output format is MMAL_ENCODING_I420, can be simple change in resizer component. But it looks that not all
encoding format defined in mmal_encodings.h are supported. E.g. for change to RGB try to define encoding format for resizer output as:

Code: Select all

format->encoding = MMAL_ENCODING_RGBA;
or

Code: Select all

format->encoding = MMAL_ENCODING_RGB16;


pbill wrote:Excellent! Thank you.

It compiles, and with a few modifications I'm getting files that are 115,200 bytes in length. Seems to match up with the expectations for 320x240 resolution.

Thought this might be in YUV422P format, but that doesn't seem to work when trying to convert as a test from FFMPEG. Still working on aspect, but very happy to have output from the preview port in any format!
No, not all encodings are supported (and that depends on which bit of GPU HW you are using) - you'll need to try until you find ones that work.
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.

User avatar
waveform80
Posts: 359
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK
Contact: Website Twitter

Re: Encoding Video & Taking Stills

Wed Nov 13, 2013 4:00 pm

codac wrote:Any news on that topic?
I still try depserately to find out if recording video and taking pictures at the same time is possible.
I've just attempted this with my picamera library (just in an interactive python session):

Code: Select all

>>> import picamera
>>> camera = picamera.PiCamera()
>>> camera.resolution = (640, 480)
>>> camera.start_recording('foo.h264')
>>> camera.capture('foo.jpg')
>>> camera.capture('bar.jpg')
>>> camera.capture('baz.jpg')
>>> camera.stop_recording()
>>> camera.close()
It works happily, in as much as the pictures and video all come back uncorrupted but as James has noted when the camera is capturing stills, the video drops frames (in my test video here it just looked as those the scene skipped slightly each time I had grabbed a still capture). Seems to work happily at higher resolutions like 720p too.

It might be possible to capture without dropped frames if, for example, one strapped a splitter to the video port, an H.264 encoder to one prong of the splitter and a JPEG encoder to the other (given that we know the JPEG encoder works happily with the video port), but I've not played with the splitter component yet and have no idea if this idea is feasible or not.

For reference, picamera's based on the same interface as raspistill/raspivid (the MMAL interface) so it shouldn't be terribly difficult to, say, mod raspivid to accept a key-press or some signal to capture images while the video is recording.


Cheers,

Dave.
Author of / contributor to a few pi related things (picamera, Sense HAT emulator, gpio-zero, piwheels, etc.), and currently a software engineer at Canonical responsible for Ubuntu Server and Core on the Raspberry Pi.

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

Re: Encoding Video & Taking Stills

Wed Nov 13, 2013 4:13 pm

The problem is that to do a capture at a different resolution, you need to change camera modes and that is guaranteed to drop a frame or two. If you capture at same resolution as video, it might work. But there may be some nastiness somewhere that still tries to change mode to use the capture mode since it has a different FOV...
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.

Return to “Camera board”