CM MP4 Record

The cmMp4Record is used to mux h264 and AAC to mp4 files. The following features are currently supported:

  • One video/x-raw input or one video/h264 input with prerecord.

  • One video/x-raw and one audio/x-raw input or one video/h264 and one audio/mpeg input with prerecord.

  • Duration control.

  • Seamless support, the user can set the seamless duration.

  • If the video input is video/x-raw, it supports saving the 1st YUV to jpeg as a thumbnail file.


API Instructions

create/destroy

If the input is prerecording data, the data will be processed as h264 and AAC. Otherwise, the input data will be processed as raw data and the record will encode them to h264 or AAC.

/* @prerec Input is prerec data */ gpointer cm_mp4_record_create(gboolean prerec); void cm_mp4_record_destroy(gpointer hd);

start/stop

void cm_mp4_record_start(gpointer hd); void cm_mp4_record_stop(gpointer hd);

parameters

/* @size Cache size for prerecord to avoid drop frame */ void cm_mp4_record_set_queue_size(gpointer hd, guint size ); /* @duration Record duration in seconds */ void cm_mp4_record_set_duration(gpointer hd, guint64 duration ); /* @duration FFmp4 fragment duration in seconds, default 2s */ void cm_mp4_record_set_fragment_duration(gpointer hd, guint64 duration ); /* @filename MP4 filename, xxxx.mp4 or xxxx%02d.mp4 if seamless enable */ void cm_mp4_record_set_filename(gpointer hd, gchar* filename); /* @thumb Save the 1st video to jpeg as thumbnail if set thumb */ void cm_mp4_record_set_thumbnail(gpointer hd, const char* thumb); /* @en Enable seamless mode */ void cm_mp4_record_set_seamless_mode(gpointer hd, gboolean en); /* @duration The seamless duration in seconds */ void cm_mp4_record_set_seamless_duration(gpointer hd, guint64 duration); void cm_mp4_record_set_bus_handler(gpointer hd, cm_bus_watch_ptr cb, gpointer user_data); /** * Get mp4 record control info. * @key start-pts, stop-pts, current-duration * @val value */ void cm_mp4_record_get_control_info(gpointer hd, gchar* key, gpointer *value);

It is important to send and wait for EOS before stopping the record, otherwise, the file can not be closed correctly. For mp4 files, this will cause the file to fail to play. For fmp4 files, this will cause the duration to be incorrect.

data

others


Demo

Mp4 Record Demo

Streaming Structure

Mux video/x-raw and audio/x-raw to mp4 file.

image-20240520-072801.png

Main codes

For more details please refer to the demo file.

Test Result

 

record-20240531-031202.png

The mp4 file can be displayed on the PC.