使用libmp4v2解封装MP4文件

2024-08-21 16:04
文章标签 使用 封装 mp4 libmp4v2

本文主要是介绍使用libmp4v2解封装MP4文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近研究了一下使用libmp4v2库解封装MP4文件,将MP4文件解封装成H264视频文件和AAC音频文件

libmp4v2源码下载:https://github.com/TechSmith/mp4v2

示例代码:

/*
使用libmp4v2库解封装出视频帧和音频帧编译:gcc -g mp4_unpack.c  -o mp4_unpack -I./include -L./lib -lmp4v2参考文献:
https://blog.csdn.net/jay100500/article/details/52955232
https://blog.csdn.net/andyhuabing/article/details/40983423
https://www.cnblogs.com/0error1warning/p/13755920.html
https://blog.nowcoder.net/n/e8f9c78aa2e0453aa2800cce162435c5
https://blog.csdn.net/liukun321/article/details/25337425
https://www.cnblogs.com/zhangxuan/p/8809245.html*/
#include <stdio.h>
#include <mp4v2/mp4v2.h>
#include <stdlib.h>
#include <string.h>#define FRAME_WRITE_FILE  (1)
#define USE_PROVIDER      (0)
#define ADTS_HEADER_SIZE7  (7)
#define ADTS_HEADER_SIZE9  (9)#if defined(USE_PROVIDER) && (USE_PROVIDER != 0)
static void* my_open( const char* name, MP4FileMode mode)
{FILE *fp = NULL;const char* om;if (name == NULL || name[0] == '\0'){printf("[%s:%d] name is NULL\n", __FUNCTION__, __LINE__);return NULL; }switch(mode) {case FILEMODE_READ:     om = "rb";  break;case FILEMODE_MODIFY:   om = "r+b"; break;case FILEMODE_CREATE:   om = "w+b"; break;case FILEMODE_UNDEFINED:default:om = "rb";break;}fp = fopen(name, om);if (fp == NULL){printf("[%s:%d] file(%s) open failed!\n", __FUNCTION__, __LINE__, name);}return fp;
}static int my_seek(void* handle, int64_t pos)
{if (!handle){printf("[%s:%d] handle is NULL\n", __FUNCTION__, __LINE__);return 0;}int ret = fseeko((FILE*)handle, pos, SEEK_SET); // fseeko用于处理大文件return (ret != 0);
}static int my_read(void* handle, void* buffer, int64_t size, int64_t* nin, int64_t maxChunkSize)
{if (!handle){printf("[%s:%d] handle is NULL\n", __FUNCTION__, __LINE__);return 1;}if (!buffer || size <= 0){printf("[%s:%d] param is invalid\n", __FUNCTION__, __LINE__);return 1;}if (fread(buffer, size, 1, (FILE*)handle) != 1){return 1;}if (nin != NULL)*nin = size;return 0;
}static int my_write(void* handle, const void* buffer, int64_t size, int64_t* nout, int64_t maxChunkSize)
{if (!handle){printf("[%s:%d] handle is NULL\n", __FUNCTION__, __LINE__);return 1;}if (!buffer || size <= 0){printf("[%s:%d] param is invalid\n", __FUNCTION__, __LINE__);return 1;}if (fwrite( buffer, size, 1, (FILE*)handle ) != 1)return 1;if (nout != NULL)*nout = size;return 0;
}static int my_close (void* handle)
{if (!handle){printf("[%s:%d] handle is NULL\n", __FUNCTION__, __LINE__);return 0;}int ret = fclose((FILE*)handle); return (ret != 0);
}
#endif/*
获取h264视频流*/
static int get_h264_stream(const char *out_file, 
MP4FileHandle file_handle, 
MP4TrackId video_track_id, 
MP4SampleId total_frame,
uint8_t *sps, 
uint32_t spslen,
uint8_t *pps,
uint32_t ppslen)
{if (!file_handle){printf("[%s:%d] param file_handle error\n", __FUNCTION__, __LINE__);return -1;}#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0)if (out_file == NULL || out_file[0] == '\0'){printf("[%s:%d] param out_file is empty\n", __FUNCTION__, __LINE__);return -1;}FILE *fp = fopen(out_file, "wb");if (fp == NULL){printf("[%s:%d] fopen:%s failed\n", __FUNCTION__, __LINE__, out_file);return -1;}
#endifuint8_t nal_header[] = {0x00, 0x00, 0x00, 0x01};    uint8_t* data = NULL;uint32_t size = 0;MP4Timestamp start_time;MP4Duration duration;MP4Duration render_offset;bool is_sync_sample = 0; // 是否是关键帧MP4SampleId sample_id = 0;uint8_t* frame_data = NULL;uint16_t vid_width = MP4GetTrackVideoWidth(file_handle, video_track_id);uint16_t vid_height = MP4GetTrackVideoHeight(file_handle, video_track_id);double vid_fps = MP4GetTrackVideoFrameRate(file_handle, video_track_id);printf("[%s:%d] vid_width:%d, vid_height:%d, vid_fps:%f\n", __FUNCTION__, __LINE__, vid_width, vid_height, vid_fps);while(sample_id < total_frame){   sample_id++; // sample id can't be zeroif (!MP4ReadSample(file_handle, video_track_id, sample_id, &data, &size, &start_time, &duration, &render_offset, &is_sync_sample)){printf("[%s:%d] MP4ReadSample failed\n", __FUNCTION__, __LINE__);if (data != NULL){free(data);data = NULL;}continue;}frame_data = (uint8_t *)malloc(spslen + ppslen + size);if (!frame_data){printf("[%s:%d] out of memory\n", __FUNCTION__, __LINE__);if (data != NULL){free(data);data = NULL;}continue;}uint8_t *pos = frame_data;//IDR֡帧,写入sps和ppsif (is_sync_sample){//printf("[%s:%d] sample_id:%lu, total_frame:%lu\n", __FUNCTION__, __LINE__, sample_id, total_frame);memcpy(pos, sps, spslen); pos += spslen;memcpy(pos, pps, ppslen);pos += ppslen;}//h264frame 标准的h264帧,前面几个字节就是frame的长度,需要替换为标准的h264 nal头if (data != NULL && size > 4){data[0] = 0x00;data[1] = 0x00;data[2] = 0x00;data[3] = 0x01;memcpy(pos, data, size);pos += size;}/*如果传入MP4ReadSample的视频pData是null它内部就会new 一个内存如果传入的是已知的内存区域,则需要保证空间bigger than max frames size.*/if (data != NULL){free(data);data = NULL;}/*收集sps pps 和 sample Data,拼接成一帧h264数据*/if (pos != frame_data){
#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0) fwrite(frame_data, (pos - frame_data), 1, fp);
#endif// TODO:这里送入解码器解码}if (frame_data != NULL){free(frame_data);frame_data = NULL;}if (sample_id == total_frame)printf("[%s:%d] video sample finished, sample_id:%lu, total_frame:%lu\n", __FUNCTION__, __LINE__, sample_id, total_frame);}       #if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0) fflush(fp);fclose(fp);  
#endifreturn 0;
}/*
填充atds头参考
https://www.cnblogs.com/lidabo/p/7261558.html
https://blog.nowcoder.net/n/e8f9c78aa2e0453aa2800cce162435c5Structure{AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)Header consists of 7 or 9 bytes (without or with CRC).
}
Letter Length (bits) Description
A     12      syncword 0xFFF, all bits must be 1
B     1       MPEG Version: 0 for MPEG-4, 1 for MPEG-2
C     2       Layer: always 0
D     1       protection absent, Warning, set to 1 if there is no CRC and 0 if there is CRC
E     2       profile, the MPEG-4 Audio Object Type minus 1
F     4       MPEG-4 Sampling Frequency Index (15 is forbidden)
G     1       private stream, set to 0 when encoding, ignore when decoding
H     3       MPEG-4 Channel Configuration (in the case of 0, the channel configuration is sent via an inband PCE)
I     1       originality, set to 0 when encoding, ignore when decoding
J     1       home, set to 0 when encoding, ignore when decoding
K     1       copyrighted stream, set to 0 when encoding, ignore when decoding
L     1       copyright start, set to 0 when encoding, ignore when decoding
M     13      frame length, this value must include 7 or 9 bytes of header length: FrameLength =(D == 1 ? 7 : 9) + size(AACFrame)
O     11      Buffer fullness
P     2       Number of AAC frames (RDBs) in ADTS frame minus 1, for maximum compatibility always use 1 AAC frame per ADTS frame
Q     16      CRC if protection absent is 0Usage in MPEG-TS
ADTS packet must be a content of PES packet. Pack AAC data inside ADTS frame, than pack inside PES packet, then mux by TS packetizer.Usage in Shoutcast
ADTS frames goes one by one in TCP stream. Look for syncword, parse header and look for next syncword after.
*/
int fill_adts_header(
uint8_t* header, 
int head_size, 
int packet_len, 
int audio_rate_index, 
int audio_channel_count, 
uint8_t audio_type)
{int ret = -1;if (header == NULL){printf("[%s:%d] header is NULL\n", __FUNCTION__, __LINE__);return -1;} if (head_size != ADTS_HEADER_SIZE7 && head_size != (ADTS_HEADER_SIZE9)){printf("[%s:%d] param error, head_size:%d\n", __FUNCTION__, __LINE__, head_size);return -1;} int toal_len = head_size + packet_len; // ADTS帧长度包括 ADTS头大小 + AAC帧长//printf("[%s:%d] head_size:%d, packet_len:%d\n", __FUNCTION__, __LINE__, head_size, packet_len);if (ADTS_HEADER_SIZE7 == head_size) // fill in ADTS data{header[0] = (uint8_t)0xFF;header[1] = (uint8_t)0xF1;header[2] = (uint8_t)(((audio_type - 1) << 6) + (audio_rate_index << 2) + (audio_channel_count >> 2));header[3] = (uint8_t)(((audio_channel_count & 0x03) << 6) + (toal_len >> 11));header[4] = (uint8_t)((toal_len & 0x07FF) >> 3);header[5] = (uint8_t)(((toal_len & 0x07) << 5) + 0x1F);header[6] = (uint8_t)0xFC;ret = 0;}return ret;
}/*
获取acc数据
total_frame 音频总帧数
audio_rate_index 音频采样率索引
audio_channel_count 音频声道数
audio_type 音频类型,例如MPEG-4 AAC LC的值为0x02*/
static int get_aac_stream(
const char *out_file, 
MP4FileHandle file_handle, 
MP4TrackId audio_track_id, 
MP4SampleId total_frame,
int audio_rate_index,
int audio_channel_count,
uint8_t audio_type)
{if (!file_handle){printf("[%s:%d] param file_handle error\n", __FUNCTION__, __LINE__);return -1;}#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0)if (out_file == NULL || out_file[0] == '\0'){printf("[%s:%d] param out_file is empty\n", __FUNCTION__, __LINE__);return -1;}FILE *fp = fopen(out_file, "wb");if (fp == NULL){printf("[%s:%d] open file failed\n", __FUNCTION__, __LINE__);return -1;}
#endifMP4SampleId frame_index = 0; // uint8_t* data = NULL;uint32_t size = 0;MP4Timestamp start_time;MP4Duration duration;MP4Duration render_offset;bool is_sync_sample = 0; // 是否是关键帧while (frame_index < total_frame) // 获取acc数据帧{frame_index++; //MP4ReadSample函数的参数要求是从1开始/*如果传入MP4ReadSample的音频data是null,它内部就会new 一个内存如果传入的是已知的内存区域,则需要保证空间bigger then max frames size.*/if (!MP4ReadSample(file_handle, audio_track_id, frame_index, &data, &size, &start_time, &duration, &render_offset, &is_sync_sample)){printf("[%s:%d] MP4ReadSample failed\n", __FUNCTION__, __LINE__);if (data != NULL){free(data);data = NULL;}continue;}#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0)uint8_t header[ADTS_HEADER_SIZE7] = { 0 };// 编码AAC裸流的时候,会遇到写出来的AAC文件并不能在PC和手机上播放,很大的可能就是AAC文件的每一帧里缺少了ADTS头信息文件的包装拼接fill_adts_header(header, ADTS_HEADER_SIZE7, size, audio_rate_index, audio_channel_count, audio_type);fwrite(header, ADTS_HEADER_SIZE7, 1, fp); // 先写入adts头fwrite(data, size, 1, fp); // 再写入acc数据#endif// TODO:收集一帧acc数据,送入解码器if (data){free(data);data = NULL;}if (frame_index == total_frame)printf("[%s:%d] audio sample finished, frame_index:%lu, total_frame:%lu\n", __FUNCTION__, __LINE__, frame_index, total_frame);}#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0)	if (fp != NULL){fflush(fp);fclose(fp);}
#endifreturn 0;
} /*
解封装MP4文件成视频和音频*/
static int unpack_mp4_file(const char* mp4_file, const char *video_file, const char *audio_file)
{if (mp4_file == NULL || mp4_file[0] == '\0'){printf("[%s:%d] param mp4_file is empty\n", __FUNCTION__, __LINE__);   return -1;}#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0) if (video_file == NULL || video_file[0] == '\0'){printf("[%s:%d] param video_file is empty\n", __FUNCTION__, __LINE__);   return -1;}if (audio_file == NULL || audio_file[0] == '\0'){printf("[%s:%d] param audio_file is empty\n", __FUNCTION__, __LINE__);   return -1;}
#endifMP4FileHandle file_handle = MP4_INVALID_FILE_HANDLE;
#if defined(USE_PROVIDER) && (USE_PROVIDER != 0)MP4FileProvider provider;provider.open  = my_open;provider.seek  = my_seek;provider.read  = my_read;provider.write = my_write;provider.close = my_close;file_handle = MP4ReadProvider(mp4_file, &provider);
#elsefile_handle = MP4Read(mp4_file);
#endifif (file_handle == MP4_INVALID_FILE_HANDLE) {printf("[%s:%d] MP4Read failed\n", __FUNCTION__, __LINE__);return -1;}if (!MP4Dump(file_handle, 0)){printf("[%s:%d] MP4Dump failed\n", __FUNCTION__, __LINE__);}uint32_t track_count = MP4GetNumberOfTracks(file_handle, NULL, 0); // 获取所有的轨道数printf("[%s:%d] track_count = %u\n", __FUNCTION__, __LINE__, track_count);uint32_t file_time_scale = MP4GetTimeScale(file_handle); // 获取文件每秒刻度数printf("[%s:%d] file_time_scale = %u\n", __FUNCTION__, __LINE__, file_time_scale);MP4Duration file_duration = MP4GetDuration(file_handle); // 获取文件总刻度数printf("[%s:%d] file_duration = %llu\n", __FUNCTION__, __LINE__, file_duration);uint32_t msec = file_duration * 1000 / file_time_scale;// 总毫秒数 = 总刻度数*1000/每秒刻度数 => 先乘法可以降低误差printf("[%s:%d] msec = %u\n\n", __FUNCTION__, __LINE__, msec);MP4TrackId track_id = MP4_INVALID_TRACK_ID;MP4TrackId track_id_vid = MP4_INVALID_TRACK_ID;MP4TrackId tarck_id_aud = MP4_INVALID_TRACK_ID;uint32_t track_index = 0;MP4SampleId vid_samples_count = 0;MP4SampleId aud_samples_count = 0;uint32_t spslen = 0, ppslen = 0;uint8_t *sps = NULL;uint8_t *pps = NULL;int audio_rate_index = -1; // 音频采样率索引int audio_channel_count = 0; // 音频声道数uint8_t audio_type = 0x00; // 音频类型,例如MPEG-4 AAC LC的值为0x02for (track_index = 0; track_index < track_count; track_index++){track_id = MP4FindTrackId(file_handle, track_index, NULL, 0);printf("[%s:%d] track_index:%u, track_id:%u\n", __FUNCTION__, __LINE__, track_index, track_id);const char* type = MP4GetTrackType(file_handle, track_id);printf("[%s:%d] type:%s\n", __FUNCTION__, __LINE__, type);if (MP4_IS_VIDEO_TRACK_TYPE(type)) // 视频类型{const char* track_name = MP4GetTrackMediaDataName(file_handle, track_id);printf("[%s:%d] track_name:%s\n", __FUNCTION__, __LINE__, track_name);uint32_t time_scale = MP4GetTrackTimeScale(file_handle, track_id);printf("[%s:%d] time_scale:%u\n", __FUNCTION__, __LINE__, time_scale);//MP4Duration duration = MP4GetTrackDuration(file_handle, track_id);//printf("[%s:%d] duration:%llu\n", __FUNCTION__, __LINE__, duration);vid_samples_count = MP4GetTrackNumberOfSamples(file_handle, track_id);printf("[%s:%d] vid_samples_count:%u\n", __FUNCTION__, __LINE__, vid_samples_count);uint32_t bit_rate = MP4GetTrackBitRate(file_handle, track_id); // 比特率printf("[%s:%d] bit_rate:%u\n", __FUNCTION__, __LINE__, bit_rate);double video_frame_rate = MP4GetTrackVideoFrameRate(file_handle, track_id);printf("[%s:%d] video_frame_rate(fps):%f\n", __FUNCTION__, __LINE__, video_frame_rate);uint16_t vid_width = MP4GetTrackVideoWidth(file_handle, track_id);uint16_t vid_height = MP4GetTrackVideoHeight(file_handle, track_id);printf("[%s:%d] vid_width:%d, vid_height:%d\n", __FUNCTION__, __LINE__, vid_width, vid_height);uint32_t max_video = MP4GetTrackMaxSampleSize(file_handle, track_id);printf("[%s:%d] max_video:%u\n", __FUNCTION__, __LINE__, max_video);char* info = MP4Info(file_handle, track_id);if (info != NULL){printf("[%s:%d] info: %s\n", __FUNCTION__, __LINE__, info);free(info);}track_id_vid = track_id;uint8_t **seq_header;uint8_t **pict_header;uint32_t *pict_header_size;uint32_t *seq_header_size;uint32_t index = 0;uint32_t size = 0;uint8_t nal_header[] = {0x00, 0x00, 0x00, 0x01}; /*获取sps和pps*/if (!MP4GetTrackH264SeqPictHeaders(file_handle, track_id, &seq_header, &seq_header_size, &pict_header, &pict_header_size)){printf("[%s:%d] MP4GetTrackH264SeqPictHeaders failed\n", __FUNCTION__, __LINE__);continue;}// 统计sps的长度size = 4; // 加上4个字节的nal头for (index = 0; seq_header_size[index] != 0; index++){size += seq_header_size[index];printf("[%s:%d] size = %d, seq_header_size[%d] = %d\n", __FUNCTION__, __LINE__, size, index, seq_header_size[index]);}printf("[%s:%d] sps with nal size:%u\n", __FUNCTION__, __LINE__, size);sps = (uint8_t *)malloc(size);if (sps == NULL){MP4Free(seq_header);MP4Free(seq_header_size);MP4Free(pict_header);MP4Free(pict_header_size);goto end;}uint8_t *sps_base = sps;memcpy(sps_base, nal_header, 4);sps_base += 4;for (index = 0; seq_header_size[index] != 0; index++){memcpy(sps_base, seq_header[index], seq_header_size[index]);sps_base += seq_header_size[index];MP4Free(seq_header[index]);}MP4Free(seq_header);MP4Free(seq_header_size);spslen = size;// 统计pps的长度size = 4; //加上4个字节的nal头for (index = 0; pict_header_size[index] != 0; index++){size += pict_header_size[index];printf("[%s:%d] size = %u, pict_header_size[%d] = %u\n", __FUNCTION__, __LINE__, size, index, pict_header_size[index]);}printf("[%s:%d] pps with nal size:%lu\n", __FUNCTION__, __LINE__, size);pps = (uint8_t *)malloc(size);if (pps == NULL){MP4Free(seq_header);MP4Free(seq_header_size);MP4Free(pict_header);MP4Free(pict_header_size);goto end;}uint8_t *pps_base = pps;memcpy(pps_base, nal_header, 4);pps_base += 4;for (index = 0; pict_header_size[index] != 0; index++){memcpy(pps_base, pict_header[index], pict_header_size[index]);pps_base += pict_header_size[index];MP4Free(pict_header[index]);}MP4Free(pict_header);MP4Free(pict_header_size);ppslen = size;printf("[%s:%d] spslen(with nal):%u, ppslen(with nal):%u\n\n", __FUNCTION__, __LINE__, spslen, ppslen);}else if (MP4_IS_AUDIO_TRACK_TYPE(type)) // 音频类型{const char* track_name = MP4GetTrackMediaDataName(file_handle, track_id);printf("[%s:%d] track_name:%s\n", __FUNCTION__, __LINE__, track_name);uint32_t time_scale = MP4GetTrackTimeScale(file_handle, track_id); // 采样率printf("[%s:%d] time_scale:%u\n", __FUNCTION__, __LINE__, time_scale);//MP4Duration duration = MP4GetTrackDuration(file_handle, track_id);//printf("[%s:%d] duration:%llu\n", __FUNCTION__, __LINE__, duration);uint32_t bit_rate = MP4GetTrackBitRate(file_handle, track_id); // 比特率printf("[%s:%d] bit_rate:%u\n", __FUNCTION__, __LINE__, bit_rate);aud_samples_count = MP4GetTrackNumberOfSamples(file_handle, track_id); // 音频总帧数printf("[%s:%d] aud_samples_count:%u\n", __FUNCTION__, __LINE__, aud_samples_count);audio_channel_count = MP4GetTrackAudioChannels(file_handle, track_id); // 声道数printf("[%s:%d] channel_count:%d\n", __FUNCTION__, __LINE__, audio_channel_count);audio_type = MP4GetTrackAudioMpeg4Type(file_handle, track_id); // 音频类型printf("[%s:%d] audio_type:0x%02X\n", __FUNCTION__, __LINE__, audio_type);uint8_t audio_profile_level = MP4GetAudioProfileLevel(file_handle);printf("[%s:%d] audio_profile_level:0x%02X\n", __FUNCTION__, __LINE__, audio_profile_level);uint32_t max_audio = MP4GetTrackMaxSampleSize(file_handle, track_id);printf("[%s:%d] max_audio:%u\n", __FUNCTION__, __LINE__, max_audio);char* info = MP4Info(file_handle, track_id);if (info != NULL){printf("[%s:%d] info: %s\n", __FUNCTION__, __LINE__, info);free(info);}// 采样率与下标的关系, 参考 ffmpeg mpeg4audio.c int avpriv_mpeg4audio_sample_rates[16]uint32_t audio_sample_rates[] = {96000, 88200, 64000, 48000, 44100, 32000,24000, 22050, 16000, 12000, 11025, 8000, 7350};int i = 0;for (i = 0; i < sizeof(audio_sample_rates)/sizeof(int); i++){if (time_scale == audio_sample_rates[i]){audio_rate_index = i; // 例如: audio_time_scale == 48000 hz, audio_rate_index = 3break;}}if (audio_rate_index == -1){printf("[%s:%d] audio sample rate %d is not supported, audio_rate_index = %d\n", __FUNCTION__, __LINE__, time_scale, audio_rate_index);goto end;}tarck_id_aud = track_id;}else{printf("[%s:%d] unknow track type:%s\n", __FUNCTION__, __LINE__, type);}}// 解析视频帧if (track_id_vid > 0){get_h264_stream(video_file, file_handle, track_id_vid, vid_samples_count, sps, spslen, pps, ppslen);}// 解析音频帧if (tarck_id_aud > 0){get_aac_stream(audio_file, file_handle, tarck_id_aud, aud_samples_count, audio_rate_index, audio_channel_count, audio_type);}end:if (sps){free(sps);sps = NULL;}if (pps){free(pps);pps = NULL;}if (file_handle){MP4Close(file_handle, 0);file_handle = MP4_INVALID_FILE_HANDLE;}return 0;
}int main(int argc, char*argv[])
{char * video_file = NULL;char * audio_file = NULL;#if defined(FRAME_WRITE_FILE) && (FRAME_WRITE_FILE != 0) if (argc != 4) {printf("[%s:%d] usage: %s file.mp4 out_video.h264 out_audio.acc\n", __FUNCTION__, __LINE__, argv[0]);return -1;} 
#endifchar * file_name = argv[1];video_file = argv[2];audio_file = argv[3];unpack_mp4_file(file_name, video_file, audio_file);return 0;
}

这篇关于使用libmp4v2解封装MP4文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1093630

相关文章

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

C#下Newtonsoft.Json的具体使用

《C#下Newtonsoft.Json的具体使用》Newtonsoft.Json是一个非常流行的C#JSON序列化和反序列化库,它可以方便地将C#对象转换为JSON格式,或者将JSON数据解析为C#对... 目录安装 Newtonsoft.json基本用法1. 序列化 C# 对象为 JSON2. 反序列化

RabbitMQ 延时队列插件安装与使用示例详解(基于 Delayed Message Plugin)

《RabbitMQ延时队列插件安装与使用示例详解(基于DelayedMessagePlugin)》本文详解RabbitMQ通过安装rabbitmq_delayed_message_exchan... 目录 一、什么是 RabbitMQ 延时队列? 二、安装前准备✅ RabbitMQ 环境要求 三、安装延时队

Python ORM神器之SQLAlchemy基本使用完全指南

《PythonORM神器之SQLAlchemy基本使用完全指南》SQLAlchemy是Python主流ORM框架,通过对象化方式简化数据库操作,支持多数据库,提供引擎、会话、模型等核心组件,实现事务... 目录一、什么是SQLAlchemy?二、安装SQLAlchemy三、核心概念1. Engine(引擎)

Java Stream 并行流简介、使用与注意事项小结

《JavaStream并行流简介、使用与注意事项小结》Java8并行流基于StreamAPI,利用多核CPU提升计算密集型任务效率,但需注意线程安全、顺序不确定及线程池管理,可通过自定义线程池与C... 目录1. 并行流简介​特点:​2. 并行流的简单使用​示例:并行流的基本使用​3. 配合自定义线程池​示

GO语言中函数命名返回值的使用

《GO语言中函数命名返回值的使用》在Go语言中,函数可以为其返回值指定名称,这被称为命名返回值或命名返回参数,这种特性可以使代码更清晰,特别是在返回多个值时,感兴趣的可以了解一下... 目录基本语法函数命名返回特点代码示例命名特点基本语法func functionName(parameters) (nam

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

Java 正则表达式的使用实战案例

《Java正则表达式的使用实战案例》本文详细介绍了Java正则表达式的使用方法,涵盖语法细节、核心类方法、高级特性及实战案例,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录一、正则表达式语法详解1. 基础字符匹配2. 字符类([]定义)3. 量词(控制匹配次数)4. 边

Python Counter 函数使用案例

《PythonCounter函数使用案例》Counter是collections模块中的一个类,专门用于对可迭代对象中的元素进行计数,接下来通过本文给大家介绍PythonCounter函数使用案例... 目录一、Counter函数概述二、基本使用案例(一)列表元素计数(二)字符串字符计数(三)元组计数三、C

使用Spring Cache本地缓存示例代码

《使用SpringCache本地缓存示例代码》缓存是提高应用程序性能的重要手段,通过将频繁访问的数据存储在内存中,可以减少数据库访问次数,从而加速数据读取,:本文主要介绍使用SpringCac... 目录一、Spring Cache简介核心特点:二、基础配置1. 添加依赖2. 启用缓存3. 缓存配置方案方案