Ameba Pro2: MP4 recording freezes when switching from H.264 to H.265

I am working with the ameba-rtos-pro2 SDK and trying to run the media_video_to_storage example.

The example works perfectly using the default H.264 settings. However, when I attempt to switch to H.265 by modifying the following line in example_media_video_to_storage.c

#define USE_H265 1 // Changed from 0 to 1

The system freezes immediately after starting the recording. It reaches STORAGE_START but never progresses to the encoding/stop phase.

Freeze Log:

Start MP4 recording (1 files)
STORAGE_INIT
open file (sd:/AmebaPro2_1.mp4) len = 10 seconds
STORAGE_INIT → STORAGE_START
[Driver]: TSFValue = 2575757210022, tsf = 0, shift_set= 0x8000, bcn int = 100


Expected Behavior (as seen in H.264): In H.264, the log continues to print the size of the video and audio it recorded, followed by STORAGE_STOP and successful file closure.

Environment:

  • Hardware: Ameba Pro2 (AMB82-mini or similar)

  • SDK: ameba-rtos-pro2

  • SD Card: Formatted and working for H.264

Has anyone successfully recorded H.265 to storage using this example? Do I need to change any other settings?

Hi @k-adarsh ,

As the codec type is hard-coded for H.264, there are 2 more settings that you might need to change to record with H.265.

  1. Ensure that you have enabled USE_H265, #define USE_H265 1
  2. Please also change `ctx.type` and the `mp4_muxer_write_video()` codec argument from `AV_CODEC_ID_H264` to `VIDEO_CODEC`, so that the muxer knows it is handling H.265 instead of H.264.

Thank you.

Thanks for the reply! I’ll try the changes you mentioned and get back to you.

Also, I’m facing another issue. I’m trying to record live video in 60-second chunks, so I modified the code to record in a loop, but there’s nearly a one-second gap between segments. I suspect the delay stems from closing the first file and opening the second. Is there a way to reduce this, or do you have any example code for continuous chunked recording?

Hey, thanks for the suggestion! The code works and is recording in H.265.

Could you also help with the other issue?

When I try to loop-record in chunks, I can’t seem to shorten the gap between recordings; I’m consistently losing about 1 second of video (600ms at best) between clips.

Hi @k-adarsh ,

Would you like to tryout the mmf video example for mp4 recording? You may modify the record_file_num in line 121 of mmf2_video_example_av_mp4_init.c ameba-rtos-pro2/project/realtek_amebapro2_v0_example/src/mmfv2_video_example/mmf2_video_example_av_mp4_init.c at main · Ameba-AIoT/ameba-rtos-pro2 · GitHub

You may also consider to record into a single large mp4 file without segmentation then split after using ffmpeg

ffmpeg -i input.mp4 -c copy -f segment -segment_time 10 -reset_timestamps 1 output_%03d.mp4

Thank you.