# Repair recorded files (/en/realtime-media/on-premise-recording/build/process-recorded-files/restore-files)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

<_PlatformTabsGroup groupMode="structured" canonicalPlatform="linux-cpp" platforms="[&#x22;linux-cpp&#x22;,&#x22;linux-java&#x22;]" showTabs="true">
  <_PlatformPanel platform="linux-cpp">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="linux-cpp" platform="linux-cpp" />

    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 [#implementation]

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

    ### Enable file recovery [#enable-file-recovery]

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

    ```cpp
    auto agoraParameter = service->getAgoraParameter();
    agoraParameter->setBool("che.media_recorder_recover_files", true);
    ```

    ### Understand file behavior [#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 [#regenerate-the-mp4-file]

    To regenerate a corrupted MP4 file, use [ffmpeg](https://ffmpeg.org/), a command-line tool for processing video and audio, to merge the retained files into a playable MP4.

    ```bash
    ffmpeg -i video.h264 -i audio.aac -c:v copy -c:a copy output.mp4
    ```

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

    ## Reference [#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 [#api-references]

    * [`getAgoraParameter`](/en/api-reference/api-ref/on-premise-recording#getagoraparameter)
    * [`onRecorderStateChanged`](/en/api-reference/api-ref/on-premise-recording#onrecorderstatechanged)
    * [`stopRecording`](/en/api-reference/api-ref/on-premise-recording#stoprecording)

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>

  <_PlatformPanel platform="linux-java">
    <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="linux-cpp" platform="linux-java" />

    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 [#implementation-1]

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

    ### Enable file recovery [#enable-file-recovery-1]

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

    ```java
    AgoraParameter parameter = agoraService.getAgoraParameter();
    parameter.setBool("che.media_recorder_recover_files", true);
    ```

    ### Understand file behavior [#understand-file-behavior-1]

    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 [#regenerate-the-mp4-file-1]

    To regenerate a corrupted MP4 file, use [ffmpeg](https://ffmpeg.org/), a command-line tool for processing video and audio, to merge the retained files into a playable MP4.

    ```bash
    ffmpeg -i agoraRecording.mp4.h264 -i agoraRecording.mp4.aac -c:v copy -c:a copy output.mp4
    ```

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

    ## Reference [#reference-1]

    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 [#api-references-1]

    * [`getAgoraParameter`](/en/api-reference/api-ref/on-premise-recording#getagoraparameter)
    * [`onRecorderStateChanged`](/en/api-reference/api-ref/on-premise-recording#onrecorderstatechanged)
    * [`stopRecording`](/en/api-reference/api-ref/on-premise-recording#stoprecording)

    <_PlatformProcessedMarker close="true" />
  </_PlatformPanel>
</_PlatformTabsGroup>
