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

Re: Stereoscopic camera capture - now implemented.

Mon Feb 19, 2018 9:37 am

Sorry, forgot to look until now.
Yes, I'm only notifying the first sensor that it should only ever use the chosen mode, the other one is either freely choosing for itself, or may be mismatching the chosen mode as array index values change.
I'll see if it is an easy fix (it should be), although I don't have a stereo rig set up at the moment to test it with.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

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

Re: Stereoscopic camera capture - now implemented.

Mon Feb 19, 2018 10:22 am

Thank you for looking into this. It is not a big issue, the automatic mode selection usually does a good job, and most of the times I don't need to choose the sensor mode. I can provide some testing if you want to check if your fix will work. I'm using a Compute Module IO board v3, with a CM3L and two NOIR v2 cameras.

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

Re: Stereoscopic camera capture - now implemented.

Sun Mar 04, 2018 8:22 pm

Thank you 6by9, your commit fixed my issue.

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

Re: Stereoscopic camera capture - now implemented.

Tue Mar 13, 2018 12:09 pm

I have a follow up question. I tried to find a good combination of size/frame rate to get maximal possible picture size at reasonable frame rates.
I found SBS [email protected] using MJPEG(40MBit/s, modified upper limit in raspivid) working reliably when using mode 5, but dropping frames when using mode 6. This seems strange to me, as there is no scaling needed and I would have assumed, mode 6 should be faster. Do you have any recommendation to archive higher frame rates and/or resolutions in stereo mode. Setting other resolution sometimes end up with seconds missing in the video and about missing about each second frame. My storage is a usb drive which can write constantly >20MB/s on the compute module. I know I can get higher frame rates at lower resolutions, but 720p is kind of minimal requirement (looking at 3mm big objects in ~0.75m distance).

I'm happy with 720p at 25fps, but slighly higher frame rate and resolution would be nice, too.

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

Re: Stereoscopic camera capture - now implemented.

Tue Mar 13, 2018 1:48 pm

I haven't run a stereo rig for quite a while, so my memory of details will be going.
I'm assuming you're using V2 sensors (IMX219) based on your comments of no scaling in mode 6.
The rescaling of 1640x922 to 1280x720 should be a minimal overhead compared to 1280x720 as input. The main warning flag to me is that mode 6 only permits 40 to 120 fps, so the minimum frame rate is 40fps rather than the 25fps you said you were asking for in mode 5.

MJPEG encode isn't nicely pipelined as H264 is. The JPEG block requires planar data, whilst H264 wants a proprietary format (referred to as SAND or YUVUV). MMAL and the video_encode component both assume H264 and YUVUV, therefore when the MJPEG codec finally gets an image it has to convert it back to planar. It does this as one big operation, and holds the vector unit for the whole period.
This came up on another thread recently. It may be more efficient to use the image_encode component and MMAL_ENCODING_I420 instead. It does mean you have to set a Q-factor instead of having bitrate control built in, but that may not be such a big deal to you. You also want to turn off EXIF, thumbnails, and any other fancy features of image_encode.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

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

Re: Stereoscopic camera capture - now implemented.

Tue Mar 13, 2018 1:57 pm

Thanks 6by9, your comment is as always very helpful. Yes, I'm using 2 v2 cameras. I did not realise that their was a minimum frame rate in mode 6/7. I will need to test this and I will try to use the image_encode component.

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

Re: Stereoscopic camera capture - now implemented.

Thu Mar 15, 2018 6:00 pm

I tried to use the image_encode component and it creates a stream of jpegs. However I can't check the timing, the pts of the callback is 0 all the time. I checked the number of recorded frames and frame number annotations instead, image_encode seems to be slightly slower then video_encode.

I don't know if I made some mistakes, or if I forget to set/modify something. I tried the following code, where I use the bitrate as quality value( raspivid ... -cd JPEG -b 10 ...).

Any ideas?

Code: Select all

diff --git a/host_applications/linux/apps/raspicam/RaspiVid.c b/host_applications/linux/apps/raspicam/RaspiVid.c
index 5cf0d66..68c0d94 100755
--- a/host_applications/linux/apps/raspicam/RaspiVid.c
+++ b/host_applications/linux/apps/raspicam/RaspiVid.c
@@ -233,6 +233,7 @@ struct RASPIVID_STATE_S
    int64_t lasttime;
 
    bool netListen;
+   bool imageEncode;
 };
 
 
@@ -440,7 +441,7 @@ static void default_status(RASPIVID_STATE *state)
    state->save_pts = 0;
 
    state->netListen = false;
-
+   state->imageEncode = false;
 
    // Setup preview window defaults
    raspipreview_set_defaults(&state->preview_parameters);
@@ -870,6 +871,8 @@ static int parse_cmdline(int argc, const char **argv, RASPIVID_STATE *state)
                state->encoding = MMAL_ENCODING_H264;
             else  if (len==5 && !strncmp("MJPEG", argv[i+1], 5))
                state->encoding = MMAL_ENCODING_MJPEG;
+            else if (len==4 && !strncmp("JPEG", argv[i+1], 4))
+               state->imageEncode = true;
             else
                valid = 0;
             i++;
@@ -1441,6 +1444,7 @@ static void encoder_buffer_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buf
                bytes_written = fwrite(buffer->data, 1, buffer->length, pData->file_handle);
                if(pData->flush_buffers) fflush(pData->file_handle);
 
+               fprintf(stderr, "pts=%lld flag=%d\n",buffer->pts,buffer->flags );
                if(pData->pstate->save_pts &&
                   (buffer->flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END ||
                    buffer->flags == 0 ||
@@ -1733,8 +1737,14 @@ static MMAL_STATUS_T create_camera_component(RASPIVID_STATE *state)
                                                      { 167, 1000 }, {999, 1000}};
         mmal_port_parameter_set(video_port, &fps_range.hdr);
    }
-
-   format->encoding = MMAL_ENCODING_OPAQUE;
+   if(state->imageEncode)
+   {
+      format->encoding = MMAL_ENCODING_I420;
+   }
+   else
+   {
+      format->encoding = MMAL_ENCODING_OPAQUE;
+   }
    format->es->video.width = VCOS_ALIGN_UP(state->width, 32);
    format->es->video.height = VCOS_ALIGN_UP(state->height, 16);
    format->es->video.crop.x = 0;
@@ -1761,7 +1771,14 @@ static MMAL_STATUS_T create_camera_component(RASPIVID_STATE *state)
 
    format = still_port->format;
 
-   format->encoding = MMAL_ENCODING_OPAQUE;
+   if(state->imageEncode)
+   {
+      format->encoding = MMAL_ENCODING_I420;
+   }
+   else
+   {
+      format->encoding = MMAL_ENCODING_OPAQUE;
+   }
    format->encoding_variant = MMAL_ENCODING_I420;
 
    format->es->video.width = VCOS_ALIGN_UP(state->width, 32);
@@ -1999,14 +2016,26 @@ static MMAL_STATUS_T create_encoder_component(RASPIVID_STATE *state)
    MMAL_STATUS_T status;
    MMAL_POOL_T *pool;
 
-   status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_ENCODER, &encoder);
-
-   if (status != MMAL_SUCCESS)
+   if(state->imageEncode)
    {
-      vcos_log_error("Unable to create video encoder component");
-      goto error;
+      status = mmal_component_create(MMAL_COMPONENT_DEFAULT_IMAGE_ENCODER, &encoder);
+      if (status != MMAL_SUCCESS)
+      {
+         vcos_log_error("Unable to create video encoder component");
+         goto error;
+      }
    }
+   else
+   {
+      status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_ENCODER, &encoder);
 
+      if (status != MMAL_SUCCESS)
+      {
+         vcos_log_error("Unable to create video encoder component");
+         goto error;
+      }
+   }
+   
    if (!encoder->input_num || !encoder->output_num)
    {
       status = MMAL_ENOSYS;
@@ -2020,204 +2049,244 @@ static MMAL_STATUS_T create_encoder_component(RASPIVID_STATE *state)
    // We want same format on input and output
    mmal_format_copy(encoder_output->format, encoder_input->format);
 
-   // Only supporting H264 at the moment
-   encoder_output->format->encoding = state->encoding;
+   if(state->imageEncode)
+   {
+      // Specify out output format - Hardcoded to JPEG
+      encoder_output->format->encoding = MMAL_ENCODING_JPEG;
+
+      //encoder_output->buffer_size = encoder_output->buffer_size_recommended;
+      encoder_output->buffer_size = 2048<<10;
+      
+      if (encoder_output->buffer_size < encoder_output->buffer_size_min)
+         encoder_output->buffer_size = encoder_output->buffer_size_min;
+
+      encoder_output->buffer_num = encoder_output->buffer_num_recommended;
+
+      if (encoder_output->buffer_num < encoder_output->buffer_num_min)
+         encoder_output->buffer_num = encoder_output->buffer_num_min;
+
+      // Commit the port changes to the output port
+      status = mmal_port_format_commit(encoder_output);
+
+      if (status != MMAL_SUCCESS)
+      {
+         vcos_log_error("Unable to set format on video encoder output port");
+         goto error;
+      }
 
-   if(state->encoding == MMAL_ENCODING_H264)
+      // Set the JPEG quality level
+      status = mmal_port_parameter_set_uint32(encoder_output, MMAL_PARAMETER_JPEG_Q_FACTOR, state->bitrate);
+
+      if (status != MMAL_SUCCESS)
+      {
+         vcos_log_error("Unable to set JPEG quality");
+         goto error;
+      }
+      MMAL_PARAMETER_THUMBNAIL_CONFIG_T param_thumb = {{MMAL_PARAMETER_THUMBNAIL_CONFIGURATION, sizeof(MMAL_PARAMETER_THUMBNAIL_CONFIG_T)}, 0, 0, 0, 0};
+      status = mmal_port_parameter_set(encoder->control, &param_thumb.hdr);
+
+   }
+   else
    {
-      if(state->level == MMAL_VIDEO_LEVEL_H264_4)
+      // Only supporting H264 at the moment
+      encoder_output->format->encoding = state->encoding;
+
+      if(state->encoding == MMAL_ENCODING_H264)
       {
-         if(state->bitrate > MAX_BITRATE_LEVEL4)
+         if(state->level == MMAL_VIDEO_LEVEL_H264_4)
          {
-            fprintf(stderr, "Bitrate too high: Reducing to 25MBit/s\n");
-            state->bitrate = MAX_BITRATE_LEVEL4;
+            if(state->bitrate > MAX_BITRATE_LEVEL4)
+            {
+               fprintf(stderr, "Bitrate too high: Reducing to 25MBit/s\n");
+               state->bitrate = MAX_BITRATE_LEVEL4;
+            }
          }
-      }
-      else
-      {
-         if(state->bitrate > MAX_BITRATE_LEVEL42)
+         else
          {
-            fprintf(stderr, "Bitrate too high: Reducing to 62.5MBit/s\n");
-            state->bitrate = MAX_BITRATE_LEVEL42;
+            if(state->bitrate > MAX_BITRATE_LEVEL42)
+            {
+               fprintf(stderr, "Bitrate too high: Reducing to 62.5MBit/s\n");
+               state->bitrate = MAX_BITRATE_LEVEL42;
+            }
          }
       }
-   }
-   else if(state->encoding == MMAL_ENCODING_MJPEG)
-   {
-      if(state->bitrate > MAX_BITRATE_MJPEG)
+      else if(state->encoding == MMAL_ENCODING_MJPEG)
       {
-         fprintf(stderr, "Bitrate too high: Reducing to 25MBit/s\n");
-         state->bitrate = MAX_BITRATE_MJPEG;
+         if(state->bitrate > MAX_BITRATE_MJPEG)
+         {
+            fprintf(stderr, "Bitrate too high: Reducing to 25MBit/s\n");
+            state->bitrate = MAX_BITRATE_MJPEG;
+         }
       }
-   }
-   
-   encoder_output->format->bitrate = state->bitrate;
+      
+      encoder_output->format->bitrate = state->bitrate;
 
-   if (state->encoding == MMAL_ENCODING_H264)
-      encoder_output->buffer_size = encoder_output->buffer_size_recommended;
-   else
-      encoder_output->buffer_size = 256<<10;
+      if (state->encoding == MMAL_ENCODING_H264)
+         encoder_output->buffer_size = encoder_output->buffer_size_recommended;
+      else
+         encoder_output->buffer_size = 256<<10;
 
 
-   if (encoder_output->buffer_size < encoder_output->buffer_size_min)
-      encoder_output->buffer_size = encoder_output->buffer_size_min;
+      if (encoder_output->buffer_size < encoder_output->buffer_size_min)
+         encoder_output->buffer_size = encoder_output->buffer_size_min;
 
-   encoder_output->buffer_num = encoder_output->buffer_num_recommended;
+      encoder_output->buffer_num = encoder_output->buffer_num_recommended;
 
-   if (encoder_output->buffer_num < encoder_output->buffer_num_min)
-      encoder_output->buffer_num = encoder_output->buffer_num_min;
+      if (encoder_output->buffer_num < encoder_output->buffer_num_min)
+         encoder_output->buffer_num = encoder_output->buffer_num_min;
 
-   // We need to set the frame rate on output to 0, to ensure it gets
-   // updated correctly from the input framerate when port connected
-   encoder_output->format->es->video.frame_rate.num = 0;
-   encoder_output->format->es->video.frame_rate.den = 1;
+      // We need to set the frame rate on output to 0, to ensure it gets
+      // updated correctly from the input framerate when port connected
+      encoder_output->format->es->video.frame_rate.num = 0;
+      encoder_output->format->es->video.frame_rate.den = 1;
 
-   // Commit the port changes to the output port
-   status = mmal_port_format_commit(encoder_output);
+      // Commit the port changes to the output port
+      status = mmal_port_format_commit(encoder_output);
 
-   if (status != MMAL_SUCCESS)
-   {
-      vcos_log_error("Unable to set format on video encoder output port");
-      goto error;
-   }
-
-   // Set the rate control parameter
-   if (0)
-   {
-      MMAL_PARAMETER_VIDEO_RATECONTROL_T param = {{ MMAL_PARAMETER_RATECONTROL, sizeof(param)}, MMAL_VIDEO_RATECONTROL_DEFAULT};
-      status = mmal_port_parameter_set(encoder_output, &param.hdr);
       if (status != MMAL_SUCCESS)
       {
-         vcos_log_error("Unable to set ratecontrol");
+         vcos_log_error("Unable to set format on video encoder output port");
          goto error;
       }
 
-   }
-
-   if (state->encoding == MMAL_ENCODING_H264 &&
-       state->intraperiod != -1)
-   {
-      MMAL_PARAMETER_UINT32_T param = {{ MMAL_PARAMETER_INTRAPERIOD, sizeof(param)}, state->intraperiod};
-      status = mmal_port_parameter_set(encoder_output, &param.hdr);
-      if (status != MMAL_SUCCESS)
+      // Set the rate control parameter
+      if (0)
       {
-         vcos_log_error("Unable to set intraperiod");
-         goto error;
-      }
-   }
+         MMAL_PARAMETER_VIDEO_RATECONTROL_T param = {{ MMAL_PARAMETER_RATECONTROL, sizeof(param)}, MMAL_VIDEO_RATECONTROL_DEFAULT};
+         status = mmal_port_parameter_set(encoder_output, &param.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_error("Unable to set ratecontrol");
+            goto error;
+         }
 
-   if (state->encoding == MMAL_ENCODING_H264 &&
-       state->quantisationParameter)
-   {
-      MMAL_PARAMETER_UINT32_T param = {{ MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT, sizeof(param)}, state->quantisationParameter};
-      status = mmal_port_parameter_set(encoder_output, &param.hdr);
-      if (status != MMAL_SUCCESS)
-      {
-         vcos_log_error("Unable to set initial QP");
-         goto error;
       }
 
-      MMAL_PARAMETER_UINT32_T param2 = {{ MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT, sizeof(param)}, state->quantisationParameter};
-      status = mmal_port_parameter_set(encoder_output, &param2.hdr);
-      if (status != MMAL_SUCCESS)
+      if (state->encoding == MMAL_ENCODING_H264 &&
+          state->intraperiod != -1)
       {
-         vcos_log_error("Unable to set min QP");
-         goto error;
+         MMAL_PARAMETER_UINT32_T param = {{ MMAL_PARAMETER_INTRAPERIOD, sizeof(param)}, state->intraperiod};
+         status = mmal_port_parameter_set(encoder_output, &param.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_error("Unable to set intraperiod");
+            goto error;
+         }
       }
 
-      MMAL_PARAMETER_UINT32_T param3 = {{ MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT, sizeof(param)}, state->quantisationParameter};
-      status = mmal_port_parameter_set(encoder_output, &param3.hdr);
-      if (status != MMAL_SUCCESS)
+      if (state->encoding == MMAL_ENCODING_H264 &&
+          state->quantisationParameter)
       {
-         vcos_log_error("Unable to set max QP");
-         goto error;
-      }
+         MMAL_PARAMETER_UINT32_T param = {{ MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT, sizeof(param)}, state->quantisationParameter};
+         status = mmal_port_parameter_set(encoder_output, &param.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_error("Unable to set initial QP");
+            goto error;
+         }
 
-   }
+         MMAL_PARAMETER_UINT32_T param2 = {{ MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT, sizeof(param)}, state->quantisationParameter};
+         status = mmal_port_parameter_set(encoder_output, &param2.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_error("Unable to set min QP");
+            goto error;
+         }
 
-   if (state->encoding == MMAL_ENCODING_H264)
-   {
-      MMAL_PARAMETER_VIDEO_PROFILE_T  param;
-      param.hdr.id = MMAL_PARAMETER_PROFILE;
-      param.hdr.size = sizeof(param);
+         MMAL_PARAMETER_UINT32_T param3 = {{ MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT, sizeof(param)}, state->quantisationParameter};
+         status = mmal_port_parameter_set(encoder_output, &param3.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_error("Unable to set max QP");
+            goto error;
+         }
 
-      param.profile[0].profile = state->profile;
+      }
 
-      if((VCOS_ALIGN_UP(state->width,16) >> 4) * (VCOS_ALIGN_UP(state->height,16) >> 4) * state->framerate > 245760)
+      if (state->encoding == MMAL_ENCODING_H264)
       {
-         if((VCOS_ALIGN_UP(state->width,16) >> 4) * (VCOS_ALIGN_UP(state->height,16) >> 4) * state->framerate <= 522240)
+         MMAL_PARAMETER_VIDEO_PROFILE_T  param;
+         param.hdr.id = MMAL_PARAMETER_PROFILE;
+         param.hdr.size = sizeof(param);
+
+         param.profile[0].profile = state->profile;
+
+         if((VCOS_ALIGN_UP(state->width,16) >> 4) * (VCOS_ALIGN_UP(state->height,16) >> 4) * state->framerate > 245760)
          {
-            fprintf(stderr, "Too many macroblocks/s: Increasing H264 Level to 4.2\n");
-            state->level=MMAL_VIDEO_LEVEL_H264_42;
+            if((VCOS_ALIGN_UP(state->width,16) >> 4) * (VCOS_ALIGN_UP(state->height,16) >> 4) * state->framerate <= 522240)
+            {
+               fprintf(stderr, "Too many macroblocks/s: Increasing H264 Level to 4.2\n");
+               state->level=MMAL_VIDEO_LEVEL_H264_42;
+            }
+            else
+            {
+               vcos_log_error("Too many macroblocks/s requested");
+               goto error;
+            }
          }
-         else
+         
+         param.profile[0].level = state->level;
+
+         status = mmal_port_parameter_set(encoder_output, &param.hdr);
+         if (status != MMAL_SUCCESS)
          {
-            vcos_log_error("Too many macroblocks/s requested");
+            vcos_log_error("Unable to set H264 profile");
             goto error;
          }
       }
-      
-      param.profile[0].level = state->level;
 
-      status = mmal_port_parameter_set(encoder_output, &param.hdr);
-      if (status != MMAL_SUCCESS)
+      if (mmal_port_parameter_set_boolean(encoder_input, MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT, state->immutableInput) != MMAL_SUCCESS)
       {
-         vcos_log_error("Unable to set H264 profile");
-         goto error;
+         vcos_log_error("Unable to set immutable input flag");
+         // Continue rather than abort..
       }
-   }
 
-   if (mmal_port_parameter_set_boolean(encoder_input, MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT, state->immutableInput) != MMAL_SUCCESS)
-   {
-      vcos_log_error("Unable to set immutable input flag");
-      // Continue rather than abort..
-   }
-
-   //set INLINE HEADER flag to generate SPS and PPS for every IDR if requested
-   if (mmal_port_parameter_set_boolean(encoder_output, MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, state->bInlineHeaders) != MMAL_SUCCESS)
-   {
-      vcos_log_error("failed to set INLINE HEADER FLAG parameters");
-      // Continue rather than abort..
-   }
-
-   //set INLINE VECTORS flag to request motion vector estimates
-   if (state->encoding == MMAL_ENCODING_H264 &&
-       mmal_port_parameter_set_boolean(encoder_output, MMAL_PARAMETER_VIDEO_ENCODE_INLINE_VECTORS, state->inlineMotionVectors) != MMAL_SUCCESS)
-   {
-      vcos_log_error("failed to set INLINE VECTORS parameters");
-      // Continue rather than abort..
-   }
-
-   // Adaptive intra refresh settings
-   if (state->encoding == MMAL_ENCODING_H264 &&
-       state->intra_refresh_type != -1)
-   {
-      MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T  param;
-      param.hdr.id = MMAL_PARAMETER_VIDEO_INTRA_REFRESH;
-      param.hdr.size = sizeof(param);
+      //set INLINE HEADER flag to generate SPS and PPS for every IDR if requested
+      if (mmal_port_parameter_set_boolean(encoder_output, MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, state->bInlineHeaders) != MMAL_SUCCESS)
+      {
+         vcos_log_error("failed to set INLINE HEADER FLAG parameters");
+         // Continue rather than abort..
+      }
 
-      // Get first so we don't overwrite anything unexpectedly
-      status = mmal_port_parameter_get(encoder_output, &param.hdr);
-      if (status != MMAL_SUCCESS)
+      //set INLINE VECTORS flag to request motion vector estimates
+      if (state->encoding == MMAL_ENCODING_H264 &&
+          mmal_port_parameter_set_boolean(encoder_output, MMAL_PARAMETER_VIDEO_ENCODE_INLINE_VECTORS, state->inlineMotionVectors) != MMAL_SUCCESS)
       {
-         vcos_log_warn("Unable to get existing H264 intra-refresh values. Please update your firmware");
-         // Set some defaults, don't just pass random stack data
-         param.air_mbs = param.air_ref = param.cir_mbs = param.pir_mbs = 0;
+         vcos_log_error("failed to set INLINE VECTORS parameters");
+         // Continue rather than abort..
       }
 
-      param.refresh_mode = state->intra_refresh_type;
+      // Adaptive intra refresh settings
+      if (state->encoding == MMAL_ENCODING_H264 &&
+          state->intra_refresh_type != -1)
+      {
+         MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T  param;
+         param.hdr.id = MMAL_PARAMETER_VIDEO_INTRA_REFRESH;
+         param.hdr.size = sizeof(param);
 
-      //if (state->intra_refresh_type == MMAL_VIDEO_INTRA_REFRESH_CYCLIC_MROWS)
-      //   param.cir_mbs = 10;
+         // Get first so we don't overwrite anything unexpectedly
+         status = mmal_port_parameter_get(encoder_output, &param.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_warn("Unable to get existing H264 intra-refresh values. Please update your firmware");
+            // Set some defaults, don't just pass random stack data
+            param.air_mbs = param.air_ref = param.cir_mbs = param.pir_mbs = 0;
+         }
 
-      status = mmal_port_parameter_set(encoder_output, &param.hdr);
-      if (status != MMAL_SUCCESS)
-      {
-         vcos_log_error("Unable to set H264 intra-refresh values");
-         goto error;
+         param.refresh_mode = state->intra_refresh_type;
+
+         //if (state->intra_refresh_type == MMAL_VIDEO_INTRA_REFRESH_CYCLIC_MROWS)
+         //   param.cir_mbs = 10;
+
+         status = mmal_port_parameter_set(encoder_output, &param.hdr);
+         if (status != MMAL_SUCCESS)
+         {
+            vcos_log_error("Unable to set H264 intra-refresh values");
+            goto error;
+         }
       }
-   }
 
+   }
    //  Enable component
    status = mmal_component_enable(encoder);
 


Return to “Camera board”

Who is online

Users browsing this forum: No registered users and 3 guests