How Can We Help?
How to record a video source to mp4
(this requires the Datastead Multipurpose Encoder to be installed)
The typical sample code to record in MP4 is, e.g.:
#define ENCODER_RECORDING_ID 0 // the encoder with ID 0 is the TVideoGrabber’s embedded encoder, this will never change
VideoGrabber.VideoDevice = VideoGrabber.VideoDeviceIndex (“c922 Pro Stream Webcam”); (1)
VideoGrabber.AudioDevice = VideoGrabber.AudioDeviceindex (“Microphone (C922 Pro Stream Webcam)”);
VideoGrabber.VideoCompressor = VideoCompressorIndex (“Datastead Multipurpose Encoder”);
VideoGrabber.AudioCompressor = AudioCompressorIndex (“Datastead Multipurpose Encoder”);
VideoGrabber.Encoder_SetInt (ENCODER_RECORDING_ID, Enc_Video_Bitrate_kb, 2000); (2)
VideoGrabber.Encoder_SetStr (ENCODER_RECORDING_ID, Enc_Video_Codec, “hevc”);
VideoGrabber.Encoder_SetInt (ENCODER_RECORDING_ID, Enc_Video_Thread_Count, 4); // default 1
// VideoGrabber.Encoder_SetInt (ENCODER_RECORDING_ID, Enc_Video_GPU_Encoder, integer (Enc_GPU_NVidia_NVENC)); to enable the GPU encoding through NVidia (to select any GPU available set Enc_GPU_Auto)
VideoGrabber.Encoder_SetStr (ENCODER_RECORDING_ID, Enc_Audio_Codec, “aac”);
VideoGrabber.RecordingMethod = rm_MP4; // to generate the file name automatically (3)
// VideoGrabber.RecordingFileName = “VideoClip.mp4”; // if the file name is specified, it determines the recording method, no need to set RecordingMethod above
VideoGrabber.AudioRecording = true;
VideoGrabber.CompressionMode = cm_CompressOnTheFly;
VideoGrabber.StartRecording();
In the MainDemo project:
(1) “video source” tab
(2) “multipurpose” tab
(3) “recording” tab
Once started, the recording can be paused by invoking:
VideoGrabber.Pauseecording();
and resumed by invoking:
VideoGrabber.ResumeRecording();
During the recording, it is possible to start recording to a new file by invoking:
VideoGrabber.RecordToNewFileNow (“”);
or
VideoGrabber.RecordToNewFileNow (“c:\folder\thenewfilename.mp4”);
(if no file name is specified, the new file is created automatically in the VideoGrabber.StoragePath folder)
More information here.