/applications/mp4box/main.c
C | 3480 lines | 3146 code | 213 blank | 121 comment | 1100 complexity | 0a46f563d3a9eabb437eb04a8c00a626 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- /*
- * GPAC - Multimedia Framework C SDK
- *
- * Copyright (c) Jean Le Feuvre 2000-2005
- * All rights reserved
- *
- * This file is part of GPAC / mp4box application
- *
- * GPAC is gf_free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * GPAC is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
- #include <gpac/scene_manager.h>
- #include <gpac/download.h>
- #ifdef GPAC_DISABLE_ISOM
- #error "Cannot compile MP4Box if GPAC is not built with ISO File Format support"
- #else
- #include <gpac/media_tools.h>
- /*RTP packetizer flags*/
- #include <gpac/ietf.h>
- #include <gpac/ismacryp.h>
- #include <gpac/constants.h>
- #include <gpac/internal/mpd.h>
- #include <time.h>
- #define BUFFSIZE 8192
- /*in fileimport.c*/
- #ifndef GPAC_DISABLE_ISOM_WRITE
- GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double force_fps, u32 frames_per_sample);
- GF_Err split_isomedia_file(GF_ISOFile *mp4, Double split_dur, u32 split_size_kb, char *inName, Double InterleavingTime, Double chunk_start, Bool adjust_split_end, char *outName, const char *tmpdir);
- GF_Err cat_isomedia_file(GF_ISOFile *mp4, char *fileName, u32 import_flags, Double force_fps, u32 frames_per_sample, char *tmp_dir, Bool force_cat);
- #if !defined(GPAC_DISABLE_MEDIA_IMPORT) && !defined(GPAC_DISABLE_SCENE_ENCODER)
- void convert_file_info(char *inName, u32 trackID);
- GF_Err EncodeFile(char *in, GF_ISOFile *mp4, GF_SMEncodeOptions *opts, FILE *logs);
- GF_Err EncodeFileChunk(char *chunkFile, char *bifs, char *inputContext, char *outputContext, const char *tmpdir);
- #endif
- GF_ISOFile *package_file(char *file_name, char *fcc, const char *tmpdir, Bool make_wgt);
- #endif
- GF_Err dump_cover_art(GF_ISOFile *file, char *inName);
- GF_Err dump_chapters(GF_ISOFile *file, char *inName);
- u32 id3_get_genre_tag(const char *name);
- /*in filedump.c*/
- #ifndef GPAC_DISABLE_SCENE_DUMP
- GF_Err dump_file_text(char *file, char *inName, u32 dump_mode, Bool do_log);
- #endif
- #ifndef GPAC_DISABLE_SCENE_STATS
- void dump_scene_stats(char *file, char *inName, u32 stat_level);
- #endif
- void PrintNode(const char *name, u32 graph_type);
- void PrintBuiltInNodes(u32 graph_type);
- #ifndef GPAC_DISABLE_ISOM_DUMP
- void dump_isom_xml(GF_ISOFile *file, char *inName);
- #endif
- #ifndef GPAC_DISABLE_ISOM_HINTING
- #ifndef GPAC_DISABLE_ISOM_DUMP
- void dump_file_rtp(GF_ISOFile *file, char *inName);
- #endif
- void DumpSDP(GF_ISOFile *file, char *inName);
- #endif
- void dump_file_ts(GF_ISOFile *file, char *inName);
- #ifndef GPAC_DISABLE_ISOM_DUMP
- void dump_file_ismacryp(GF_ISOFile *file, char *inName);
- void dump_timed_text_track(GF_ISOFile *file, u32 trackID, char *inName, Bool is_convert, u32 dump_type);
- #endif /*GPAC_DISABLE_ISOM_DUMP*/
- void DumpTrackInfo(GF_ISOFile *file, u32 trackID, Bool full_dump);
- void DumpMovieInfo(GF_ISOFile *file);
- void PrintLanguages();
- const char *GetLanguageCode(char *lang);
- #ifndef GPAC_DISABLE_MPEG2TS
- void dump_mpeg2_ts(char *mpeg2ts_file, char *pes_out_name, Bool prog_num,
- Double dash_duration, Bool seg_at_rap, u32 subseg_per_seg,
- char *seg_name, char *seg_ext, Bool use_url_template, Bool single_segment, u32 representation_idx, Bool last_rep);
- #endif
- #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
- void PrintStreamerUsage();
- int stream_file_rtp(int argc, char **argv);
- int live_session(int argc, char **argv);
- void PrintLiveUsage();
- #endif
- int mp4boxTerminal(int argc, char **argv);
- u32 quiet = 0;
- Bool dvbhdemux =0;
- Bool keep_sys_tracks = 0;
- /*some global vars for swf import :(*/
- u32 swf_flags = 0;
- Float swf_flatten_angle = 0;
- s32 laser_resolution = 0;
- typedef struct { u32 code; const char *name; const char *comment; } itunes_tag;
- static const itunes_tag itags[] = {
- {GF_ISOM_ITUNE_ALBUM_ARTIST, "album_artist", "usage: album_artist=album artist"},
- {GF_ISOM_ITUNE_ALBUM, "album", "usage: album=name" },
- {GF_ISOM_ITUNE_TRACKNUMBER, "tracknum", "usage: track=x/N"},
- {GF_ISOM_ITUNE_TRACK, "track", "usage: track=name"},
- {GF_ISOM_ITUNE_ARTIST, "artist", "usage: artist=name"},
- {GF_ISOM_ITUNE_COMMENT, "comment", "usage: comment=any comment"},
- {GF_ISOM_ITUNE_COMPILATION, "compilation", "usage: compilation=yes,no"},
- {GF_ISOM_ITUNE_COMPOSER, "composer", "usage: composer=name"},
- {GF_ISOM_ITUNE_CREATED, "created", "usage: created=time"},
- {GF_ISOM_ITUNE_DISK, "disk", "usage: disk=x/N"},
- {GF_ISOM_ITUNE_TOOL, "tool", "usage: tool=name"},
- {GF_ISOM_ITUNE_GENRE, "genre", "usage: genre=name"},
- {GF_ISOM_ITUNE_NAME, "name", "usage: name=name"},
- {GF_ISOM_ITUNE_TEMPO, "tempo", "usage: tempo=integer"},
- {GF_ISOM_ITUNE_WRITER, "writer", "usage: writer=name"},
- {GF_ISOM_ITUNE_GROUP, "group", "usage: group=name"},
- {GF_ISOM_ITUNE_COVER_ART, "cover", "usage: cover=file.jpg,file.png"},
- {GF_ISOM_ITUNE_ENCODER, "encoder", "usage: encoder=name"},
- {GF_ISOM_ITUNE_GAPLESS, "gapless", "usage: gapless=yes,no"},
- };
- u32 nb_itunes_tags = sizeof(itags) / sizeof(itunes_tag);
- void PrintVersion()
- {
- fprintf(stdout, "MP4Box - GPAC version " GPAC_FULL_VERSION "\n"
- "GPAC Copyright: (c) Jean Le Feuvre 2000-2005\n\t\t(c) ENST 2005-200X\n"
- "GPAC Configuration: " GPAC_CONFIGURATION "\n"
- "Features: %s\n", gpac_features());
- }
- void PrintGeneralUsage()
- {
- fprintf(stdout, "General Options:\n"
- #ifdef GPAC_MEMORY_TRACKING
- " -mem-track: enables memory tracker\n"
- #endif
- " -strict-error exits after the first error is reported\n"
- " -inter time_in_ms interleaves file data (track chunks of time_in_ms)\n"
- " * Note 1: Interleaving is 0.5s by default\n"
- " * Note 2: Performs drift checking accross tracks\n"
- " * Note 3: a value of 0 disables interleaving\n"
- " -old-inter time same as -inter but doesn't perform drift checking\n"
- " -tight performs tight interleaving (sample based) of the file\n"
- " * Note: reduces disk seek but increases file size\n"
- " -flat stores file with all media data first, non-interleaved\n"
- " -frag time_in_ms fragments file (track fragments of time_in_ms)\n"
- " * Note: Always disables interleaving\n"
- " -ffspace size inserts free space before moof in fragmented files\n"
- " -out filename specifies output file name\n"
- " * Note: By default input (MP4,3GP) file is overwritten\n"
- " -tmp dirname specifies directory for temporary file creation\n"
- " * Note: Default temp dir is OS-dependent\n"
- " -no-sys removes all MPEG-4 Systems info except IOD (profiles)\n"
- " * Note: Set by default whith '-add' and '-cat'\n"
- " -no-iod removes InitialObjectDescriptor from file\n"
- " -isma rewrites the file as an ISMA 1.0 AV file\n"
- " -ismax same as \'-isma\' and removes all clock references\n"
- " -3gp rewrites as 3GPP(2) file (no more MPEG-4 Systems Info)\n"
- " * Note 1: some tracks may be removed in the process\n"
- " * Note 2: always on for *.3gp *.3g2 *.3gpp\n"
- " -ipod rewrites the file for iPod\n"
- " -brand ABCD[:v] sets major brand of file, with optional version\n"
- " -ab ABCD adds given brand to file's alternate brand list\n"
- " -rb ABCD removes given brand from file's alternate brand list\n"
- " -cprt string adds copyright string to movie\n"
- " -chap file adds chapter information contained in file\n"
- " -rem trackID removes track from file\n"
- " -enable trackID enables track\n"
- " -disable trackID disables track\n"
- " -new forces creation of a new destination file\n"
- " -lang [tkID=]LAN sets track language. LAN is the ISO 639-2 code (eng, und)\n"
- " -delay tkID=TIME sets track start delay in ms.\n"
- " -par tkID=PAR sets visual track pixel aspect ratio (PAR=N:D or \"none\")\n"
- " -name tkID=NAME sets track handler name\n"
- " * NAME can indicate a UTF-8 file (\"file://file name\"\n"
- " -itags tag1[:tag2] sets iTunes tags to file - more info: MP4Box -tag-list.\n"
- " -split time_sec splits in files of time_sec max duration\n"
- " * Note: this removes all MPEG-4 Systems media\n"
- " -split-size size splits in files of max filesize kB. same as -splits.\n"
- " * Note: this removes all MPEG-4 Systems media\n"
- " -split-rap splits in files begining at each RAP. same as -splitr.\n"
- " * Note: this removes all MPEG-4 Systems media\n"
- " -split-chunk S:E extracts a new file from Start to End (in seconds). same as -splitx\n"
- " * Note: this removes all MPEG-4 Systems media\n"
- " -splitz S:E same as -split-chunk, but adjust the end time to be before the last RAP sample\n"
- " * Note: this removes all MPEG-4 Systems media\n"
- " -group-add fmt creates a new grouping information in the file. Format is\n"
- " a colon-separated list of following options:\n"
- " refTrack=ID: ID of the track used as a group reference.\n"
- " If not set, the track will belong to the same group as the previous trackID specified.\n"
- " If 0 or no previous track specified, a new alternate group will be created\n"
- " switchID=ID: ID of the switch group to create.\n"
- " If 0, a new ID will be computed for you\n"
- " If <0, disables SwitchGroup\n"
- " criteria=string: list of space-separated 4CCs.\n"
- " trackID=ID: ID of the track to add to this group.\n"
- "\n"
- " *WARNING* Options modify state as they are parsed:\n"
- " trackID=1:criteria=lang:trackID=2\n"
- " is different from:\n"
- " criteria=lang:trackID=1:trackID=2\n"
- "\n"
- " -group-rem-track ID removes track from its group\n"
- " -group-rem ID removes the track's group\n"
- " -group-clean removes all group information from all tracks\n"
- " -group-single puts all tracks in a single group\n"
- " -ref id:XXXX:refID adds a reference of type 4CC from track ID to track refID\n"
- "\n"
- " -dash dur enables DASH-ing of the file with a segment duration of DUR\n"
- " Note: the duration of a fragment (subsegment) is set\n"
- " using the interleaver (-inter) switch.\n"
- " Note: You can specify -rap switch to split segments at RAP boundaries\n"
- " Note: when single-segment is used, this specifies the duration of a subsegment\n"
- " -subsegs-per-sidx N sets the number of subsegments to be written in each SIDX box\n"
- " If 0, a single SIDX box is used per segment\n"
- " If -1, no SIDX box is used\n"
- " -rap segments begin with random access points\n"
- " Note: segment duration may not be exactly what asked by\n"
- " \"-dash\" since raw video data is not modified\n"
- " -segment-name name sets the segment name for generated segments\n"
- " If not set (default), segments are concatenated in output file\n"
- " -segment-ext name sets the segment extension. Default is m4s\n"
- " -url-template uses SegmentTemplate instead of explicit sources in segments.\n"
- " Ignored if segments are stored in the output file.\n"
- " -daisy-chain Uses daisy-chain SIDX instead of hierarchical. Ignored if frags/sidx is 0.\n"
- " -single-segment Uses a single segment for the whole file (OnDemand profile). \n"
- " -dash-ctx FILE Stores/restore DASH timing from FILE.\n"
- " -dash-ts-prog N program_number to be considered in case of an MPTS input file.\n"
- "\n");
- }
- void PrintFormats()
- {
- fprintf(stdout, "Suppported raw formats and file extensions:\n"
- " NHNT .media .nhnt .info\n"
- " NHML .nhml (opt: .media .info)\n"
- " MPEG-1-2 Video .m1v .m2v\n"
- " MPEG-4 Video .cmp .m4v\n"
- " H263 Video .263 .h263\n"
- " AVC/H264 Video .h264 .h26L .264 .26L\n"
- " JPEG Images .jpg .jpeg\n"
- " PNG Images .png\n"
- " MPEG 1-2 Audio .mp3, .m1a, .m2a\n"
- " ADTS-AAC Audio .aac\n"
- " AMR(WB) Audio .amr .awb\n"
- " EVRC Audio .evc\n"
- " SMV Audio .smv\n"
- "\n"
- "Supported containers and file extensions:\n"
- " AVI .avi\n"
- " MPEG-2 PS .mpg .mpeg .vob .vcd .svcd\n"
- " MPEG-2 TS .ts .m2t\n"
- " QCP .qcp\n"
- " OGG .ogg\n"
- " ISO-Media files no extension checking\n"
- "\n"
- "Supported text formats:\n"
- " SRT Subtitles .srt\n"
- " SUB Subtitles .sub\n"
- " GPAC Timed Text .ttxt\n"
- " QuickTime TeXML Text .xml (cf QT documentation)\n"
- "\n"
- "Supported Scene formats:\n"
- " MPEG-4 XMT-A .xmt .xmta .xmt.gz .xmta.gz\n"
- " MPEG-4 BT .bt .bt.gz\n"
- " VRML .wrl .wrl.gz\n"
- " X3D-XML .x3d .x3d.gz\n"
- " X3D-VRML .x3dv .x3dv.gz\n"
- " MacroMedia Flash .swf (very limitted import support only)\n"
- "\n"
- );
- }
- void PrintImportUsage()
- {
- fprintf(stdout, "Importing Options\n"
- "\nFile importing syntax:\n"
- " \"#video\" \"#audio\" base import for most AV files\n"
- " \"#trackID=ID\" track import for IsoMedia and other files\n"
- " \"#pid=ID\" stream import from MPEG-2 TS\n"
- " \":dur=D\" imports only the first D seconds\n"
- " \":lang=LAN\" sets imported media language code\n"
- " \":delay=delay_ms\" sets imported media initial delay in ms\n"
- " \":par=PAR\" sets visual pixel aspect ratio (PAR=Num:Den)\n"
- " \":name=NAME\" sets track handler name\n"
- " \":ext=EXT\" overrides file extension when importing\n"
- " \":hdlr=code\" sets track handler type to the given code point (4CC)\n"
- " \":disable\" imported track(s) will be disabled\n"
- " \":group=G\" adds the track as part of the G alternate group.\n"
- " If G is 0, the first available GroupID will be picked.\n"
- " \":fps=VAL\" same as -fps option\n"
- " \":agg=VAL\" same as -agg option\n"
- " \":par=VAL\" same as -par option\n"
- " \":dref\" same as -dref option\n"
- " \":nodrop\" same as -nodrop option\n"
- " \":packed\" same as -packed option\n"
- " \":sbr\" same as -sbr option\n"
- " \":sbrx\" same as -sbrx option\n"
- " \":ps\": same as -ps option\n"
- " \":psx\": same as -psx option\n"
- " \":ovsbr\": same as -ovsbr option\n"
- " \":mpeg4\" same as -mpeg4 option\n"
- " \":svc\" import SVC with explicit signaling (no AVC base compatibility)\n"
- " \":nosvc\" discard SVC data when importing\n"
- " \":subsamples\" adds SubSample information for AVC+SVC\n"
- " \":forcesync\" forces non IDR samples with I slices to be marked as sync points (AVC GDR)\n"
- " !! RESULTING FILE IS NOT COMPLIANT WITH THE SPEC but will fix seeking in most players\n"
- " \":font=name\" specifies font name for text import (default \"Serif\")\n"
- " \":size=s\" specifies font size for text import (default 18)\n"
- " \":stype=4CC\" forces the sample description type to a different value\n"
- " !! THIS MAY BREAK THE FILE WRITING !!\n"
- " \":chap\" specifies the track is a chapter track\n"
- " \":layout=WxHxXxY\" specifies the track layout\n"
- " - if W (resp H) = 0, the max width (resp height) of\n"
- " the tracks in the file are used.\n"
- " - if Y=-1, the layout is moved to the bottom of the\n"
- " track area\n"
- " - X and Y can be omitted (:layout=WxH)\n"
- "\n"
- " -add file add file tracks to (new) output file\n"
- " -cat file concatenates file samples to (new) output file\n"
- " * Note: creates tracks if needed\n"
- " -force-cat skips media configuration check when concatenating file\n"
- " !!! THIS MAY BREAK THE CONCATENATED TRACK(S) !!!\n"
- " -keep-sys keeps all MPEG-4 Systems info when using '-add' / 'cat'\n"
- " -keep-all keeps all existing tracks when using '-add'\n"
- " * Note: only used when adding IsoMedia files\n"
- "\n"
- "All the following options can be specified as default or for each track.\n"
- "When specified by track the syntax is \":opt\" or \":opt=val\".\n\n"
- " -dref keeps media data in original file\n"
- " -no-drop forces constant FPS when importing AVI video\n"
- " -packed forces packed bitstream when importing raw ASP\n"
- " -sbr backward compatible signaling of AAC-SBR\n"
- " -sbrx non-backward compatible signaling of AAC-SBR\n"
- " -ps: backward compatible signaling of AAC-PS\n"
- " -psx: non-backward compatible signaling of AAC-PS\n"
- " -ovsbr: oversample SBR\n"
- " * Note: SBR AAC, PS AAC and oversampled SBR cannot be detected at import time\n"
- " -fps FPS forces frame rate for video and SUB subtitles import\n"
- " FPS is either a number or expressed as timescale-increment\n"
- " * For raw H263 import, default FPS is 15\n"
- " * For all other imports, default FPS is 25\n"
- " !! THIS IS IGNORED FOR IsoMedia IMPORT !!\n"
- " -mpeg4 forces MPEG-4 sample descriptions when possible (3GPP2)\n"
- " For AAC, forces MPEG-4 AAC signaling even if MPEG-2\n"
- " -agg N aggregates N audio frames in 1 sample (3GP media only)\n"
- " * Note: Maximum value is 15 - Disabled by default\n"
- "\n"
- );
- }
- void PrintEncodeUsage()
- {
- fprintf(stdout, "MPEG-4 Scene Encoding Options\n"
- " -mp4 specify input file is for encoding.\n"
- " -def encode DEF names\n"
- " -sync time_in_ms forces BIFS sync sample generation every time_in_ms\n"
- " * Note: cannot be used with -shadow\n"
- " -shadow time_ms forces BIFS sync shadow sample generation every time_ms.\n"
- " * Note: cannot be used with -sync\n"
- " -log generates scene codec log file if available\n"
- " -ms file specifies file for track importing\n"
- "\nChunk Processing\n"
- " -ctx-in file specifies initial context (MP4/BT/XMT)\n"
- " * Note: input file must be a commands-only file\n"
- " -ctx-out file specifies storage of updated context (MP4/BT/XMT)\n"
- "\n"
- "LASeR Encoding options\n"
- " -resolution res resolution factor (-8 to 7, default 0)\n"
- " all coords are multiplied by 2^res before truncation\n"
- " -coord-bits bits bits used for encoding truncated coordinates\n"
- " (0 to 31, default 12)\n"
- " -scale-bits bits extra bits used for encoding truncated scales\n"
- " (0 to 4, default 0)\n"
- " -auto-quant res resolution is given as if using -resolution\n"
- " but coord-bits and scale-bits are infered\n"
- );
- }
- void PrintEncryptUsage()
- {
- fprintf(stdout, "ISMA Encryption/Decryption Options\n"
- " -crypt drm_file crypts a specific track using ISMA AES CTR 128\n"
- " -decrypt [drm_file] decrypts a specific track using ISMA AES CTR 128\n"
- " * Note: drm_file can be omitted if keys are in file\n"
- " -set-kms kms_uri changes KMS location for all tracks or a given one.\n"
- " * to adress a track, use \'tkID=kms_uri\'\n"
- "\n"
- "DRM file syntax for GPAC ISMACryp:\n"
- " File is XML and shall start with xml header\n"
- " File root is an \"ISMACryp\" element\n"
- " File is a list of \"ISMACrypTrack\" elements\n"
- "\n"
- "ISMACrypTrack attributes are\n"
- " TrackID ID of track to en/decrypt\n"
- " key AES-128 key formatted (hex string \'0x\'+32 chars)\n"
- " salt CTR IV salt key (64 bits) (hex string \'0x\'+16 chars)\n"
- "\nEncryption only attributes:\n"
- " Scheme_URI URI of scheme used\n"
- " KMS_URI URI of key management system\n"
- " * Note: \'self\' writes key and salt in the file\n"
- " selectiveType selective encryption type - understood values are:\n"
- " \"None\" all samples encrypted (default)\n"
- " \"RAP\" only encrypts random access units\n"
- " \"Non-RAP\" only encrypts non-random access units\n"
- " \"Rand\" random selection is performed\n"
- " \"X\" Encrypts every first sample out of X (uint)\n"
- " \"RandX\" Encrypts one random sample out of X (uint)\n"
- "\n"
- " ipmpType IPMP Signaling Type: None, IPMP, IPMPX\n"
- " ipmpDescriptorID IPMP_Descriptor ID to use if IPMP(X) is used\n"
- " * If not set MP4Box will generate one for you\n"
- "\n"
- );
- }
- void PrintHintUsage()
- {
- fprintf(stdout, "Hinting Options\n"
- " -hint hints the file for RTP/RTSP\n"
- " -mtu size specifies RTP MTU (max size) in bytes. Default size is 1450\n"
- " * Note: this includes the RTP header (12 bytes)\n"
- " -copy copies media data to hint track rather than reference\n"
- " * Note: speeds up server but takes much more space\n"
- " -multi [maxptime] enables frame concatenation in RTP packets if possible\n"
- " maxptime max packet duration in ms (optional, default 100ms)\n"
- " -rate ck_rate specifies rtp rate in Hz when no default for payload\n"
- " * Note: default value is 90000 (MPEG rtp rates)\n"
- " -mpeg4 forces MPEG-4 generic payload whenever possible\n"
- " -latm forces MPG4-LATM transport for AAC streams\n"
- " -static enables static RTP payload IDs whenever possible\n"
- " * By default, dynamic payloads are always used\n"
- "\n"
- "MPEG-4 Generic Payload Options\n"
- " -ocr forces all streams to be synchronized\n"
- " * Most RTSP servers only support synchronized streams\n"
- " -rap signals random access points in RTP packets\n"
- " -ts signals AU Time Stamps in RTP packets\n"
- " -size signals AU size in RTP packets\n"
- " -idx signals AU sequence numbers in RTP packets\n"
- " -iod prevents systems tracks embedding in IOD\n"
- " * Note: shouldn't be used with -isma option\n"
- "\n"
- " -add-sdp string adds sdp string to (hint) track (\"-add-sdp tkID:string\")\n"
- " or movie. This will take care of SDP lines ordering\n"
- " -unhint removes all hinting information.\n"
- "\n");
- }
- void PrintExtractUsage()
- {
- fprintf(stdout, "Extracting Options\n"
- " -raw TrackID extracts track in raw format when supported\n"
- " -raws TrackID extract each track sample to a file\n"
- " * Note: \"TrackID:N\" extracts Nth sample\n"
- " -nhnt TrackID extracts track in nhnt format\n"
- " -nhml TrackID extracts track in nhml format (XML nhnt).\n"
- " * Note: \"-nhml +TrackID\" for full dump\n"
- " -single TrackID extracts track to a new mp4 file\n"
- " -avi TrackID extracts visual track to an avi file\n"
- " -qcp TrackID same as \'-raw\' but defaults to QCP file for EVRC/SMV\n"
- " -aviraw TK extracts AVI track in raw format\n"
- " $TK can be one of \"video\" \"audio\" \"audioN\"\n"
- " -saf remux file to SAF multiplex\n"
- " -dvbhdemux demux DVB-H file into IP Datagrams\n"
- " * Note: can be used when encoding scene descriptions\n"
- " -diod extracts file IOD in raw format when supported\n"
- "\n");
- }
- void PrintDumpUsage()
- {
- fprintf(stdout, "Dumping Options\n"
- " -std dumps to stdout instead of file\n"
- " -info [trackID] prints movie info / track info if trackID specified\n"
- " * Note: for non IsoMedia files, gets import options\n"
- " -bt scene to bt format - removes unknown MPEG4 nodes\n"
- " -xmt scene to XMT-A format - removes unknown MPEG4 nodes\n"
- " -wrl scene VRML format - removes unknown VRML nodes\n"
- " -x3d scene to X3D/XML format - removes unknown X3D nodes\n"
- " -x3dv scene to X3D/VRML format - removes unknown X3D nodes\n"
- " -lsr scene to LASeR format\n"
- " -diso scene IsoMedia file boxes in XML output\n"
- " -drtp rtp hint samples structure to XML output\n"
- " -dts prints sample timing to text output\n"
- " -sdp dumps SDP description of hinted file\n"
- " -dcr ISMACryp samples structure to XML output\n"
- " -dump-cover Extracts cover art\n"
- " -dump-chap Extracts chapter file\n"
- "\n"
- #ifndef GPAC_DISABLE_ISOM_WRITE
- " -ttxt Converts input subtitle to GPAC TTXT format\n"
- #endif
- " -ttxt TrackID Dumps Text track to GPAC TTXT format\n"
- #ifndef GPAC_DISABLE_ISOM_WRITE
- " -srt Converts input subtitle to SRT format\n"
- #endif
- " -srt TrackID Dumps Text track to SRT format\n"
- "\n"
- " -stat generates node/field statistics for scene\n"
- " -stats generates node/field statistics per MPEG-4 Access Unit\n"
- " -statx generates node/field statistics for scene after each AU\n"
- "\n"
- " -hash generates SHA-1 Hash of the input file\n"
- "\n");
- }
- void PrintMetaUsage()
- {
- fprintf(stdout, "Meta handling Options\n"
- " -set-meta args sets given meta type - syntax: \"ABCD[:tk=ID]\"\n"
- " * ABCD: four char meta type (NULL or 0 to remove meta)\n"
- " * [:tk=ID]: if not set use root (file) meta\n"
- " if ID is 0 use moov meta\n"
- " if ID is not 0 use track meta\n"
- " -add-item args adds resource to meta\n"
- " * syntax: file_path + options (\':\' separated):\n"
- " tk=ID: meta adressing (file, moov, track)\n"
- " name=str: item name\n"
- " mime=mtype: item mime type\n"
- " encoding=enctype: item content-encoding type\n"
- " * file_path \"this\" or \"self\": item is the file itself\n"
- " -rem-item args removes resource from meta - syntax: item_ID[:tk=ID]\n"
- " -set-primary args sets item as primary for meta - syntax: item_ID[:tk=ID]\n"
- " -set-xml args sets meta XML data\n"
- " * syntax: xml_file_path[:tk=ID][:binary]\n"
- " -rem-xml [tk=ID] removes meta XML data\n"
- " -dump-xml args dumps meta XML to file - syntax file_path[:tk=ID]\n"
- " -dump-item args dumps item to file - syntax item_ID[:tk=ID][:path=fileName]\n"
- " -package packages input XML file into an ISO container\n"
- " * all media referenced except hyperlinks are added to file\n"
- " -mgt packages input XML file into an MPEG-U widget with ISO container.\n"
- " * all files contained in the current folder are added to the widget package\n"
- "\n");
- }
- void PrintSWFUsage()
- {
- fprintf(stdout,
- "SWF Importer Options\n"
- "\n"
- "MP4Box can import simple Macromedia Flash files (\".SWF\")\n"
- "You can specify a SWF input file with \'-bt\', \'-xmt\' and \'-mp4\' options\n"
- "\n"
- " -global all SWF defines are placed in first scene replace\n"
- " * Note: By default SWF defines are sent when needed\n"
- " -no-ctrl uses a single stream for movie control and dictionary\n"
- " * Note: this will disable ActionScript\n"
- " -no-text removes all SWF text\n"
- " -no-font removes all embedded SWF Fonts (terminal fonts used)\n"
- " -no-line removes all lines from SWF shapes\n"
- " -no-grad removes all gradients from swf shapes\n"
- " -quad uses quadratic bezier curves instead of cubic ones\n"
- " -xlp support for lines transparency and scalability\n"
- " -flatten ang complementary angle below which 2 lines are merged\n"
- " * Note: angle \'0\' means no flattening\n"
- "\n"
- );
- }
- void PrintUsage()
- {
- fprintf (stdout, "MP4Box [option] input [option]\n"
- " -h general general options help\n"
- " -h hint hinting options help\n"
- " -h import import options help\n"
- " -h encode encode options help\n"
- " -h meta meta handling options help\n"
- " -h extract extraction options help\n"
- " -h dump dump options help\n"
- " -h swf Flash (SWF) options help\n"
- " -h crypt ISMA E&A options help\n"
- " -h format supported formats help\n"
- " -h rtp file streamer help\n"
- " -h live BIFS streamer help\n"
- "\n"
- " -nodes lists supported MPEG4 nodes\n"
- " -node NodeName gets MPEG4 node syntax and QP info\n"
- " -xnodes lists supported X3D nodes\n"
- " -xnode NodeName gets X3D node syntax\n"
- " -snodes lists supported SVG nodes\n"
- " -snode NodeName gets SVG node syntax\n"
- " -languages lists supported ISO 639 languages\n"
- "\n"
- " -quiet quiet mode\n"
- " -noprog disables progress\n"
- " -v verbose mode\n"
- " -logs set log tools and levels, formatted as a ':'-separated list of toolX[:toolZ]@levelX\n"
- " -version gets build version\n"
- );
- }
- void scene_coding_log(void *cbk, u32 log_level, u32 log_tool, const char *fmt, va_list vlist)
- {
- FILE *logs = cbk;
- if (log_tool != GF_LOG_CODING) return;
- vfprintf(logs, fmt, vlist);
- fflush(logs);
- }
- #ifndef GPAC_DISABLE_ISOM_HINTING
- /*
- MP4 File Hinting
- */
- void SetupClockReferences(GF_ISOFile *file)
- {
- u32 i, count, ocr_id;
- count = gf_isom_get_track_count(file);
- if (count==1) return;
- ocr_id = 0;
- for (i=0; i<count; i++) {
- if (!gf_isom_is_track_in_root_od(file, i+1)) continue;
- ocr_id = gf_isom_get_track_id(file, i+1);
- break;
- }
- /*doesn't look like MP4*/
- if (!ocr_id) return;
- for (i=0; i<count; i++) {
- GF_ESD *esd = gf_isom_get_esd(file, i+1, 1);
- if (esd) {
- esd->OCRESID = ocr_id;
- gf_isom_change_mpeg4_description(file, i+1, 1, esd);
- gf_odf_desc_del((GF_Descriptor *) esd);
- }
- }
- }
- /*base RTP payload type used (you can specify your own types if needed)*/
- #define BASE_PAYT 96
- GF_Err HintFile(GF_ISOFile *file, u32 MTUSize, u32 max_ptime, u32 rtp_rate, u32 base_flags, Bool copy_data, Bool interleave, Bool regular_iod, Bool single_group)
- {
- GF_ESD *esd;
- GF_InitialObjectDescriptor *iod;
- u32 i, val, res, streamType;
- u32 sl_mode, prev_ocr, single_ocr, nb_done, tot_bw, bw, flags, spec_type;
- GF_Err e;
- char szPayload[30];
- GF_RTPHinter *hinter;
- Bool copy, has_iod, single_av;
- u8 init_payt = BASE_PAYT;
- u32 iod_mode, mtype;
- u32 media_group = 0;
- u8 media_prio = 0;
- tot_bw = 0;
- prev_ocr = 0;
- single_ocr = 1;
-
- has_iod = 1;
- iod = (GF_InitialObjectDescriptor *) gf_isom_get_root_od(file);
- if (!iod) has_iod = 0;
- else {
- if (!gf_list_count(iod->ESDescriptors)) has_iod = 0;
- gf_odf_desc_del((GF_Descriptor *) iod);
- }
- spec_type = gf_isom_guess_specification(file);
- single_av = single_group ? 1 : gf_isom_is_single_av(file);
- /*first make sure we use a systems track as base OCR*/
- for (i=0; i<gf_isom_get_track_count(file); i++) {
- res = gf_isom_get_media_type(file, i+1);
- if ((res==GF_ISOM_MEDIA_SCENE) || (res==GF_ISOM_MEDIA_OD)) {
- if (gf_isom_is_track_in_root_od(file, i+1)) {
- gf_isom_set_default_sync_track(file, i+1);
- break;
- }
- }
- }
- nb_done = 0;
- for (i=0; i<gf_isom_get_track_count(file); i++) {
- sl_mode = base_flags;
- copy = copy_data;
- /*skip emty tracks (mainly MPEG-4 interaction streams...*/
- if (!gf_isom_get_sample_count(file, i+1)) continue;
- if (!gf_isom_is_track_enabled(file, i+1)) {
- fprintf(stdout, "Track ID %d disabled - skipping hint\n", gf_isom_get_track_id(file, i+1) );
- continue;
- }
- mtype = gf_isom_get_media_type(file, i+1);
- switch (mtype) {
- case GF_ISOM_MEDIA_VISUAL:
- if (single_av) {
- media_group = 2;
- media_prio = 2;
- }
- break;
- case GF_ISOM_MEDIA_AUDIO:
- if (single_av) {
- media_group = 2;
- media_prio = 1;
- }
- break;
- case GF_ISOM_MEDIA_HINT:
- continue;
- default:
- /*no hinting of systems track on isma*/
- if (spec_type==GF_4CC('I','S','M','A')) continue;
- }
- mtype = gf_isom_get_media_subtype(file, i+1, 1);
- if ((mtype==GF_ISOM_SUBTYPE_MPEG4) || (mtype==GF_ISOM_SUBTYPE_MPEG4_CRYP) ) mtype = gf_isom_get_mpeg4_subtype(file, i+1, 1);
- if (!single_av) {
- /*one media per group only (we should prompt user for group selection)*/
- media_group ++;
- media_prio = 1;
- }
- streamType = 0;
- esd = gf_isom_get_esd(file, i+1, 1);
- if (esd) {
- streamType = esd->decoderConfig->streamType;
- if (!prev_ocr) {
- prev_ocr = esd->OCRESID;
- if (!esd->OCRESID) prev_ocr = esd->ESID;
- } else if (esd->OCRESID && prev_ocr != esd->OCRESID) {
- single_ocr = 0;
- }
- /*OD MUST BE WITHOUT REFERENCES*/
- if (streamType==1) copy = 1;
- }
- gf_odf_desc_del((GF_Descriptor *) esd);
- if (!regular_iod && gf_isom_is_track_in_root_od(file, i+1)) {
- /*single AU - check if base64 would fit in ESD (consider 33% overhead of base64), otherwise stream*/
- if (gf_isom_get_sample_count(file, i+1)==1) {
- GF_ISOSample *samp = gf_isom_get_sample(file, i+1, 1, &val);
- if (streamType) {
- res = gf_hinter_can_embbed_data(samp->data, samp->dataLength, streamType);
- } else {
- /*not a system track, we shall hint it*/
- res = 0;
- }
- if (samp) gf_isom_sample_del(&samp);
- if (res) continue;
- }
- }
- if (interleave) sl_mode |= GP_RTP_PCK_USE_INTERLEAVING;
- hinter = gf_hinter_track_new(file, i+1, MTUSize, max_ptime, rtp_rate, sl_mode, init_payt, copy, media_group, media_prio, &e);
- if (!hinter) {
- if (e) {
- fprintf(stdout, "Cannot create hinter (%s)\n", gf_error_to_string(e));
- if (!nb_done) return e;
- }
- continue;
- }
- bw = gf_hinter_track_get_bandwidth(hinter);
- tot_bw += bw;
- flags = gf_hinter_track_get_flags(hinter);
- gf_hinter_track_get_payload_name(hinter, szPayload);
- fprintf(stdout, "Hinting track ID %d - Type \"%s:%s\" (%s) - BW %d kbps\n", gf_isom_get_track_id(file, i+1), gf_4cc_to_str(mtype), gf_4cc_to_str(mtype), szPayload, bw);
- if (flags & GP_RTP_PCK_SYSTEMS_CAROUSEL) fprintf(stdout, "\tMPEG-4 Systems stream carousel enabled\n");
- /*
- if (flags & GP_RTP_PCK_FORCE_MPEG4) fprintf(stdout, "\tMPEG4 transport forced\n");
- if (flags & GP_RTP_PCK_USE_MULTI) fprintf(stdout, "\tRTP aggregation enabled\n");
- */
- e = gf_hinter_track_process(hinter);
- if (!e) e = gf_hinter_track_finalize(hinter, has_iod);
- gf_hinter_track_del(hinter);
-
- if (e) {
- fprintf(stdout, "Error while hinting (%s)\n", gf_error_to_string(e));
- if (!nb_done) return e;
- }
- init_payt++;
- nb_done ++;
- }
- if (has_iod) {
- iod_mode = GF_SDP_IOD_ISMA;
- if (regular_iod) iod_mode = GF_SDP_IOD_REGULAR;
- } else {
- iod_mode = GF_SDP_IOD_NONE;
- }
- gf_hinter_finalize(file, iod_mode, tot_bw);
- if (!single_ocr)
- fprintf(stdout, "Warning: at least 2 timelines found in the file\nThis may not be supported by servers/players\n\n");
- return GF_OK;
- }
- #endif /*GPAC_DISABLE_ISOM_HINTING*/
- #if !defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_AV_PARSERS)
- static void check_media_profile(GF_ISOFile *file, u32 track)
- {
- u8 PL;
- GF_M4ADecSpecInfo dsi;
- GF_ESD *esd = gf_isom_get_esd(file, track, 1);
- if (!esd) return;
- switch (esd->decoderConfig->streamType) {
- case 0x04:
- PL = gf_isom_get_pl_indication(file, GF_ISOM_PL_VISUAL);
- if (esd->decoderConfig->objectTypeIndication==GPAC_OTI_VIDEO_MPEG4_PART2) {
- GF_M4VDecSpecInfo dsi;
- gf_m4v_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &dsi);
- if (dsi.VideoPL > PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, dsi.VideoPL);
- } else if (esd->decoderConfig->objectTypeIndication==GPAC_OTI_VIDEO_AVC) {
- gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0x15);
- } else if (!PL) {
- gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0xFE);
- }
- break;
- case 0x05:
- PL = gf_isom_get_pl_indication(file, GF_ISOM_PL_AUDIO);
- switch (esd->decoderConfig->objectTypeIndication) {
- case GPAC_OTI_AUDIO_AAC_MPEG2_MP:
- case GPAC_OTI_AUDIO_AAC_MPEG2_LCP:
- case GPAC_OTI_AUDIO_AAC_MPEG2_SSRP:
- case GPAC_OTI_AUDIO_AAC_MPEG4:
- gf_m4a_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &dsi);
- if (dsi.audioPL > PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, dsi.audioPL);
- break;
- default:
- if (!PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0xFE);
- }
- break;
- }
- gf_odf_desc_del((GF_Descriptor *) esd);
- }
- void remove_systems_tracks(GF_ISOFile *file)
- {
- u32 i, count;
- count = gf_isom_get_track_count(file);
- if (count==1) return;
- /*force PL rewrite*/
- gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0);
- gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0);
- gf_isom_set_pl_indication(file, GF_ISOM_PL_OD, 1); /*the lib always remove IOD when no profiles are specified..*/
- for (i=0; i<gf_isom_get_track_count(file); i++) {
- switch (gf_isom_get_media_type(file, i+1)) {
- case GF_ISOM_MEDIA_VISUAL:
- case GF_ISOM_MEDIA_AUDIO:
- case GF_ISOM_MEDIA_TEXT:
- case GF_ISOM_MEDIA_SUBT:
- gf_isom_remove_track_from_root_od(file, i+1);
- check_media_profile(file, i+1);
- break;
- /*only remove real systems tracks (eg, delaing with scene description & presentation)
- but keep meta & all unknown tracks*/
- case GF_ISOM_MEDIA_SCENE:
- switch (gf_isom_get_media_subtype(file, i+1, 1)) {
- case GF_ISOM_MEDIA_DIMS:
- gf_isom_remove_track_from_root_od(file, i+1);
- continue;
- default:
- break;
- }
- case GF_ISOM_MEDIA_OD:
- case GF_ISOM_MEDIA_OCR:
- case GF_ISOM_MEDIA_MPEGJ:
- gf_isom_remove_track(file, i+1);
- i--;
- break;
- default:
- break;
- }
- }
- /*none required*/
- if (!gf_isom_get_pl_indication(file, GF_ISOM_PL_AUDIO)) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0xFF);
- if (!gf_isom_get_pl_indication(file, GF_ISOM_PL_VISUAL)) gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0xFF);
- gf_isom_set_pl_indication(file, GF_ISOM_PL_OD, 0xFF);
- gf_isom_set_pl_indication(file, GF_ISOM_PL_SCENE, 0xFF);
- gf_isom_set_pl_indication(file, GF_ISOM_PL_GRAPHICS, 0xFF);
- gf_isom_set_pl_indication(file, GF_ISOM_PL_INLINE, 0);
- }
- #endif /*!defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_AV_PARSERS)*/
- /*return value:
- 0: not supported
- 1: ISO media
- 2: input bt file (.bt, .wrl)
- 3: input XML file (.xmt)
- 4: input SVG file (.svg)
- 5: input SWF file (.swf)
- 6: input LASeR file (.lsr or .saf)
- */
- u32 get_file_type_by_ext(char *inName)
- {
- u32 type = 0;
- char *ext = strrchr(inName, '.');
- if (ext) {
- char *sep;
- if (!strcmp(ext, ".gz")) ext = strrchr(ext-1, '.');
- ext+=1;
- sep = strchr(ext, '.');
- if (sep) sep[0] = 0;
- if (!stricmp(ext, "mp4") || !stricmp(ext, "3gp") || !stricmp(ext, "mov") || !stricmp(ext, "3g2") || !stricmp(ext, "3gs")) type = 1;
- else if (!stricmp(ext, "bt") || !stricmp(ext, "wrl") || !stricmp(ext, "x3dv")) type = 2;
- else if (!stricmp(ext, "xmt") || !stricmp(ext, "x3d")) type = 3;
- else if (!stricmp(ext, "lsr") || !stricmp(ext, "saf")) type = 6;
- else if (!stricmp(ext, "svg")) type = 4;
- else if (!stricmp(ext, "xsr")) type = 4;
- else if (!stricmp(ext, "xml")) type = 4;
- else if (!stricmp(ext, "swf")) type = 5;
- else if (!stricmp(ext, "jp2")) {
- if (sep) sep[0] = '.';
- return 0;
- }
- else type = 0;
- if (sep) sep[0] = '.';
- }
- /*try open file in read mode*/
- if (!type && gf_isom_probe_file(inName)) type = 1;
- return type;
- }
- #ifndef GPAC_DISABLE_ISOM_WRITE
- static Bool can_convert_to_isma(GF_ISOFile *file)
- {
- u32 spec = gf_isom_guess_specification(file);
- if (spec==GF_4CC('I','S','M','A')) return 1;
- return 0;
- }
- #endif
- static void progress_quiet(const void *cbck, const char *title, u64 done, u64 total) { }
- typedef struct
- {
- u32 trackID;
- char *line;
- } SDPLine;
- typedef struct
- {
- /*actions:
- 0: set meta type
- 1: add item
- 2: rem item
- 3: set item primary
- 4: set XML
- 5: set binary XML
- 6: rem XML
- 7: dump item
- 8: dump XML
- */
- u32 act_type;
- Bool root_meta, use_dref;
- u32 trackID;
- u32 meta_4cc;
- char szPath[GF_MAX_PATH];
- char szName[1024], mime_type[1024], enc_type[1024];
- u32 item_id;
- } MetaAction;
- /*for SDP_EX, AddTrack and RemTrack*/
- #define MAX_CUMUL_OPS 20
- #ifndef GPAC_DISABLE_ISOM_WRITE
- static Bool parse_meta_args(MetaAction *meta, char *opts)
- {
- Bool ret = 0;
- char szSlot[1024], *next;
- meta->mime_type[0] = 0;
- meta->enc_type[0] = 0;
- meta->szName[0] = 0;
- meta->szPath[0] = 0;
- meta->trackID = 0;
- meta->root_meta = 1;
- if (!opts) return 0;
- while (1) {
- if (!opts || !opts[0]) return ret;
- if (opts[0]==':') opts += 1;
- strcpy(szSlot, opts);
- next = strchr(szSlot, ':');
- /*use ':' as separator, but beware DOS paths...*/
- if (next && next[1]=='\\') next = strchr(szSlot+2, ':');
- if (next) next[0] = 0;
-
- if (!strnicmp(szSlot, "tk=", 3)) {
- sscanf(szSlot, "tk=%u", &meta->trackID);
- meta->root_meta = 0;
- ret = 1;
- }
- else if (!strnicmp(szSlot, "name=", 5)) { strcpy(meta->szName, szSlot+5); ret = 1; }
- else if (!strnicmp(szSlot, "path=", 5)) { strcpy(meta->szPath, szSlot+5); ret = 1; }
- else if (!strnicmp(szSlot, "mime=", 5)) { strcpy(meta->mime_type, szSlot+5); ret = 1; }
- else if (!strnicmp(szSlot, "encoding=", 9)) { strcpy(meta->enc_type, szSlot+9); ret = 1; }
- else if (!strnicmp(szSlot, "dref", 4)) { meta->use_dref = 1; ret = 1; }
- else if (!stricmp(szSlot, "binary")) {
- if (meta->act_type==4) meta->act_type=5;
- ret = 1;
- }
- else if (!strchr(szSlot, '=')) {
- switch (meta->act_type) {
- case 0:
- if (!stricmp(szSlot, "null") || !stricmp(szSlot, "0")) meta->meta_4cc = 0;
- else meta->meta_4cc = GF_4CC(szSlot[0], szSlot[1], szSlot[2], szSlot[3]);
- ret = 1;
- break;
- case 1:
- case 4:
- case 7:
- strcpy(meta->szPath, szSlot);
- ret = 1;
- break;
- case 2:
- case 3:
- case 8:
- meta->item_id = atoi(szSlot);
- ret = 1;
- break;
- }
- }
- opts += strlen(szSlot);
- }
- return ret;
- }
- #endif
- typedef struct
- {
- /*0: set tsel param - 1 remove tsel - 2 remove all tsel info in alternate group - 3 remove all tsel info in file*/
- u32 act_type;
- u32 trackID;
- u32 refTrackID;
- u32 criteria[30];
- u32 nb_criteria;
- Bool is_switchGroup;
- u32 switchGroupID;
- } TSELAction;
- static Bool parse_tsel_args(TSELAction *tsel_list, char *opts, u32 *nb_tsel_act)
- {
- u32 act;
- u32 refTrackID = 0;
- Bool has_switch_id;
- u32 switch_id = 0;
- u32 criteria[30];
- u32 nb_criteria = 0;
- TSELAction *tsel_act;
- char szSlot[1024], *next;
- has_switch_id = 0;
- act = tsel_list[*nb_tsel_act].act_type;
-
- if (!opts) return 0;
- while (1) {
- if (!opts || !opts[0]) return 1;
- if (opts[0]==':') opts += 1;
- strcpy(szSlot, opts);
- next = strchr(szSlot, ':');
- /*use ':' as separator, but beware DOS paths...*/
- if (next && next[1]=='\\') next = strchr(szSlot+2, ':');
- if (next) next[0] = 0;
- if (!strnicmp(szSlot, "ref=", 4)) refTrackID = atoi(szSlot+4);
- else if (!strnicmp(szSlot, "switchID=", 9)) {
- if (atoi(szSlot+9)<0) {
- switch_id = 0;
- has_switch_id = 0;
- } else {
- switch_id = atoi(szSlot+9);
- has_switch_id = 1;
- }
- }
- else if (!strnicmp(szSlot, "switchID", 8)) {
- switch_id = 0;
- has_switch_id = 1;
- }
- else if (!strnicmp(szSlot, "criteria=", 9)) {
- u32 j=9;
- nb_criteria = 0;
- while (j+3<strlen(szSlot)) {
- criteria[nb_criteria] = GF_4CC(szSlot[j], szSlot[j+1], szSlot[j+2], szSlot[j+3]);
- j+=5;
- nb_criteria++;
- }
- }
- else if (!strnicmp(szSlot, "trackID=", 8) || !strchr(szSlot, '=') ) {
- if (*nb_tsel_act>=MAX_CUMUL_OPS) {
- fprintf(stdout, "Sorry - no more than %d track selection operations allowed\n", MAX_CUMUL_OPS);
- return 0;
- }
- tsel_act = &tsel_list[*nb_tsel_act];
- memset(tsel_act, 0, sizeof(TSELAction));
- tsel_act->act_type = act;
- tsel_act->trackID = strchr(szSlot, '=') ? atoi(szSlot+8) : atoi(szSlot);
- tsel_act->refTrackID = refTrackID;
- tsel_act->switchGroupID = switch_id;
- tsel_act->is_switchGroup = has_switch_id;
- tsel_act->nb_criteria = nb_criteria;
- memcpy(tsel_act->criteria, criteria, sizeof(u32)*nb_criteria);
- if (!refTrackID)
- refTrackID = tsel_act->trackID;
- (*nb_tsel_act) ++;
- }
- opts += strlen(szSlot);
- }
- return 1;
- }
- #define CHECK_NEXT_ARG if (i+1==(u32)argc) { fprintf(stdout, "Missing arg - please check usage\n"); return 1; }
- #define CHECK_META_OPS CHECK_NEXT_ARG if (nb_meta_act>=MAX_CUMUL_OPS) { fprintf(stdout, "Sorry - no more than %d meta operations allowed\n", MAX_CUMUL_OPS); return 1; }
- typedef struct
- {
- /*
- 0: rem track
- 1: set track language
- 2: set track delay
- 3: set track KMS URI
- 4: set visual track PAR if possible
- 5: set track handler name
- 6: enables track
- 7: disables track
- 8: referenceTrack
- */
- u32 act_type;
- /*track ID*/
- u32 trackID;
- char lang[4];
- s32 delay_ms;
- const char *kms;
- const char *hdl_name;
- s32 par_num, par_den;
- } TrackAction;
- enum
- {
- GF_ISOM_CONV_TYPE_ISMA = 1,
- GF_ISOM_CONV_TYPE_ISMA_EX,
- GF_ISOM_CONV_TYPE_3GPP,
- GF_ISOM_CONV_TYPE_IPOD,
- GF_ISOM_CONV_TYPE_PSP
- };
- /*for dash*/
- #define MAX_DASH_REP 30
- int mp4boxMain(int argc, char **argv)
- {
- char outfile[5000];
- GF_Err e;
- #ifndef GPAC_DISABLE_SCENE_ENCODER
- GF_SMEncodeOptions opts;
- #endif
- #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
- SDPLine sdp_lines[MAX_CUMUL_OPS];
- #endif
- Double InterleavingTime, split_duration, split_start, import_fps, dash_duration;
- MetaAction metas[MAX_CUMUL_OPS];
- TrackAction tracks[MAX_CUMUL_OPS];
- TSELAction tsel_acts[MAX_CUMUL_OPS];
- u64 movie_time;
- s32 subsegs_per_sidx;
- u32 brand_add[MAX_CUMUL_OPS];
- u32 i, MTUSize, stat_level, hint_flags, info_track_id, import_flags, nb_add, nb_cat, ismaCrypt, agg_samples, nb_sdp_ex, max_ptime, raw_sample_num, split_size, nb_meta_act, nb_track_act, rtp_rate, major_brand, nb_alt_brand_add, nb_alt_brand_rem, old_interleave, car_dur, minor_version, conv_type, nb_tsel_acts, program_number;
- Bool HintIt, needSave, FullInter, Frag, HintInter, dump_std, dump_rtp, dump_mode, regular_iod, trackID, HintCopy, remove_sys_tracks, remove_hint, force_new, remove_root_od, import_subtitle, dump_chap;
- Bool print_sdp, print_info, open_edit, track_dump_type, dump_isom, dump_cr, force_ocr, encode, do_log, do_flat, dump_srt, dump_ttxt, chunk_mode, dump_ts, do_saf, do_mpd, dump_m2ts, dump_cart, do_hash, verbose, force_cat, pack_wgt, single_group;
- char *inName, *outName, *arg, *mediaSource, *tmpdir, *input_ctx, *output_ctx, *drm_file, *avi2raw, *cprt, *chap_file, *pes_dump, *itunes_tags, *pack_file, *raw_cat, *seg_name, *dash_ctx;
- GF_ISOFile *file;
- Bool stream_rtp=0;
- Bool live_scene=0;
- Bool enable_mem_tracker = 0;
- Bool dump_iod=0;
- Bool daisy_chain_sidx=0;
- Bool single_segment=0;
- Bool use_url_template=0;
- Bool seg_at_rap =0;
- Bool adjust_split_end = 0;
- char *dash_inputs[MAX_DASH_REP];
- u32 nb_dash_inputs = 0;
- char *gf_logs = NULL;
- char *seg_ext = NULL;
- if (argc < 2) {
- PrintUsage();
- return 1;
- }
- nb_tsel_acts = nb_add = nb_cat = nb_track_act = nb_sdp_ex = max_ptime = raw_sample_num = nb_meta_act = rtp_rate = major_brand = nb_alt_brand_add = nb_alt_brand_rem = car_dur = minor_version = 0;
- e = GF_OK;
- split_duration = 0.0;
- split_start = -1.0;
- InterleavingTime = 0.5;
- dash_duration = 0.0;…
Large files files are truncated, but you can click here to view the full file