This example introduces the SpinVideo class, which is used to quickly and easily create various types of video files. It demonstrates the creation of four types: uncompressed, MJPG, H264 (AVI) and H264 (MP4).
#include <stdbool.h>
#include "stdio.h"
#include "string.h"
#define MAX_BUFF_LEN 256
#define NUM_IMAGES 100
{
{
}
{
{
printf(
"Unable to retrieve node readability (%s node) with error: %s [%d]\n\n",
nodeName,
err);
}
return pbReadable;
}
{
{
printf(
"Unable to retrieve node writability (%s node) with error: %s [%d]\n\n",
nodeName,
err);
}
return pbWritable;
}
{
printf("\n\n*** CREATING VIDEO ***\n\n");
double acquisitionFrameRate = 0.0;
float frameRateToSet = 0.0;
{
printf(
"Unable to retrieve frame rate (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
if (
IsReadable(hAcquisitionFrameRate,
"AcquisitionFrameRate"))
{
{
printf(
"Unable to retrieve frame rate (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
printf(
"Unable to read frame rate. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
frameRateToSet = (float)acquisitionFrameRate;
{
}
printf("Frame rate to be set to %f\n", frameRateToSet);
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
else
{
if (
IsReadable(hDeviceSerialNumber,
"DeviceSerialNumber"))
{
err =
spinStringGetValue(hDeviceSerialNumber, deviceSerialNumber, &lenDeviceSerialNumber);
{
printf(
"Unable to get device serial number. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
}
else
{
printf(
"Unable to get device serial number. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
return err;
}
printf("Device serial number retrieved as %s...\n", deviceSerialNumber);
}
printf("\n");
{
if (lenDeviceSerialNumber == 0)
{
sprintf(filename, "SaveToVideo-C-Uncompressed");
}
else
{
sprintf(filename, "SaveToVideo-C-%s-Uncompressed", deviceSerialNumber);
}
}
{
if (lenDeviceSerialNumber == 0)
{
sprintf(filename, "SaveToVideo-C-MJPG");
}
else
{
sprintf(filename, "SaveToVideo-C-%s-MJPG", deviceSerialNumber);
}
}
{
if (lenDeviceSerialNumber == 0)
{
sprintf(filename, "SaveToVideo-C-H264");
}
else
{
sprintf(filename, "SaveToVideo-C-%s-H264", deviceSerialNumber);
}
}
{
spinAVIOption option;
option.frameRate = frameRateToSet;
int64_t width = 0;
{
printf(
"Unable to retrieve width (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
{
{
printf(
"Unable to retrieve width (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
return err;
}
option.width = (unsigned int)width;
int64_t height = 0;
{
printf(
"Unable to retrieve height (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
{
{
printf(
"Unable to retrieve height (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
return err;
}
option.height = (unsigned int)height;
{
printf(
"Unable to open uncompressed video file. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
{
spinMJPGOption option;
option.frameRate = frameRateToSet;
option.quality = 75;
int64_t width = 0;
{
printf(
"Unable to retrieve width (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
{
{
printf(
"Unable to retrieve width (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
return err;
}
option.width = (unsigned int)width;
int64_t height = 0;
{
printf(
"Unable to retrieve height (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
{
{
printf(
"Unable to retrieve height (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
return err;
}
option.height = (unsigned int)height;
{
printf(
"Unable to open MJPG video file. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
{
spinH264Option option;
option.frameRate = frameRateToSet;
option.bitrate = 1000000;
option.crf = 23;
int64_t width = 0;
{
printf(
"Unable to retrieve width (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
{
{
printf(
"Unable to retrieve width (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
return err;
}
option.width = (unsigned int)width;
int64_t height = 0;
{
printf(
"Unable to retrieve height (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
{
{
printf(
"Unable to retrieve height (value retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
return err;
}
option.height = (unsigned int)height;
{
printf(
"Unable to open H264 video file. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
const unsigned int k_videoFileSize = 2048;
{
printf(
"Unable to set maximum file size. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
unsigned int imageCnt = 0;
printf(
"Appending %d images to video file: %s\n\n",
NUM_IMAGES, filename);
for (imageCnt = 0; imageCnt <
NUM_IMAGES; imageCnt++)
{
{
printf(
"Unable to append image. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("\tAppended image %d...\n", imageCnt);
}
printf("\nVideo saved at %s\n\n", filename);
{
printf(
"Unable to close video file. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
for (imageCnt = 0; imageCnt <
NUM_IMAGES; imageCnt++)
{
{
printf("Unable to destroy image %d. Non-fatal error %d...\n\n", imageCnt, err);
}
}
return err;
}
{
unsigned int i = 0;
printf("\n*** DEVICE INFORMATION ***\n\n");
{
return err;
}
size_t numFeatures = 0;
if (
IsReadable(hDeviceInformation,
"DeviceInformation"))
{
{
printf(
"Unable to retrieve number of nodes. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
else
{
printf(
"Unable to read device information. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
for (i = 0; i < numFeatures; i++)
{
{
continue;
}
{
strcpy(featureName, "Unknown name");
}
{
{
printf(
"Unable to retrieve node type. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
continue;
}
}
else
{
printf("%s: Node not readable\n", featureName);
continue;
}
{
strcpy(featureValue, "Unknown value");
}
printf("%s: %s\n", featureName, featureValue);
}
printf("\n");
return err;
}
{
printf("\n*** IMAGE ACQUISITION ***\n\n");
int64_t acquisitionModeContinuous = 0;
{
printf(
"Unable to set acquisition mode to continuous (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
if (
IsReadable(hAcquisitionMode,
"AcquisitionMode"))
{
{
printf(
"Unable to set acquisition mode to continuous (entry 'continuous' retrieval). Aborting with error "
"%d...\n\n",
err);
return err;
}
}
else
{
printf(
"Unable to read acquisition mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (
IsReadable(hAcquisitionModeContinuous,
"AcquisitionModeContinuous"))
{
{
printf(
"Unable to set acquisition mode to continuous (entry int value retrieval). Aborting with error "
"%d...\n\n",
err);
return err;
}
}
else
{
printf(
"Unable to read acquisition mode continuous. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (
IsWritable(hAcquisitionMode,
"AcquisitionMode"))
{
{
printf(
"Unable to set acquisition mode to continuous (entry int value setting). Aborting with error %d...\n\n",
err);
return err;
}
printf("Acquisition mode set to continuous...\n");
}
else
{
printf(
"Unable to write to acquisition mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to begin image acquisition. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Acquiring images...\n");
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
else
{
if (
IsReadable(hDeviceSerialNumber,
"DeviceSerialNumber"))
{
err =
spinStringGetValue(hDeviceSerialNumber, deviceSerialNumber, &lenDeviceSerialNumber);
{
printf(
"Unable to get device serial number. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
printf("Device serial number retrieved as %s...\n", deviceSerialNumber);
}
else
{
printf(
"Unable to get device serial number. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
}
printf("\n");
unsigned int imageCnt = 0;
{
printf(
"Unable to create image processor. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
{
printf(
"Unable to set image processor color processing method. Non-fatal error: %s [%d]\n\n",
err);
}
{
{
continue;
}
{
printf(
"Unable to determine image completion. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
if (isIncomplete)
{
{
printf(
"Unable to retrieve image status. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
else
{
printf("Image incomplete with image status %d...\n", imageStatus);
}
}
if (hasFailed)
{
{
}
continue;
}
size_t width = 0;
size_t height = 0;
printf("Grabbed image %d, ", imageCnt);
{
printf("width = unknown, ");
}
else
{
printf("width = %u, ", (unsigned int)width);
}
{
printf("height = unknown\n");
}
else
{
printf("height = %u\n", (unsigned int)height);
}
hImages[imageCnt] = NULL;
{
}
{
}
{
}
++imageCnt;
}
{
printf(
"Unable to destroy image processor. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
{
}
return err;
}
{
{
printf(
"Unable to retrieve TL device nodemap. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
else
{
}
{
printf(
"Unable to initialize camera. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to retrieve GenICam nodemap. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
return err;
}
{
return err;
}
{
printf(
"Unable to deinitialize camera. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
return err;
}
{
unsigned int i = 0;
printf("Application build date: %s %s \n\n", __DATE__, __TIME__);
{
printf(
"Unable to retrieve system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
spinLibraryVersion hLibraryVersion;
printf(
"Spinnaker library version: %d.%d.%d.%d\n\n",
hLibraryVersion.major,
hLibraryVersion.minor,
hLibraryVersion.type,
hLibraryVersion.build);
{
printf(
"Unable to create camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to retrieve camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
size_t numCameras = 0;
{
printf(
"Unable to retrieve number of cameras. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Number of cameras detected: %u\n\n", (unsigned int)numCameras);
if (numCameras == 0)
{
{
printf(
"Unable to clear camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to destroy camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to release system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Not enough cameras!\n");
printf("Done! Press Enter to exit...\n");
getchar();
return -1;
}
for (i = 0; i < numCameras; i++)
{
printf("\nRunning example for camera %d...\n", i);
{
printf(
"Unable to retrieve camera from list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
errReturn = err;
}
else
{
{
errReturn = err;
}
}
{
errReturn = err;
}
printf("Camera %d example complete...\n\n", i);
}
{
printf(
"Unable to clear camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to destroy camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to release system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("\nDone! Press Enter to exit...\n");
getchar();
return errReturn;
}