MP4 to SD file fails

Hello,

I’m having an issue getting the mp4 module to write video to file successfully. My setup is simple

video => SISO => mp4

when I stream jpeg snapshots from the video while the recording is taking place, I get a good stream. But when I try to close the video, I get error output.

Here’s my clean up code:

static void cleanup_mmf(void)
{
    printf("[VIDEO_SESSION] cleanup_mmf called\n");

    if (g_vs.siso_video_mp4) {
        printf("[VIDEO_SESSION] siso_video_mp4 pausing\n");
        siso_pause(g_vs.siso_video_mp4);
    }

    if (g_vs.mp4_ctx) {
        printf("[VIDEO_SESSION] mp4_ctx stopping\n");
        // mm_module_ctrl(g_vs.mp4_ctx, CMD_MP4_STOP, 0);
        mm_module_ctrl(g_vs.mp4_ctx, CMD_MP4_STOP, 0);
    }

    if (g_vs.video_ctx) {
        printf("[VIDEO_SESSION] video_ctx stream stopping\n");
        mm_module_ctrl(g_vs.video_ctx, CMD_VIDEO_STREAM_STOP, 0);
    }

    if (g_vs.siso_video_mp4) {
        printf("[VIDEO_SESSION] siso_video_mp4 deleting\n");
        siso_delete(g_vs.siso_video_mp4);
        g_vs.siso_video_mp4 = NULL;
    }

    if (g_vs.video_ctx) {
        printf("[VIDEO_SESSION] video_ctx closing\n");
        mm_module_close(g_vs.video_ctx);
        g_vs.video_ctx = NULL;
    }
    if (g_vs.mp4_ctx) {
        printf("[VIDEO_SESSION] mp4_ctx closing\n");
        mm_module_close(g_vs.mp4_ctx);
        g_vs.mp4_ctx = NULL;
    }

    printf("[VIDEO_SESSION] calling video_voe_release\n");
    video_voe_release();
    printf("[VIDEO_SESSION] video_voe_release called\n");
}

And here’s the output:

[VIDEO_SESSION] cleanup_mmf called
[VIDEO_SESSION] siso_video_mp4 pausing
[VIDEO_SESSION] mp4_ctx stopping
Stop MP4 recording
[VIDEO_SESSION] video_ctx stream stopping
finish output task
hal_video_output_task closed 
hal_voe_send2voe too long 112107 cmd 0x00000207 p1 0x00000000 p2 0x00000000
hal_voe_ready 0x0 0x1718 
[VIDEO_SESSION] siso_video_mp4 deleting
[VIDEO_SESSION] video_ctx closing
[VIDEO_SESSION] mp4_ctx closing
Stop MP4 recording
It don't init the buffer
STORAGE_ERROR -> STORAGE_IDLE
[VIDEO_SESSION] mp4_error_cb called
mp4_muxer_close
SD_DeInit
[VIDEO_SESSION] calling video_voe_release
[VIDEO_SESSION] video_voe_release called

After this the SD card is not readable, until I reboot and then it is readable. But there was no mp4 file written on the SD card.

I’m happy to provide more data on the initialization or anything else if that helps. Hoping someone can give me a clue as to what could be the cause.

thanks
Khaled

Hi @khassounah,

You may refer to this file to do a recording to SD card.

Thank you.

I found what the issue is, and putting it here in case someone has a similar issue.

The FMP4 module (and I believe the MP4 module would have the same issue) expects audio input or it doesn’t generate any frames and you see the issue I experienced.

So setting up the pipeline as Video => SISO => mp4 would fail.

When I set it up as Video & Audio (AAC) => MISO => fmp4, it works perfectly. I haven’t gotten mp4 to work in the same setup, but I don’t need it now. Will update thread if I confirm that it also works.

I wish Realtek would make the lower layer code available. The code fails easily if everything is not perfect, and it’s hard to troubleshoot issues without tons of trial and error. I thought multiple times about quitting and moving back to ESP32, which would be sad for such a powerful hardware platform.