使用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

相关文章

Java中流式并行操作parallelStream的原理和使用方法

《Java中流式并行操作parallelStream的原理和使用方法》本文详细介绍了Java中的并行流(parallelStream)的原理、正确使用方法以及在实际业务中的应用案例,并指出在使用并行流... 目录Java中流式并行操作parallelStream0. 问题的产生1. 什么是parallelS

Linux join命令的使用及说明

《Linuxjoin命令的使用及说明》`join`命令用于在Linux中按字段将两个文件进行连接,类似于SQL的JOIN,它需要两个文件按用于匹配的字段排序,并且第一个文件的换行符必须是LF,`jo... 目录一. 基本语法二. 数据准备三. 指定文件的连接key四.-a输出指定文件的所有行五.-o指定输出

Linux jq命令的使用解读

《Linuxjq命令的使用解读》jq是一个强大的命令行工具,用于处理JSON数据,它可以用来查看、过滤、修改、格式化JSON数据,通过使用各种选项和过滤器,可以实现复杂的JSON处理任务... 目录一. 简介二. 选项2.1.2.2-c2.3-r2.4-R三. 字段提取3.1 普通字段3.2 数组字段四.

Linux kill正在执行的后台任务 kill进程组使用详解

《Linuxkill正在执行的后台任务kill进程组使用详解》文章介绍了两个脚本的功能和区别,以及执行这些脚本时遇到的进程管理问题,通过查看进程树、使用`kill`命令和`lsof`命令,分析了子... 目录零. 用到的命令一. 待执行的脚本二. 执行含子进程的脚本,并kill2.1 进程查看2.2 遇到的

详解SpringBoot+Ehcache使用示例

《详解SpringBoot+Ehcache使用示例》本文介绍了SpringBoot中配置Ehcache、自定义get/set方式,并实际使用缓存的过程,文中通过示例代码介绍的非常详细,对大家的学习或者... 目录摘要概念内存与磁盘持久化存储:配置灵活性:编码示例引入依赖:配置ehcache.XML文件:配置

Java 虚拟线程的创建与使用深度解析

《Java虚拟线程的创建与使用深度解析》虚拟线程是Java19中以预览特性形式引入,Java21起正式发布的轻量级线程,本文给大家介绍Java虚拟线程的创建与使用,感兴趣的朋友一起看看吧... 目录一、虚拟线程简介1.1 什么是虚拟线程?1.2 为什么需要虚拟线程?二、虚拟线程与平台线程对比代码对比示例:三

k8s按需创建PV和使用PVC详解

《k8s按需创建PV和使用PVC详解》Kubernetes中,PV和PVC用于管理持久存储,StorageClass实现动态PV分配,PVC声明存储需求并绑定PV,通过kubectl验证状态,注意回收... 目录1.按需创建 PV(使用 StorageClass)创建 StorageClass2.创建 PV

Redis 基本数据类型和使用详解

《Redis基本数据类型和使用详解》String是Redis最基本的数据类型,一个键对应一个值,它的功能十分强大,可以存储字符串、整数、浮点数等多种数据格式,本文给大家介绍Redis基本数据类型和... 目录一、Redis 入门介绍二、Redis 的五大基本数据类型2.1 String 类型2.2 Hash

Redis中Hash从使用过程到原理说明

《Redis中Hash从使用过程到原理说明》RedisHash结构用于存储字段-值对,适合对象数据,支持HSET、HGET等命令,采用ziplist或hashtable编码,通过渐进式rehash优化... 目录一、开篇:Hash就像超市的货架二、Hash的基本使用1. 常用命令示例2. Java操作示例三

Linux创建服务使用systemctl管理详解

《Linux创建服务使用systemctl管理详解》文章指导在Linux中创建systemd服务,设置文件权限为所有者读写、其他只读,重新加载配置,启动服务并检查状态,确保服务正常运行,关键步骤包括权... 目录创建服务 /usr/lib/systemd/system/设置服务文件权限:所有者读写js,其他