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

相关文章

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Python中help()和dir()函数的使用

《Python中help()和dir()函数的使用》我们经常需要查看某个对象(如模块、类、函数等)的属性和方法,Python提供了两个内置函数help()和dir(),它们可以帮助我们快速了解代... 目录1. 引言2. help() 函数2.1 作用2.2 使用方法2.3 示例(1) 查看内置函数的帮助(

Linux脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

Python中使用uv创建环境及原理举例详解

《Python中使用uv创建环境及原理举例详解》uv是Astral团队开发的高性能Python工具,整合包管理、虚拟环境、Python版本控制等功能,:本文主要介绍Python中使用uv创建环境及... 目录一、uv工具简介核心特点:二、安装uv1. 通过pip安装2. 通过脚本安装验证安装:配置镜像源(可

LiteFlow轻量级工作流引擎使用示例详解

《LiteFlow轻量级工作流引擎使用示例详解》:本文主要介绍LiteFlow是一个灵活、简洁且轻量的工作流引擎,适合用于中小型项目和微服务架构中的流程编排,本文给大家介绍LiteFlow轻量级工... 目录1. LiteFlow 主要特点2. 工作流定义方式3. LiteFlow 流程示例4. LiteF

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.