Posts: 31
Joined: Wed Nov 14, 2018 8:53 am

Capture to Jpeg+ Raw image

Sun Sep 26, 2021 11:41 am

I have two questions:
1.Is it possible to capture image to jpeg and in addition to save the raw data (meaning, capture two files : one raw and the other jpeg)?
2.Is it possible to record video to multiple files whithout loosing data?
When i use record sequence i loose some data when one file ended and the other created


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

Re: Capture to Jpeg+ Raw image

Tue Sep 28, 2021 12:06 pm

1) It would be possible to separate the two, but it involves scanning the entire JPEG for the relevant markers (0xff 0xd9 @ B R C M).
The trickier bit is that this could be split across two buffers coming back from the GPU, so the state machine would need to be a little clever to achieve that.

2) A compressed video can be split at any IDR-frame as that means that there is no intra-frame prediction from previous frames. The Pi only ever uses one reference frame (no B-frame support), so all I-frames are also IDR-frames. Most compressed formats also require what are termed header bytes to tell the decoder that basic stream parameters. The firmware will send these header bytes before every IDR frame if requested, which means that whenever you get the header bytes you would be safe to start a new file without actually stopping encoding. This is how the PiCameraCircularIO works.
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.

Posts: 31
Joined: Wed Nov 14, 2018 8:53 am

Re: Capture to Jpeg+ Raw image

Wed Sep 29, 2021 7:48 am

Thanks for the answer
I tired to record video using the example in the link
I think i'm doing someting wrong- i get a 0 bytes file when i use stream.copy_to

here is my code:

Code: Select all

camera.resolution = (1280, 720)
stream = picamera.PiCameraCircularIO(camera, seconds=30)
 camera.start_recording(stream, format='h264')
 camera.split_recording('first_file.h264')  # This worked, i get a video file 
 stream.copy_to('first_file_stream.h264', seconds=5) # This doesnt work, i get a video file with 0 bytes size

Could you help?

I'm actualy trying to record video and split to multiple files by size (for example every 10 MB)while not lossing data (with record_sequence i loose data beween files)- is this the correct way to do it?

Return to “Camera board”