【VC开源代码栏目提醒】:本文主要为网学会员提供mp4creator.cpp,希望对需要mp4creator.cpp网友有所帮助,学习一下!
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* The Initial Developer of the Original Code is Cisco Systems Inc.
* Portions created by Cisco Systems Inc. are
* Copyright (C) Cisco Systems Inc. 2001-2002. All Rights Reserved.
*
* Contributor(s):
* Dave Mackie dmackie@cisco.com
*/
#define MP4CREATOR_GLOBALS
#include "mp4creator.h"
#include "
mpeg4ip_getopt.h"
// forward declarations
MP4TrackId* CreateMediaTracks(
MP4FileHandle mp4File,
const char* inputFileName);
void CreateHintTrack(
MP4FileHandle mp4File,
MP4TrackId mediaTrackId,
const char* payloadName,
bool interleave,
u_int16_t maxPayloadSize);
void ExtractTrack(
MP4FileHandle mp4File,
MP4TrackId trackId,
const char* outputFileName);
// external declarations
// track creators
MP4TrackId* AviCreator(
MP4FileHandle mp4File, const char* aviFileName);
MP4TrackId AacCreator(
MP4FileHandle mp4File, FILE* inFile);
MP4TrackId Mp3Creator(
MP4FileHandle mp4File, FILE* inFile);
MP4TrackId Mp4vCreator(
MP4FileHandle mp4File, FILE* inFile);
// main routine
int main(int argc, char** argv)
{
char* usageString =
"usage: %s <options> <mp4-file>\n"
" Options:\n"
" -create=<input-file> Create track from <input-file>\n"
" input files can be of type: .aac .mp3 .divx .mp4v .m4v .cmp .xvid\n"
" -extract=<track-id> Extract a track\n"
" -delete=<track-id> Delete a track\n"
" -hint[=<track-id>] Create hint track, also -H\n"
" -interleave Use interleaved audio payload format, also -I\n"
" -list List tracks in mp4 file\n"
" -mtu=<size> MTU for hint track\n"
" -optimize Optimize mp4 file layout\n"
" -payload=<payload> Rtp payload type \n"
" (use 3119 or mpa-robust for mp3 rfc 3119 support)\n"
" -rate=<fps> Video frame rate, e.g. 30 or 29.97\n"
" -timescale=<ticks> Time scale (ticks per second)\n"
" -verbose[=[1-5]] Enable debug messages\n"
" -version Display version information\n"
;
bool doCreate = false;
bool doExtract = false;
bool doDelete = false;
bool doHint = false;
bool doList = false;
bool doOptimize = false;
bool doInterleave = false;
char* mp4FileName = NULL;
char* inputFileName = NULL;
char* outputFileName = NULL;
char* payloadName = NULL;
MP4TrackId hintTrackId = MP4_INVALID_TRACK_ID;
MP4TrackId extractTrackId = MP4_INVALID_TRACK_ID;
MP4TrackId deleteTrackId = MP4_INVALID_TRACK_ID;
u_int16_t maxPayloadSize = 1460;
Verbosity = MP4_DETAILS_ERROR;
VideoFrameRate = 0; // determine from input file
Mp4TimeScale = 90000;
// begin processing command line
ProgName = argv[0];
while (true) {
int c = -1;
int option_index = 0;
static struct option long_options[] = {
{ "create", 1, 0, 'c' },
{ "delete", 1, 0, 'd' },
{ "extract", 1, 0, 'e' },
{ "help", 0, 0, '?' },
{ "hint", 2, 0, 'H' },
{ "interleave", 0, 0, 'I' },
{ "list", 0, 0, 'l' },
{ "mtu", 1, 0, 'm' },
{ "optimize", 0, 0, 'O' },
{ "payload", 1, 0, 'p' },
{ "rate", 1, 0, 'r' },
{ "timescale", 1, 0, 't' },
{ "verbose", 2, 0, 'v' },
{ "version", 0, 0, 'V' },
{ NULL, 0, 0, 0 }
};
c = getopt_long_only(argc, argv, "c:d:e:H::Ilm:Op:r:t:v::V",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'c':
doCreate = true;
inputFileName = optarg;
break;
case 'd':
if (sscanf(optarg, "%u", &deleteTrackId) != 1) {
fprintf(stderr,
"%s: bad track-id specified: %s\n",
ProgName, optarg);
exit(EXIT_COMMAND_LINE);
}
doDelete = true;
break;
case 'e':
if (sscanf(optarg, "%u", &extractTrackId) != 1) {
fprintf(stderr,
"%s: bad track-id specified: %s\n",
ProgName, optarg);
exit(EXIT_COMMAND_LINE);
}
doExtract = true;
break;
case 'H':
doHint = true;
if (optarg) {
if (sscanf(optarg, "%u", &hintTrackId) != 1) {
fprintf(stderr,
"%s: bad track-id specified: %s\n",
ProgName, optarg);
exit(EXIT_COMMAND_LINE);
}
}
break;
case 'I':
doInterleave = true;
break;
case 'l':
doList = true;
break;
case 'm':
u_int32_t mtu;
if (sscanf(optarg, "%u", &mtu) != 1 || mtu < 64) {
fpri