資源簡介
讀取MP4文件 解析MP4文件結構,獲取各個box屬性

代碼片段和文件信息
#include?“StdAfx.h“
#include?“Mp4Box.h“
#include?“Single.h“
#ifndef?FREE
#define?FREE(p)?if?(p)?free(p);?p?=?NULL;
#endif
#ifndef?ZERO
#define?ZERO(p)?memset(&p0sizeof?(p));
#endif
CMp4Box::CMp4Box(void)
{
memset?(&m_Header?0?sizeof?(m_Header));
m_Header.nSize?=?sizeof?(m_Header);
}
CMp4Box::~CMp4Box(void)
{
}
int?CMp4Box::Read?(FILE?*pFile)
{
if?(NULL?==?pFile)
return?-1;
fread?(&m_Header?1?sizeof?(m_Header)?pFile);
return?sizeof(m_Header);
}
int?CMp4Box::Write?(FILE?*pFile)
{
if?(NULL?==?pFile)
return?-1;
fwrite?(&m_Header?1?sizeof?(m_Header)?pFile);
return?sizeof(m_Header);
}
CMp4Ftyp::CMp4Ftyp()
{
m_nMajor?=?1;
m_nMinor?=?1;
m_nCount?=?0;
memset?(m_nCompatible?0?sizeof?(m_nCompatible));
memcpy?(&m_Header.nType?“ftyp“?sizeof(m_Header.nType));
}
CMp4Ftyp::~CMp4Ftyp()
{
}
int?CMp4Ftyp::Read?(FILE?*pFile)
{
if?(NULL?==?pFile)
return?-1;
int?nRet?=?0;
int?nRead?=?0;
nRead?=?fread?(&m_nMajor?1?sizeof?(m_nMajor)?pFile);
nRet?+=?nRead;
nRead?=?fread?(&m_nMinor?1?sizeof?(m_nMinor)?pFile);
nRet?+=?nRead;
m_nCount?=?(m_Header.nSize?-?sizeof?(m_nMajor)?-?sizeof?(m_nMinor))?/?sizeof(uint32_t);
if?(m_nCount?>?0)
{
int??nLastCount?=?0;
if?(?m_nCount?>=?10)
{
nLastCount?=?m_nCount?-?10;
m_nCount?=?10;
}
nRead?=?fread?(m_nCompatible?1?sizeof?(m_nCompatible[0])?*?m_nCount?pFile);
nRet?+=?nRead;
if?(nLastCount?>?0)
{
nRead?=?sizeof?(m_nCompatible[0])?*?nLastCount;
fseek?(pFile?nRead?SEEK_CUR);
nRet?+=?nRead;
}
}
return?nRet;
}
int?CMp4Ftyp::Write?(FILE?*pFile)
{
if?(NULL?==?pFile)
return?-1;
int?nRet?=?0;
m_Header.nSize?=?sizeof?(m_Header)?+?sizeof?(m_nMajor)?+?sizeof?(m_nMinor)?+?sizeof?(m_nCompatible[0])?*?m_nCount;
// m_Header.nSize?=?ConvertEndian();
nRet?=?fwrite(&m_Header?sizeof(m_Header)?1?pFile?);
return?nRet;
}
CMp4UserData::CMp4UserData()
{
memcpy?(&m_Header.nType?“udta“?sizeof(m_Header.nType));
}
CMp4UserData::~CMp4UserData()
{
}
int?CMp4UserData::Read?(FILE?*pFile)
{
return?0;
}
int?CMp4UserData::Write?(FILE?*pFile)
{
return?0;
}
/****************************************************/
/*?Moov?box
/*
/****************************************************/
//?moov
CMp4Moov::CMp4Moov()
{
m_nTrackCount?=?0;
memcpy?(&m_Header.nType?“moov“?sizeof(m_Header.nType));
}
CMp4Moov::~CMp4Moov()
{
}
int?CMp4Moov::Read?(FILE?*f?)
{
if?(NULL?==?f?)
return?-1;
int?nRet?=?0;
CMp4Trak?track;
CMp4Trak?*pTrack?=?NULL;
CMp4UserData?udta;
unsigned?char?p[5];?????????????????????????
int?nInnerSize?=?0;
int?nSubBoxSize?=?0;
int?nCusPos?=?ftell(?f);
int?nMoovDataSize?=?m_Header.nSize;
do
{
fseek(?f?nCusPos?SEEK_SET);
MP4_HEADER?Header;
int?nRead?=?fread?(&Header?1??BOX_HEAD_SIZE??f?);?//?sizeof?(Header)
nRet?+=?nRead;
nSubBoxSize?=?Single::Instance().PrintBoxHeadInfo(Heade
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????????0??2012-04-05?17:17??Mp4Parse\Mp4Parse\audio
?????文件??????32316??2012-04-12?15:10??Mp4Parse\Mp4Parse\Mp4Box.cpp
?????文件??????14968??2012-04-12?15:10??Mp4Parse\Mp4Parse\Mp4Box.h
?????文件????????541??2012-04-12?15:10??Mp4Parse\Mp4Parse\Mp4Parse.cpp
?????文件???????5069??2012-03-28?16:21??Mp4Parse\Mp4Parse\Mp4Parse.vcproj
?????文件???????1427??2012-03-30?11:05??Mp4Parse\Mp4Parse\Mp4Parse.vcproj.DHCC-8882492B3D.dch.user
?????文件???????1427??2012-04-12?15:12??Mp4Parse\Mp4Parse\Mp4Parse.vcproj.WWW-4A86108C845.Administrator.user
?????文件???????3274??2012-04-12?15:11??Mp4Parse\Mp4Parse\Mp4RW.cpp
?????文件???????1059??2012-04-11?16:01??Mp4Parse\Mp4Parse\Mp4RW.h
?????文件??????34218??2012-04-12?15:10??Mp4Parse\Mp4Parse\mp4_boxes.cpp
?????文件???????7547??2012-04-01?16:30??Mp4Parse\Mp4Parse\mp4_boxes.h
?????文件???????1372??2012-02-13?14:47??Mp4Parse\Mp4Parse\portable.h
?????文件???????1308??2012-02-13?14:36??Mp4Parse\Mp4Parse\ReadMe.txt
?????文件???????1276??2012-04-05?15:54??Mp4Parse\Mp4Parse\Single.cpp
?????文件???????1220??2012-04-05?16:27??Mp4Parse\Mp4Parse\Single.h
?????文件????????295??2012-02-13?14:36??Mp4Parse\Mp4Parse\stdafx.cpp
?????文件????????320??2012-02-13?14:36??Mp4Parse\Mp4Parse\stdafx.h
?????文件????????765??2012-02-13?14:36??Mp4Parse\Mp4Parse\targetver.h
?????文件???????3570??2012-04-10?15:09??Mp4Parse\Mp4Parse\Utls.h
?????文件??????????0??2012-04-05?17:17??Mp4Parse\Mp4Parse\video
?????文件??????34656??2012-03-21?10:25??Mp4Parse\Mp4Parse\復件?Mp4File.cpp
?????文件???????7196??2012-03-21?10:23??Mp4Parse\Mp4Parse\復件?Mp4File.h
?????文件????????890??2012-02-13?14:36??Mp4Parse\Mp4Parse.sln
????..A..H.?????49664??2012-04-12?15:12??Mp4Parse\Mp4Parse.suo
?????目錄??????????0??2012-04-12?15:12??Mp4Parse\Mp4Parse
?????目錄??????????0??2012-04-12?15:12??Mp4Parse
-----------?---------??----------?-----??----
???????????????204378????????????????????26
評論
共有 條評論