Skip to content

MP4 recording

The MP4 recording uses the Microsoft and GPU codecs: H.264 video, AAC audio.

To record in MP4 format with the default H.264 encoder (GPU encoder when available), use the following sample code (see RecordingMethod and StartRecording):

VideoGrabber.RecordingMethod = rm_MP4
VideoGrabber.StartRecording ()

To choose the H.264 encoder, use the following sample code (see CompressionMode, VideoCompressor and VideoCompressorIndex):

VideoGrabber.RecordingMethod = rm_MP4
VideoGrabber.CompressionMode = cm_CompressOnTheFly
VideoGrabber.VideoCompressor = VideoGrabber.VideoCompressorIndex ("...") (1)
VideoGrabber.StartRecording ()

(1) Specify the name of the H.264 encoder as shown in the "video compressors" list (listed in the "Recording" tab of MainDemo.exe), e.g. "H264 (Auto)", "H264 GPU (Nvidia)", "H264 GPU (Intel)", "H264 CPU (Microsoft)"; the list depends on the GPUs and drivers of the computer.

To record video and audio, also set AudioRecording = true (the audio is encoded in AAC).

To play the MP4 file while it is being recorded, set VideoPlayableWhileRecording = true (fragmented MP4, Windows 8 or later).

Without a video compressor (1st example above), the H.264 encoder of the built-in MP4 writer uses by default: VBR, automatic bit rate, a key frame every 2 seconds. These settings can be changed with VideoCompression_DataRate (mean bit rate, in bits per second), VideoCompression_Quality (constant quality, unless VideoCompression_DataRate is set) and VideoCompression_KeyFrameRate (frames per key frame, 0: automatic), see Software compression by using codecs. If the encoder refuses them, the video is recorded with the default settings and a warning is reported by OnLog.

Setting / saving / restoring the encoder settings

To adjust the compressor settings, invoke ShowDialog (dlg_VideoCompressor) as follows; the settings are saved in the registry and reused for the next recordings:

VideoGrabber.RecordingMethod = rm_MP4
VideoGrabber.CompressionMode = cm_CompressOnTheFly
VideoGrabber.VideoCompressor = VideoGrabber.VideoCompressorIndex ("...") (1)
VideoGrabber.ShowDialog (dlg_VideoCompressor)

The VideoCompression_DataRate, VideoCompression_Quality and VideoCompression_KeyFrameRate values set by the application take precedence over the settings saved with ShowDialog (dlg_VideoCompressor).

The SaveCompressorSettings... and LoadCompressorSettings... functions can also save/reload programmatically several sets of compressor settings, without having to invoke ShowDialog() anymore: see SaveCompressorSettingsToDataString, SaveCompressorSettingsToTextFile, LoadCompressorSettingsFromDataString and LoadCompressorSettingsFromTextFile.

Note

The selected video compressor is configured by ShowDialog (dlg_VideoCompressor), as shown above. Encoder_SetInt / Encoder_SetStr apply to the FFmpeg codecs of the Datastead Multipurpose Encoder only, see Recording through the Datastead Encoder.