Updated: October 28, 2024 |
You can record video to a file.
Then, you can set any of the equivalent video properties using camera_set_video_property().
... ... camera_handle_t cameraHandle; int err; // 1. To prepare to start recording, connect to the camera if (err = camera_open(CAMERA_UNIT_1, CAMERA_MODE_RW | CAMERA_MODE_ROLL, &cameraHandle) != CAMERA_EOK) { printf("Failed to open the camera: err = %d\n", err); return err; } // 2. Set the viewfinder image stream mode if (err = camera_set_vf_mode(cameraHandle, CAMERA_VFMODE_VIDEO) != CAMERA_EOK) { printf("Failed to set the viewfinder mode: err = %d\n", err); camera_close(cameraHandle); return err; } // 3. Set up Screen to work with the Camera API. // This entails using the exact same code shown in "Connect Screen with the Camera API". // You must insert that code at this point, and follow it immediately with the code shown next. // 4. Start the viewfinder -- in this sample, we don't configuration any camera settings err = camera_start_viewfinder(cameraHandle, NULL, NULL, NULL); if (err != CAMERA_EOK) { printf("Failed to start viewfinder: err = %d\n", err); camera_close(cameraHandle); return err; } // 5. We now need to use Screen to access the viewfinder window and make it visible. // This entails using the exact same code shown in "Use Screen to show the viewfinder window". // You must insert that code at this point, and follow it immediately with the code shown next. // 6. Retrieve the relevant viewfinder properties and set the equivalent parameters // for video recording. camera_frametype_t format; uint32_t width, height, rotation; err = camera_get_vf_property(cameraHandle, CAMERA_IMGPROP_FORMAT, &format, CAMERA_IMGPROP_WIDTH, &width, CAMERA_IMGPROP_HEIGHT, &height, CAMERA_IMGPROP_ROTATION, &rotation); double framerate; camera_videocodec_t videoCodec; camera_audiocodec_t audioCodec; err = camera_get_vf_property(cameraHandle, CAMERA_IMGPROP_FRAMERATE, &framerate, CAMERA_IMGPROP_VIDEOCODEC, &videoCodec, CAMERA_IMGPROP_AUDIOCODEC, &audioCodec); // Set the equivalent properties for the camera err = camera_set_video_property(cameraHandle, CAMERA_IMGPROP_FORMAT, format, CAMERA_IMGPROP_WIDTH, width, CAMERA_IMGPROP_HEIGHT, height, CAMERA_IMGPROP_ROTATION, rotation, CAMERA_IMGPROP_FRAMERATE, framerate, CAMERA_IMGPROP_VIDEOCODEC, videoCodec, CAMERA_IMGPROP_AUDIOCODEC, audioCodec); int exitExample = 0; static char userString[80]; while (exitExample == 0) { printf("\tPress c to start recording:\n"); fgets(userString, sizeof(userString), stdin); if ( (userString[0] == 'c') || (userString[0] == 'C') ) { exitExample = 1; } } // 7. Open a file for recording char* rollFilename = (char*) malloc(sizeof(char) * CAMERA_ROLL_NAMELEN); int fd; camera_roll_open_video(cameraHandle, &fd, rollFilename, CAMERA_ROLL_NAMELEN, CAMERA_ROLL_VIDEO_FMT_MP4); // 8. Start recording video camera_start_video(cameraHandle, rollFilename, NULL, NULL, NULL); exitExample = 0; while (exitExample == 0) { printf("\tPress c to stop recording:\n"); fgets(userString, sizeof(userString), stdin); if ( (userString[0] == 'c') || (userString[0] == 'C') ) { exitExample = 1; } } // 9. Stop recording video and close the file in the camera roll camera_stop_video(cameraHandle); camera_roll_close_video(fd); // 10. Stop receiving image buffers and disconnect from the camera camera_stop_viewfinder(cameraHandle); camera_close(cameraHandle); // 11. Clean up memory allocated for the video file, and Screen objects (not shown) free(rollFilename); ... ...