Skip to main content

Repair recorded files

If a recording session crashes, the generated MP4 file may be unplayable. To preserve recorded audio and video content, the On-Premise Recording SDK provides a recovery feature that lets you reconstruct the MP4 file from temporary H264 and AAC files.

Implementation

This section shows how to enable recovery mode and regenerate MP4 files after a crash.

Enable file recovery

To enable file recovery, set the che.media_recorder_recover_files parameter to true during AgoraService initialization:

Understand file behavior

When file recovery is enabled, the SDK generates an MP4 file as well as two additional files, H264 and AAC—with the same base name. For example, if the output file is storagePath/agoraRecording.mp4, then agoraRecording.mp4.h264 and agoraRecording.mp4.aac files are also generated in the same path.

  • If the recording ends normally and the SDK triggers onRecorderStateChanged with RECORDER_STATE_STOP after stopRecording is called, the SDK deletes the H264 and AAC files automatically.

  • If the recording crashes or exits unexpectedly, the SDK retains the H264 and AAC files for recovery.

Regenerate the MP4 file

To regenerate a corrupted MP4 file, use ffmpeg, a command-line tool for processing video and audio, to merge the retained files into a playable MP4.

This command creates a new playable MP4 file using the video and audio data from the retained files.

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

API references