Parse all mp4 boxes

pull/891/head
winlin 8 years ago
parent 366d6bcb82
commit fe43a31d06

@ -3948,7 +3948,9 @@ int SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox)
while (stream->length() < (int)required) {
ssize_t nread;
if ((ret = rsio->read(buf, SRS_MP4_BUF_SIZE, &nread)) != ERROR_SUCCESS) {
srs_error("MP4 load failed, nread=%d, required=%d. ret=%d", nread, required, ret);
if (ret != ERROR_SYSTEM_FILE_EOF) {
srs_error("MP4 load failed, nread=%d, required=%d. ret=%d", nread, required, ret);
}
return ret;
}

@ -1715,7 +1715,7 @@ public:
/**
* Read a sample from mp4.
* @param pht The sample hanler type, audio/soun or video/vide.
* @param pft, The frame type. For video, it's SrsVideoAvcFrameType.
* @param pft, The frame type. For video, it's SrsVideoAvcFrameType. For audio, ignored.
* @param pct, The codec type. For video, it's SrsVideoAvcFrameTrait. For audio, it's SrsAudioAacFrameTrait.
* @param pdts The output dts in milliseconds.
* @param ppts The output pts in milliseconds.

@ -25,38 +25,91 @@
#include <srs_kernel_error.hpp>
#include <srs_service_log.hpp>
#include <srs_kernel_mp4.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_core_autofree.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
using namespace std;
// @global log and context.
ISrsLog* _srs_log = new SrsConsoleLog(SrsLogLevelTrace, false);
ISrsThreadContext* _srs_context = new SrsThreadContext();
void help(char** argv)
int parse(std::string mp4_file)
{
printf("Usage: %s <mp4_file>\n"
" mp4_file The MP4 file path to parse.\n"
"For example:\n"
" %s doc/source.200kbps.768x320.mp4\n",
argv[0], argv[0]);
int ret = ERROR_SUCCESS;
exit(0);
SrsFileReader fr;
if ((ret = fr.open(mp4_file)) != ERROR_SUCCESS) {
srs_error("Open MP4 file failed, ret=%d", ret);
return ret;
}
srs_trace("MP4 file open success");
SrsMp4BoxReader br;
if ((ret = br.initialize(&fr)) != ERROR_SUCCESS) {
srs_error("Open MP4 box reader failed, ret=%d", ret);
return ret;
}
srs_trace("MP4 box reader open success");
SrsSimpleStream stream;
while (true) {
SrsMp4Box* box = NULL;
SrsAutoFree(SrsMp4Box, box);
if ((ret = br.read(&stream, &box)) != ERROR_SUCCESS) {
if (ret != ERROR_SYSTEM_FILE_EOF) {
srs_error("Read MP4 box failed, ret=%d", ret);
}
return ret;
}
if ((ret = br.skip(box, &stream)) != ERROR_SUCCESS) {
srs_error("Skip MP4 box failed, ret=%d", ret);
return ret;
}
stringstream ss;
ss << "type=" << char(box->type>>24) << char(box->type>>16) << char(box->type>>8) << char(box->type)
<< ", size=" << box->sz();
srs_trace("MP4 box %s", ss.str().c_str());
}
return ret;
}
int main(int argc, char** argv)
{
printf("SRS MP4 parser/%d.%d.%d, show the mp4 boxes structure.\n",
int ret = ERROR_SUCCESS;
printf("SRS MP4 parser/%d.%d.%d, parse and show the mp4 boxes structure.\n",
VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);
if (argc < 2) {
help(argv);
printf("Usage: %s <mp4_file>\n"
" mp4_file The MP4 file path to parse.\n"
"For example:\n"
" %s doc/source.200kbps.768x320.mp4\n",
argv[0], argv[0]);
exit(-1);
}
string mp4_file = argv[1];
srs_trace("Parse MP4 file %s", mp4_file.c_str());
return 0;
ret = parse(mp4_file);
if (ret == ERROR_SYSTEM_FILE_EOF) {
srs_trace("Parse complete");
return 0;
}
return ret;
}

Loading…
Cancel
Save