PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/ext/gpac/applications/mp4box/main.c

https://github.com/paulcbetts/yikes
C | 2488 lines | 2259 code | 129 blank | 100 comment | 830 complexity | c076cd6ae41e3e0f9504ead5c88ea99e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * GPAC - Multimedia Framework C SDK
  3. *
  4. * Copyright (c) Jean Le Feuvre 2000-2005
  5. * All rights reserved
  6. *
  7. * This file is part of GPAC / mp4box application
  8. *
  9. * GPAC is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * GPAC is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; see the file COPYING. If not, write to
  21. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. */
  24. #include <gpac/scene_manager.h>
  25. #include <gpac/media_tools.h>
  26. /*RTP packetizer flags*/
  27. #include <gpac/ietf.h>
  28. #include <gpac/ismacryp.h>
  29. #define BUFFSIZE 8192
  30. /*in fileimport.c*/
  31. #ifndef GPAC_READ_ONLY
  32. void convert_file_info(char *inName, u32 trackID);
  33. GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double force_fps, u32 frames_per_sample);
  34. GF_Err split_isomedia_file(GF_ISOFile *mp4, Double split_dur, u32 split_size_kb, char *inName, Double InterleavingTime, Double chunk_start, const char *tmpdir, char *outfile);
  35. GF_Err cat_isomedia_file(GF_ISOFile *mp4, char *fileName, u32 import_flags, Double force_fps, u32 frames_per_sample, char *tmp_dir);
  36. GF_Err EncodeFile(char *in, GF_ISOFile *mp4, GF_SMEncodeOptions *opts, FILE *logs);
  37. GF_Err EncodeFileChunk(char *chunkFile, char *bifs, char *inputContext, char *outputContext, const char *tmpdir);
  38. GF_ISOFile *package_file(char *file_name, char *fcc, const char *tmpdir);
  39. GF_Err dump_cover_art(GF_ISOFile *file, char *inName);
  40. u32 id3_get_genre_tag(const char *name);
  41. #endif
  42. /*in filedump.c*/
  43. #ifndef GPAC_READ_ONLY
  44. GF_Err dump_file_text(char *file, char *inName, u32 dump_mode, Bool do_log);
  45. void dump_scene_stats(char *file, char *inName, u32 stat_level);
  46. #endif
  47. void PrintNode(const char *name, u32 graph_type);
  48. void PrintBuiltInNodes(u32 graph_type);
  49. void dump_file_mp4(GF_ISOFile *file, char *inName);
  50. void dump_file_rtp(GF_ISOFile *file, char *inName);
  51. void dump_file_ts(GF_ISOFile *file, char *inName);
  52. void dump_file_ismacryp(GF_ISOFile *file, char *inName);
  53. void dump_timed_text_track(GF_ISOFile *file, u32 trackID, char *inName, Bool is_convert, u32 dump_type);
  54. void DumpSDP(GF_ISOFile *file, char *inName);
  55. void DumpTrackInfo(GF_ISOFile *file, u32 trackID, Bool full_dump);
  56. void DumpMovieInfo(GF_ISOFile *file);
  57. void PrintLanguages();
  58. const char *GetLanguageCode(char *lang);
  59. void dump_mpeg2_ts(char *mpeg2ts_in, char *pes_out_name);
  60. Bool quiet = 0;
  61. /*some global vars for swf import :(*/
  62. u32 swf_flags = 0;
  63. Float swf_flatten_angle = 0;
  64. s32 laser_resolution = 0;
  65. typedef struct { u32 code; const char *name; const char *comment; } itunes_tag;
  66. static const itunes_tag itags[] = {
  67. {GF_ISOM_ITUNE_ALBUM_ARTIST, "album_artist", "usage: album_artist=album artist"},
  68. {GF_ISOM_ITUNE_ALBUM, "album", "usage: album=name" },
  69. {GF_ISOM_ITUNE_TRACKNUMBER, "tracknum", "usage: track=x/N"},
  70. {GF_ISOM_ITUNE_TRACK, "track", "usage: track=name"},
  71. {GF_ISOM_ITUNE_ARTIST, "artist", "usage: artist=name"},
  72. {GF_ISOM_ITUNE_COMMENT, "comment", "usage: comment=any comment"},
  73. {GF_ISOM_ITUNE_COMPILATION, "compilation", "usage: compilation=yes,no"},
  74. {GF_ISOM_ITUNE_COMPOSER, "composer", "usage: composer=name"},
  75. {GF_ISOM_ITUNE_CREATED, "created", ""},
  76. {GF_ISOM_ITUNE_DISK, "disk", "usage: disk=x/N"},
  77. {GF_ISOM_ITUNE_TOOL, "tool", "usage: tool=name"},
  78. {GF_ISOM_ITUNE_GENRE, "genre", "usage: genre=name"},
  79. {GF_ISOM_ITUNE_NAME, "name", "usage: name=name"},
  80. {GF_ISOM_ITUNE_TEMPO, "tempo", "usage: tempo=integer"},
  81. {GF_ISOM_ITUNE_WRITER, "writer", "usage: writer=name"},
  82. {GF_ISOM_ITUNE_GROUP, "group", "usage: group=name"},
  83. {GF_ISOM_ITUNE_COVER_ART, "cover", "usage: covber=file.jpg,file.png"},
  84. {GF_ISOM_ITUNE_ENCODER, "encoder", "usage: encoder=name"},
  85. {GF_ISOM_ITUNE_GAPELESS, "gapeless", "usage: artist=yes,no"},
  86. };
  87. u32 nb_itunes_tags = sizeof(itags) / sizeof(itunes_tag);
  88. void PrintVersion()
  89. {
  90. fprintf(stdout, "MP4Box - GPAC version " GPAC_VERSION "\n"
  91. #ifdef GPAC_FIXED_POINT
  92. "GPAC compiled in fixed-point version\n"
  93. #endif
  94. #ifdef GPAC_READ_ONLY
  95. "GPAC compiled in read-only version\n"
  96. #endif
  97. "GPAC Copyright: (c) Jean Le Feuvre 2000-2005\n\t\t(c) ENST 2005-200X\n");
  98. }
  99. void PrintGeneralUsage()
  100. {
  101. fprintf(stdout, "General Options:\n"
  102. " -inter time_in_ms interleaves file data (track chunks of time_in_ms)\n"
  103. " * Note 1: Interleaving is 0.5s by default\n"
  104. " * Note 2: Performs drift checking accross tracks\n"
  105. " * Note 3: a value of 0 disables interleaving\n"
  106. " -old-inter time same as -inter but doesn't perform drift checking\n"
  107. " -tight: performs tight interleaving (sample based) of the file\n"
  108. " * Note: reduces disk seek but increases file size\n"
  109. " -flat stores file with all media data first, non-interleaved\n"
  110. " -frag time_in_ms fragments file (track fragments of time_in_ms)\n"
  111. " * Note: Always disables interleaving\n"
  112. " -out filename specifies output file name\n"
  113. " * Note: By default input (MP4,3GP) file is overwritten\n"
  114. " -tmp dirname specifies directory for temporary file creation\n"
  115. " * Note: Default temp dir is OS-dependent\n"
  116. " -no-sys removes all MPEG-4 Systems info except IOD (profiles)\n"
  117. " * Note: Set by default whith '-add' and '-cat'\n"
  118. " -no-iod removes InitialObjkectDescriptor from file\n"
  119. " -isma rewrites the file as an ISMA 1.0 AV file\n"
  120. " -ismax same as \'-isma\' and removes all clock references\n"
  121. " -3gp rewrites as 3GPP(2) file (no more MPEG-4 Systems Info)\n"
  122. " * Note 1: some tracks may be removed in the process\n"
  123. " * Note 2: always on for *.3gp *.3g2 *.3gpp\n"
  124. " -ipod rewrites the file for iPod\n"
  125. " -brand ABCD[:v] sets major brand of file, with optional version\n"
  126. " -ab ABCD adds given brand to file's alternate brand list\n"
  127. " -rb ABCD removes given brand from file's alternate brand list\n"
  128. " -cprt string adds copyright string to movie\n"
  129. " -chap file adds chapter information contained in file\n"
  130. " -rem trackID: removes track from file\n"
  131. " -new: forces creation of a new destination file\n"
  132. " -rem trackID: removes track from file\n"
  133. " -lang [tkID=]LAN: sets track language. LAN is the ISO 639-2 code (eng, und)\n"
  134. " -delay tkID=TIME: sets track start delay in ms.\n"
  135. " -par tkID=PAR: sets visual track pixel aspect ratio (PAR=N:D or \"none\")\n"
  136. " -name tkID=NAME: sets track handler name\n"
  137. " * NAME can indicate a UTF-8 file (\"file://file name\"\n"
  138. " -itags tag1[:tag2]: sets iTunes tags to file - more info: MP4Box -tag-list.\n"
  139. " -split time_sec splits in files of time_sec max duration\n"
  140. " * Note: this removes all MPEG-4 Systems media\n"
  141. " -split-size size splits in files of max filesize kB.\n"
  142. " * Note: this removes all MPEG-4 Systems media\n"
  143. " -split-chunk S:E extracts a new file from Start to End (in seconds)\n"
  144. " * Note: this removes all MPEG-4 Systems media\n"
  145. "\n");
  146. }
  147. void PrintFormats()
  148. {
  149. fprintf(stdout, "Suppported raw formats and file extensions:\n"
  150. " NHNT .media .nhnt .info\n"
  151. " NHML .nhml (opt: .media .info)\n"
  152. " MPEG-1-2 Video .m1v .m2v\n"
  153. " MPEG-4 Video .cmp .m4v\n"
  154. " H263 Video .263 .h263\n"
  155. " AVC/H264 Video .h264 .h26L .264 .26L\n"
  156. " JPEG Images .jpg .jpeg\n"
  157. " PNG Images .png\n"
  158. " MPEG 1-2 Audio .mp3, .m1a, .m2a\n"
  159. " ADTS-AAC Audio .aac\n"
  160. " AMR(WB) Audio .amr .awb\n"
  161. " EVRC Audio .evc\n"
  162. " SMV Audio .smv\n"
  163. "\n"
  164. "Supported containers and file extensions:\n"
  165. " AVI .avi\n"
  166. " MPEG-2 PS .mpg .mpeg .vob .vcd .svcd\n"
  167. " MPEG-2 TS .ts .m2t\n"
  168. " QCP .qcp\n"
  169. " OGG .ogg\n"
  170. " ISO-Media files no extension checking\n"
  171. "\n"
  172. "Supported text formats:\n"
  173. " SRT Subtitles .srt\n"
  174. " SUB Subtitles .sub\n"
  175. " GPAC Timed Text .ttxt\n"
  176. " QuickTime TeXML Text .xml (cf QT documentation)\n"
  177. "\n"
  178. "Supported Scene formats:\n"
  179. " MPEG-4 XMT-A .xmt .xmta .xmt.gz .xmta.gz\n"
  180. " MPEG-4 BT .bt .bt.gz\n"
  181. " VRML .wrl .wrl.gz\n"
  182. " X3D-XML .x3d .x3d.gz\n"
  183. " X3D-VRML .x3dv .x3dv.gz\n"
  184. " MacroMedia Flash .swf (very limitted import support only)\n"
  185. "\n"
  186. );
  187. }
  188. void PrintImportUsage()
  189. {
  190. fprintf(stdout, "Importing Options\n"
  191. "\nFile importing syntax:\n"
  192. " \"#video\" \"#audio\": base import for most AV files\n"
  193. " \"#trackID=ID\": track import for IsoMedia and other files\n"
  194. " \"#pid=ID\": stream import from MPEG-2 TS\n"
  195. " \":dur=D\": imports only the first D seconds\n"
  196. " \":lang=LAN\": sets imported media language code\n"
  197. " \":delay=delay_ms\": sets imported media initial delay in ms\n"
  198. " \":par=PAR\": sets visual pixel aspect ratio (PAR=Num:Den)\n"
  199. " \":name=NAME\": sets track handler name\n"
  200. " \":fps=VAL\": same as -fps option\n"
  201. " \":agg=VAL\": same as -agg option\n"
  202. " \":par=VAL\": same as -par option\n"
  203. " \":dref\": same as -dref option\n"
  204. " \":nodrop\": same as -nodrop option\n"
  205. " \":packed\": same as -packed option\n"
  206. " \":sbr\": same as -sbr option\n"
  207. " \":sbrx\": same as -sbrx option\n"
  208. " \":mpeg4\": same as -mpeg4 option\n"
  209. " \":font=name\": specifies font name for text import (default \"Serif\")\n"
  210. " \":size=s\": specifies font size for text import (default 18)\n"
  211. "\n"
  212. " -add file: add file tracks to (new) output file\n"
  213. " -cat file: concatenates file samples to (new) output file\n"
  214. " * Note: creates tracks if needed\n"
  215. " -keep-sys: keeps all MPEG-4 Systems info when using '-add' / 'cat'\n"
  216. " -keep-all: keeps all existing tracks when using '-add'\n"
  217. " * Note: only used when adding IsoMedia files\n"
  218. "\n"
  219. "All the following options can be specified as default or for each track.\n"
  220. "When specified by track the syntax is \":opt\" or \":opt=val\".\n\n"
  221. " -dref: keeps media data in original file\n"
  222. " -no-drop: forces constant FPS when importing AVI video\n"
  223. " -packed: * forces packed bitstream when importing raw ASP\n"
  224. " -sbr: backward compatible signaling of AAC-SBR\n"
  225. " -sbrx: non-backward compatible signaling of AAC-SBR\n"
  226. " * Note: SBR AAC cannot be detected at import time\n"
  227. " -fps FPS: forces frame rate for video and SUB subtitles import\n"
  228. " * For raw H263 import, default FPS is 15\n"
  229. " * For all other imports, default FPS is 25\n"
  230. " -- THIS IS IGNORED FOR IsoMedia IMPORT --\n"
  231. " -mpeg4: forces MPEG-4 sample descriptions when possible (3GPP2)\n"
  232. " -agg N: aggregates N audio frames in 1 sample (3GP media only)\n"
  233. " * Note: Maximum value is 15 - Disabled by default\n"
  234. "\n"
  235. );
  236. }
  237. void PrintEncodeUsage()
  238. {
  239. fprintf(stdout, "MPEG-4 Scene Encoding Options\n"
  240. " -mp4: specify input file is for encoding.\n"
  241. " -def: encode DEF names\n"
  242. " -sync time_in_ms: forces BIFS sync sample generation every time_in_ms\n"
  243. " * Note: cannot be used with -shadow\n"
  244. " -shadow time_ms: forces BIFS sync shadow sample generation every time_ms.\n"
  245. " * Note: cannot be used with -sync\n"
  246. " -log: generates scene codec log file if available\n"
  247. " -ms file: specifies file for track importing\n"
  248. "\nChunk Processing\n"
  249. " -ctx-in file: specifies initial context (MP4/BT/XMT)\n"
  250. " * Note: input file must be a commands-only file\n"
  251. " -ctx-out file: specifies storage of updated context (MP4/BT/XMT)\n"
  252. "\n"
  253. "LASeR Encoding options\n"
  254. " -auto_quant res: resolution is given as if using -resolution\n"
  255. " but coord-bits and scale-bits are infered\n"
  256. " -resolution res: resolution factor (-8 to 7, default 0)\n"
  257. " all coords are multiplied by 2^res before truncation\n"
  258. " -coord-bits bits: bits used for encoding truncated coordinates\n"
  259. " (0 to 31, default 12)\n"
  260. " -scale-bits bits: extra bits used for encoding truncated scales\n"
  261. " (0 to 4, default 0)\n"
  262. );
  263. }
  264. void PrintEncryptUsage()
  265. {
  266. fprintf(stdout, "ISMA Encryption/Decryption Options\n"
  267. " -crypt drm_file: crypts a specific track using ISMA AES CTR 128\n"
  268. " -decrypt [drm_file] decrypts a specific track using ISMA AES CTR 128\n"
  269. " * Note: drm_file can be omitted if keys are in file\n"
  270. " -set-kms kms_uri changes KMS location for all tracks or a given one.\n"
  271. " * to adress a track, use \'tkID=kms_uri\'\n"
  272. "\n"
  273. "DRM file syntax for GPAC ISMACryp:\n"
  274. " File is XML and shall start with xml header\n"
  275. " File root is an \"ISMACryp\" element\n"
  276. " File is a list of \"ISMACrypTrack\" elements\n"
  277. "\n"
  278. "ISMACrypTrack attributes are\n"
  279. " TrackID: ID of track to en/decrypt\n"
  280. " key: AES-128 key formatted (hex string \'0x\'+32 chars)\n"
  281. " salt: CTR IV salt key (64 bits) (hex string \'0x\'+16 chars)\n"
  282. "\nEncryption only attributes:\n"
  283. " Scheme_URI: URI of scheme used\n"
  284. " KMS_URI: URI of key management system\n"
  285. " * Note: \'self\' writes key and salt in the file\n"
  286. " selectiveType: selective encryption type - understood values are:\n"
  287. " \"None\": all samples encrypted (default)\n"
  288. " \"RAP\": only encrypts random access units\n"
  289. " \"Non-RAP\": only encrypts non-random access units\n"
  290. " \"Rand\": random selection is performed\n"
  291. " \"X\": Encrypts every first sample out of X (uint)\n"
  292. " \"RandX\": Encrypts one random sample out of X (uint)\n"
  293. "\n"
  294. " ipmpType: IPMP Signaling Type: None, IPMP, IPMPX\n"
  295. " ipmpDescriptorID: IPMP_Descriptor ID to use if IPMP(X) is used\n"
  296. " * If not set MP4Box will generate one for you\n"
  297. "\n"
  298. );
  299. }
  300. void PrintHintUsage()
  301. {
  302. fprintf(stdout, "Hinting Options\n"
  303. " -hint: hints the file for RTP/RTSP\n"
  304. " -mtu size: specifies RTP MTU (max size) in bytes. Default size is 1450\n"
  305. " * Note: this includes the RTP header (12 bytes)\n"
  306. " -copy: copies media data to hint track rather than reference\n"
  307. " * Note: speeds up server but takes much more space\n"
  308. " -multi [maxptime]: enables frame concatenation in RTP packets if possible\n"
  309. " maxptime: max packet duration in ms (optional, default 100ms)\n"
  310. " -rate ck_rate: specifies rtp rate in Hz when no default for payload\n"
  311. " * Note: default value is 90000 (MPEG rtp rates)\n"
  312. " -mpeg4: forces MPEG-4 generic payload whenever possible\n"
  313. " -latm: forces MPG4-LATM transport for AAC streams\n"
  314. " -static: enables static RTP payload IDs whenever possible\n"
  315. " * By default, dynamic payloads are always used\n"
  316. "\n"
  317. "MPEG-4 Generic Payload Options\n"
  318. " -ocr: forces all streams to be synchronized\n"
  319. " * Most RTSP servers only support synchronized streams\n"
  320. " -rap: signals random access points in RTP packets\n"
  321. " -ts: signals AU Time Stamps in RTP packets\n"
  322. " -size: signals AU size in RTP packets\n"
  323. " -idx: signals AU sequence numbers in RTP packets\n"
  324. " -iod: prevents systems tracks embedding in IOD\n"
  325. " * Note: shouldn't be used with -isma option\n"
  326. "\n"
  327. " -add-sdp string: adds sdp string to (hint) track (\"-add-sdp tkID:string\")\n"
  328. " or movie. This will take care of SDP lines ordering\n"
  329. " * WARNING: You cannot add anything to SDP, cf rfc2327.\n"
  330. " -unhint: removes all hinting information.\n"
  331. "\n");
  332. }
  333. void PrintExtractUsage()
  334. {
  335. fprintf(stdout, "Extracting Options\n"
  336. " -raw TrackID: extracts track in raw format when supported\n"
  337. " -raws TrackID: extract each track sample to a file\n"
  338. " * Note: \"TrackID:N\" extracts Nth sample\n"
  339. " -nhnt TrackID: extracts track in nhnt format\n"
  340. " -nhml TrackID: extracts track in nhml format (XML nhnt).\n"
  341. " * Note: \"-nhml +TrackID\" for full dump\n"
  342. " -single TrackID: extracts track to a new mp4 file\n"
  343. " -avi TrackID: extracts visual track to an avi file\n"
  344. " -qcp TrackID: same as \'-raw\' but defaults to QCP file for EVRC/SMV\n"
  345. " -aviraw TK: extracts AVI track in raw format\n"
  346. " $TK can be one of \"video\" \"audio\" \"audioN\"\n"
  347. " -saf: remux file to SAF multiplex\n"
  348. " * Note: can be used when encoding scene descriptions\n"
  349. "\n");
  350. }
  351. void PrintDumpUsage()
  352. {
  353. fprintf(stdout, "Dumping Options\n"
  354. " -std: dumps to stdout instead of file\n"
  355. " -info [trackID] prints movie info / track info if trackID specified\n"
  356. " * Note: for non IsoMedia files, gets import options\n"
  357. " -bt: scene to bt format - removes unknown MPEG4 nodes\n"
  358. " -xmt: scene to XMT-A format - removes unknown MPEG4 nodes\n"
  359. " -wrl: scene VRML format - removes unknown VRML nodes\n"
  360. " -x3d: scene to X3D/XML format - removes unknown X3D nodes\n"
  361. " -x3dv: scene to X3D/VRML format - removes unknown X3D nodes\n"
  362. " -lsr: scene to LASeR format\n"
  363. " -diso: scene IsoMedia file boxes in XML output\n"
  364. " -drtp: rtp hint samples structure to XML output\n"
  365. " -dts: prints sample timing to text output\n"
  366. " -sdp: dumps SDP description of hinted file\n"
  367. " -dcr: ISMACryp samples structure to XML output\n"
  368. "\n"
  369. #ifndef GPAC_READ_ONLY
  370. " -ttxt: Converts input subtitle to GPAC TTXT format\n"
  371. #endif
  372. " -ttxt TrackID: Dumps Text track to GPAC TTXT format\n"
  373. #ifndef GPAC_READ_ONLY
  374. " -srt: Converts input subtitle to SRT format\n"
  375. #endif
  376. " -srt TrackID: Dumps Text track to SRT format\n"
  377. "\n"
  378. " -stat: generates node/field statistics for scene\n"
  379. " -stats: generates node/field statistics per MPEG-4 Access Unit\n"
  380. " -statx: generates node/field statistics for scene after each AU\n"
  381. "\n"
  382. " -hash: generates SHA-1 Hash of the input file\n"
  383. "\n");
  384. }
  385. void PrintMetaUsage()
  386. {
  387. fprintf(stdout, "Meta handling Options\n"
  388. " -set-meta args: sets given meta type - syntax: \"ABCD[:tk=ID]\"\n"
  389. " * ABCD: four char meta type (NULL or 0 to remove meta)\n"
  390. " * [:tk=ID]: if not set use root (file) meta\n"
  391. " if ID is 0 use moov meta\n"
  392. " if ID is not 0 use track meta\n"
  393. " -add-item args: adds resource to meta\n"
  394. " * syntax: file_path + options (\':\' separated):\n"
  395. " tk=ID: meta adressing (file, moov, track)\n"
  396. " name=str: item name\n"
  397. " mime=mtype: item mime type\n"
  398. " encoding=enctype: item content-encoding type\n"
  399. " * file_path \"this\" or \"self\": item is the file itself\n"
  400. " -rem-item args: removes resource from meta - syntax: item_ID[:tk=ID]\n"
  401. " -set-primary args: sets item as primary for meta - syntax: item_ID[:tk=ID]\n"
  402. " -set-xml args: sets meta XML data\n"
  403. " * syntax: xml_file_path[:tk=ID][:binary]\n"
  404. " -rem-xml [tk=ID]: removes meta XML data\n"
  405. " -dump-xml args: dumps meta XML to file - syntax file_path[:tk=ID]\n"
  406. " -dump-item args: dumps item to file - syntax item_ID[:tk=ID][:path=fileName]\n"
  407. " -package: packages input XML file into an ISO container\n"
  408. " * all media referenced except hyperlinks are added to file\n"
  409. "\n");
  410. }
  411. void PrintSWFUsage()
  412. {
  413. fprintf(stdout,
  414. "SWF Importer Options\n"
  415. "\n"
  416. "MP4Box can import simple Macromedia Flash files (\".SWF\")\n"
  417. "You can specify a SWF input file with \'-bt\', \'xmt\' and \'-mp4\' options\n"
  418. "\n"
  419. " -global: all SWF defines are placed in first scene replace\n"
  420. " * Note: By default SWF defines are sent when needed\n"
  421. " -ctrl: uses a dedicated stream for movie control\n"
  422. " * Note: Forces \'-global\'\n"
  423. " -no-text: removes all SWF text\n"
  424. " -no-font: removes all embedded SWF Fonts (terminal fonts used)\n"
  425. " -no-line: removes all lines from SWF shapes\n"
  426. " -no-grad: removes all gradients from swf shapes\n"
  427. " -quad: uses quadratic bezier curves instead of cubic ones\n"
  428. " -xlp: support for lines transparency and scalability\n"
  429. " -flatten ang: complementary angle below which 2 lines are merged\n"
  430. " * Note: angle \'0\' means no flattening\n"
  431. "\n"
  432. );
  433. }
  434. void PrintUsage()
  435. {
  436. fprintf (stdout, "MP4Box [option] input [option]\n"
  437. #ifndef GPAC_READ_ONLY
  438. " -h general: general options help\n"
  439. " -h hint: hinting options help\n"
  440. " -h import: import options help\n"
  441. " -h encode: encode options help\n"
  442. " -h meta: meta handling options help\n"
  443. #else
  444. "READ-ONLY VERSION\n"
  445. #endif
  446. " -h extract: extraction options help\n"
  447. " -h dump: dump options help\n"
  448. " -h swf: Flash (SWF) options help\n"
  449. " -h crypt: ISMA E&A options help\n"
  450. " -h format: supported formats help\n"
  451. "\n"
  452. " -nodes: lists supported MPEG4 nodes\n"
  453. " -node NodeName: gets MPEG4 node syntax and QP info\n"
  454. " -xnodes: lists supported X3D nodes\n"
  455. " -xnode NodeName: gets X3D node syntax\n"
  456. " -snodes: lists supported SVG nodes\n"
  457. " -snode NodeName: gets SVG node syntax\n"
  458. " -languages: lists supported ISO 639 languages\n"
  459. "\n"
  460. "-quiet: quiet mode\n"
  461. " -v: verbose mode\n"
  462. " -version: gets build version\n"
  463. );
  464. }
  465. void scene_coding_log(void *cbk, u32 log_level, u32 log_tool, const char *fmt, va_list vlist)
  466. {
  467. FILE *logs = cbk;
  468. if (log_tool != GF_LOG_CODING) return;
  469. vfprintf(logs, fmt, vlist);
  470. fflush(logs);
  471. }
  472. #ifndef GPAC_READ_ONLY
  473. /*
  474. MP4 File Hinting
  475. */
  476. void SetupClockReferences(GF_ISOFile *file)
  477. {
  478. u32 i, count, ocr_id;
  479. count = gf_isom_get_track_count(file);
  480. if (count==1) return;
  481. ocr_id = 0;
  482. for (i=0; i<count; i++) {
  483. if (!gf_isom_is_track_in_root_od(file, i+1)) continue;
  484. ocr_id = gf_isom_get_track_id(file, i+1);
  485. break;
  486. }
  487. /*doesn't look like MP4*/
  488. if (!ocr_id) return;
  489. for (i=0; i<count; i++) {
  490. GF_ESD *esd = gf_isom_get_esd(file, i+1, 1);
  491. if (esd) {
  492. esd->OCRESID = ocr_id;
  493. gf_isom_change_mpeg4_description(file, i+1, 1, esd);
  494. gf_odf_desc_del((GF_Descriptor *) esd);
  495. }
  496. }
  497. }
  498. /*base RTP payload type used (you can specify your own types if needed)*/
  499. #define BASE_PAYT 96
  500. 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)
  501. {
  502. GF_ESD *esd;
  503. GF_InitialObjectDescriptor *iod;
  504. u32 i, val, res, streamType;
  505. u32 sl_mode, prev_ocr, single_ocr, nb_done, tot_bw, bw, flags, spec_type;
  506. GF_Err e;
  507. char szPayload[30];
  508. GF_RTPHinter *hinter;
  509. Bool copy, has_iod, single_av;
  510. u8 init_payt = BASE_PAYT;
  511. u32 iod_mode, mtype;
  512. u32 media_group = 0;
  513. u8 media_prio = 0;
  514. tot_bw = 0;
  515. prev_ocr = 0;
  516. single_ocr = 1;
  517. has_iod = 1;
  518. iod = (GF_InitialObjectDescriptor *) gf_isom_get_root_od(file);
  519. if (!iod) has_iod = 0;
  520. else {
  521. if (!gf_list_count(iod->ESDescriptors)) has_iod = 0;
  522. gf_odf_desc_del((GF_Descriptor *) iod);
  523. }
  524. spec_type = gf_isom_guess_specification(file);
  525. single_av = gf_isom_is_single_av(file);
  526. /*first make sure we use a systems track as base OCR*/
  527. for (i=0; i<gf_isom_get_track_count(file); i++) {
  528. res = gf_isom_get_media_type(file, i+1);
  529. if ((res==GF_ISOM_MEDIA_SCENE) || (res==GF_ISOM_MEDIA_OD)) {
  530. if (gf_isom_is_track_in_root_od(file, i+1)) {
  531. gf_isom_set_default_sync_track(file, i+1);
  532. break;
  533. }
  534. }
  535. }
  536. nb_done = 0;
  537. for (i=0; i<gf_isom_get_track_count(file); i++) {
  538. sl_mode = base_flags;
  539. copy = copy_data;
  540. /*skip emty tracks (mainly MPEG-4 interaction streams...*/
  541. if (!gf_isom_get_sample_count(file, i+1)) continue;
  542. mtype = gf_isom_get_media_type(file, i+1);
  543. switch (mtype) {
  544. case GF_ISOM_MEDIA_VISUAL:
  545. if (single_av) {
  546. media_group = 2;
  547. media_prio = 2;
  548. }
  549. break;
  550. case GF_ISOM_MEDIA_AUDIO:
  551. if (single_av) {
  552. media_group = 2;
  553. media_prio = 1;
  554. }
  555. break;
  556. case GF_ISOM_MEDIA_HINT:
  557. continue;
  558. default:
  559. /*no hinting of systems track on isma*/
  560. if (spec_type==GF_4CC('I','S','M','A')) continue;
  561. }
  562. mtype = gf_isom_get_media_subtype(file, i+1, 1);
  563. if ((mtype==GF_ISOM_SUBTYPE_MPEG4) || (mtype==GF_ISOM_SUBTYPE_MPEG4_CRYP) ) mtype = gf_isom_get_mpeg4_subtype(file, i+1, 1);
  564. if (!single_av) {
  565. /*one media per group only (we should prompt user for group selection)*/
  566. media_group ++;
  567. media_prio = 1;
  568. }
  569. streamType = 0;
  570. esd = gf_isom_get_esd(file, i+1, 1);
  571. if (esd) {
  572. streamType = esd->decoderConfig->streamType;
  573. if (!prev_ocr) {
  574. prev_ocr = esd->OCRESID;
  575. if (!esd->OCRESID) prev_ocr = esd->ESID;
  576. } else if (esd->OCRESID && prev_ocr != esd->OCRESID) {
  577. single_ocr = 0;
  578. }
  579. /*OD MUST BE WITHOUT REFERENCES*/
  580. if (streamType==1) copy = 1;
  581. }
  582. gf_odf_desc_del((GF_Descriptor *) esd);
  583. if (!regular_iod && gf_isom_is_track_in_root_od(file, i+1)) {
  584. /*single AU - check if base64 would fit in ESD (consider 33% overhead of base64), otherwise stream*/
  585. if (gf_isom_get_sample_count(file, i+1)==1) {
  586. GF_ISOSample *samp = gf_isom_get_sample(file, i+1, 1, &val);
  587. if (streamType) {
  588. res = gf_hinter_can_embbed_data(samp->data, samp->dataLength, streamType);
  589. } else {
  590. /*not a system track, we shall hint it*/
  591. res = 0;
  592. }
  593. if (samp) gf_isom_sample_del(&samp);
  594. if (res) continue;
  595. }
  596. }
  597. if (interleave) sl_mode |= GP_RTP_PCK_USE_INTERLEAVING;
  598. hinter = gf_hinter_track_new(file, i+1, MTUSize, max_ptime, rtp_rate, sl_mode, init_payt, copy, media_group, media_prio, &e);
  599. if (!hinter) {
  600. if (e) {
  601. fprintf(stdout, "Cannot create hinter (%s)\n", gf_error_to_string(e));
  602. if (!nb_done) return e;
  603. }
  604. continue;
  605. }
  606. bw = gf_hinter_track_get_bandwidth(hinter);
  607. tot_bw += bw;
  608. flags = gf_hinter_track_get_flags(hinter);
  609. gf_hinter_track_get_payload_name(hinter, szPayload);
  610. 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);
  611. if (flags & GP_RTP_PCK_AUTO_CAROUSEL) fprintf(stdout, "\tMPEG-4 Systems stream carousel enabled\n");
  612. /*
  613. if (flags & GP_RTP_PCK_FORCE_MPEG4) fprintf(stdout, "\tMPEG4 transport forced\n");
  614. if (flags & GP_RTP_PCK_USE_MULTI) fprintf(stdout, "\tRTP aggregation enabled\n");
  615. */
  616. e = gf_hinter_track_process(hinter);
  617. if (!e) e = gf_hinter_track_finalize(hinter, has_iod);
  618. gf_hinter_track_del(hinter);
  619. if (e) {
  620. fprintf(stdout, "Error while hinting (%s)\n", gf_error_to_string(e));
  621. if (!nb_done) return e;
  622. }
  623. init_payt++;
  624. nb_done ++;
  625. }
  626. if (has_iod) {
  627. iod_mode = GF_SDP_IOD_ISMA;
  628. if (regular_iod) iod_mode = GF_SDP_IOD_REGULAR;
  629. } else {
  630. iod_mode = GF_SDP_IOD_NONE;
  631. }
  632. gf_hinter_finalize(file, iod_mode, tot_bw);
  633. if (!single_ocr)
  634. fprintf(stdout, "Warning: at least 2 timelines found in the file\nThis may not be supported by servers/players\n\n");
  635. return GF_OK;
  636. }
  637. static void check_media_profile(GF_ISOFile *file, u32 track)
  638. {
  639. u8 PL;
  640. GF_M4ADecSpecInfo dsi;
  641. GF_ESD *esd = gf_isom_get_esd(file, track, 1);
  642. if (!esd) return;
  643. switch (esd->decoderConfig->streamType) {
  644. case 0x04:
  645. PL = gf_isom_get_pl_indication(file, GF_ISOM_PL_VISUAL);
  646. if (esd->decoderConfig->objectTypeIndication==0x20) {
  647. GF_M4VDecSpecInfo dsi;
  648. gf_m4v_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &dsi);
  649. if (dsi.VideoPL > PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, dsi.VideoPL);
  650. } else if (esd->decoderConfig->objectTypeIndication==0x21) {
  651. gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0x15);
  652. } else if (!PL) {
  653. gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0xFE);
  654. }
  655. break;
  656. case 0x05:
  657. PL = gf_isom_get_pl_indication(file, GF_ISOM_PL_AUDIO);
  658. switch (esd->decoderConfig->objectTypeIndication) {
  659. case 0x66: case 0x67: case 0x68: case 0x40:
  660. gf_m4a_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &dsi);
  661. if (dsi.audioPL > PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, dsi.audioPL);
  662. break;
  663. default:
  664. if (!PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0xFE);
  665. }
  666. break;
  667. }
  668. gf_odf_desc_del((GF_Descriptor *) esd);
  669. }
  670. void remove_systems_tracks(GF_ISOFile *file)
  671. {
  672. u32 i, count;
  673. count = gf_isom_get_track_count(file);
  674. if (count==1) return;
  675. /*force PL rewrite*/
  676. gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0);
  677. gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0);
  678. gf_isom_set_pl_indication(file, GF_ISOM_PL_OD, 1); /*the lib always remove IOD when no profiles are specified..*/
  679. for (i=0; i<gf_isom_get_track_count(file); i++) {
  680. switch (gf_isom_get_media_type(file, i+1)) {
  681. case GF_ISOM_MEDIA_VISUAL:
  682. case GF_ISOM_MEDIA_AUDIO:
  683. case GF_ISOM_MEDIA_TEXT:
  684. gf_isom_remove_track_from_root_od(file, i+1);
  685. check_media_profile(file, i+1);
  686. break;
  687. /*only remove real systems tracks (eg, delaing with scene description & presentation)
  688. but keep meta & all unknown tracks*/
  689. case GF_ISOM_MEDIA_SCENE:
  690. case GF_ISOM_MEDIA_OD:
  691. case GF_ISOM_MEDIA_OCR:
  692. case GF_ISOM_MEDIA_MPEGJ:
  693. gf_isom_remove_track(file, i+1);
  694. i--;
  695. break;
  696. default:
  697. break;
  698. }
  699. }
  700. /*none required*/
  701. if (!gf_isom_get_pl_indication(file, GF_ISOM_PL_AUDIO)) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0xFF);
  702. if (!gf_isom_get_pl_indication(file, GF_ISOM_PL_VISUAL)) gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0xFF);
  703. gf_isom_set_pl_indication(file, GF_ISOM_PL_OD, 0xFF);
  704. gf_isom_set_pl_indication(file, GF_ISOM_PL_SCENE, 0xFF);
  705. gf_isom_set_pl_indication(file, GF_ISOM_PL_GRAPHICS, 0xFF);
  706. gf_isom_set_pl_indication(file, GF_ISOM_PL_INLINE, 0);
  707. }
  708. #endif
  709. /*return value:
  710. 0: not supported
  711. 1: ISO media
  712. 2: input bt file (.bt, .wrl)
  713. 3: input XML file (.xmt)
  714. 4: input SVG file (.svg)
  715. 5: input SWF file (.swf)
  716. 6: input LASeR file (.lsr or .saf)
  717. */
  718. u32 get_file_type_by_ext(char *inName)
  719. {
  720. u32 type = 0;
  721. char *__ext = strrchr(inName, '.');
  722. if (__ext) {
  723. char ext[20];
  724. if (!strcmp(__ext, ".gz")) __ext = strrchr(__ext-1, '.');
  725. strcpy(ext, __ext+1);
  726. __ext = strchr(ext, '.');
  727. if (__ext) __ext[0] = 0;
  728. if (!stricmp(ext, "mp4") || !stricmp(ext, "3gp") || !stricmp(ext, "mov") || !stricmp(ext, "3g2")) type = 1;
  729. else if (!stricmp(ext, "bt") || !stricmp(ext, "wrl") || !stricmp(ext, "x3dv")) type = 2;
  730. else if (!stricmp(ext, "xmt") || !stricmp(ext, "x3d")) type = 3;
  731. else if (!stricmp(ext, "lsr") || !stricmp(ext, "saf")) type = 6;
  732. else if (!stricmp(ext, "svg")) type = 4;
  733. else if (!stricmp(ext, "xsr")) type = 4;
  734. else if (!stricmp(ext, "xml")) type = 4;
  735. else if (!stricmp(ext, "swf")) type = 5;
  736. else if (!stricmp(ext, "jp2")) return 0;
  737. else type = 0;
  738. }
  739. /*try open file in read mode*/
  740. if (!type && gf_isom_probe_file(inName)) type = 1;
  741. return type;
  742. }
  743. #ifndef GPAC_READ_ONLY
  744. static Bool can_convert_to_isma(GF_ISOFile *file)
  745. {
  746. u32 spec = gf_isom_guess_specification(file);
  747. if (spec==GF_4CC('I','S','M','A')) return 1;
  748. return 0;
  749. }
  750. #endif
  751. static void progress_quiet(void *cbck, char *title, u32 done, u32 total) { }
  752. typedef struct
  753. {
  754. u32 trackID;
  755. char *line;
  756. } SDPLine;
  757. typedef struct
  758. {
  759. /*actions:
  760. 0: set meta type
  761. 1: add item
  762. 2: rem item
  763. 3: set item primary
  764. 4: set XML
  765. 5: set binary XML
  766. 6: rem XML
  767. 7: dump item
  768. 8: dump XML
  769. */
  770. u32 act_type;
  771. Bool root_meta, use_dref;
  772. u32 trackID;
  773. u32 meta_4cc;
  774. char szPath[GF_MAX_PATH];
  775. char szName[1024], mime_type[1024], enc_type[1024];
  776. u32 item_id;
  777. } MetaAction;
  778. /*for SDP_EX, AddTrack and RemTrack*/
  779. #define MAX_CUMUL_OPS 20
  780. #ifndef GPAC_READ_ONLY
  781. static Bool parse_meta_args(MetaAction *meta, char *opts)
  782. {
  783. Bool ret = 0;
  784. char szSlot[1024], *next;
  785. meta->mime_type[0] = 0;
  786. meta->enc_type[0] = 0;
  787. meta->szName[0] = 0;
  788. meta->szPath[0] = 0;
  789. meta->trackID = 0;
  790. meta->root_meta = 1;
  791. if (!opts) return 0;
  792. while (1) {
  793. if (!opts || !opts[0]) return ret;
  794. if (opts[0]==':') opts += 1;
  795. strcpy(szSlot, opts);
  796. next = strchr(szSlot, ':');
  797. /*use ':' as separator, but beware DOS paths...*/
  798. if (next && next[1]=='\\') next = strchr(szSlot+2, ':');
  799. if (next) next[0] = 0;
  800. if (!strnicmp(szSlot, "tk=", 3)) {
  801. sscanf(szSlot, "tk=%d", &meta->trackID);
  802. meta->root_meta = 0;
  803. ret = 1;
  804. }
  805. else if (!strnicmp(szSlot, "name=", 5)) { strcpy(meta->szName, szSlot+5); ret = 1; }
  806. else if (!strnicmp(szSlot, "path=", 5)) { strcpy(meta->szPath, szSlot+5); ret = 1; }
  807. else if (!strnicmp(szSlot, "mime=", 5)) { strcpy(meta->mime_type, szSlot+5); ret = 1; }
  808. else if (!strnicmp(szSlot, "encoding=", 9)) { strcpy(meta->enc_type, szSlot+9); ret = 1; }
  809. else if (!strnicmp(szSlot, "dref", 4)) { meta->use_dref = 1; ret = 1; }
  810. else if (!stricmp(szSlot, "binary")) {
  811. if (meta->act_type==4) meta->act_type=5;
  812. ret = 1;
  813. }
  814. else if (!strchr(szSlot, '=')) {
  815. switch (meta->act_type) {
  816. case 0:
  817. if (!stricmp(szSlot, "null") || !stricmp(szSlot, "0")) meta->meta_4cc = 0;
  818. else meta->meta_4cc = GF_4CC(szSlot[0], szSlot[1], szSlot[2], szSlot[3]);
  819. ret = 1;
  820. break;
  821. case 1:
  822. case 4:
  823. case 7:
  824. strcpy(meta->szPath, szSlot);
  825. ret = 1;
  826. break;
  827. case 2:
  828. case 3:
  829. case 8:
  830. meta->item_id = atoi(szSlot);
  831. ret = 1;
  832. break;
  833. }
  834. }
  835. opts += strlen(szSlot);
  836. }
  837. return ret;
  838. }
  839. #endif
  840. #define CHECK_NEXT_ARG if (i+1==(u32)argc) { fprintf(stdout, "Missing arg - please check usage\n"); return 1; }
  841. #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; }
  842. typedef struct
  843. {
  844. /*
  845. 0: rem track
  846. 1: set track language
  847. 2: set track delay
  848. 3: set track KMS URI
  849. 4: set visual track PAR if possible
  850. 5: set track handler name
  851. */
  852. u32 act_type;
  853. /*track ID*/
  854. u32 trackID;
  855. char lang[4];
  856. s32 delay_ms;
  857. const char *kms;
  858. const char *hdl_name;
  859. s32 par_num, par_den;
  860. } TrackAction;
  861. enum
  862. {
  863. GF_ISOM_CONV_TYPE_ISMA = 1,
  864. GF_ISOM_CONV_TYPE_ISMA_EX,
  865. GF_ISOM_CONV_TYPE_3GPP,
  866. GF_ISOM_CONV_TYPE_IPOD,
  867. GF_ISOM_CONV_TYPE_PSP
  868. };
  869. int main(int argc, char **argv)
  870. {
  871. char outfile[5000];
  872. GF_Err e;
  873. GF_SMEncodeOptions opts;
  874. Double InterleavingTime, split_duration, split_start, import_fps;
  875. SDPLine sdp_lines[MAX_CUMUL_OPS];
  876. MetaAction metas[MAX_CUMUL_OPS];
  877. char *szFilesToCat[MAX_CUMUL_OPS];
  878. char *szTracksToAdd[MAX_CUMUL_OPS];
  879. TrackAction tracks[MAX_CUMUL_OPS];
  880. u32 brand_add[MAX_CUMUL_OPS], brand_rem[MAX_CUMUL_OPS];
  881. 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;
  882. Bool HintIt, needSave, FullInter, Frag, HintInter, dump_std, dump_rtp, dump_mode, regular_iod, trackID, HintCopy, remove_sys_tracks, remove_hint, force_new, keep_sys_tracks, remove_root_od, import_subtitle;
  883. 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, x3d_info, chunk_mode, dump_ts, do_saf, dump_m2ts, dump_cart, do_hash, verbose;
  884. char *inName, *outName, *arg, *mediaSource, *tmpdir, *input_ctx, *output_ctx, *drm_file, *avi2raw, *cprt, *chap_file, *pes_dump, *itunes_tags, *pack_file, *raw_cat;
  885. GF_ISOFile *file;
  886. if (argc < 2) {
  887. PrintUsage();
  888. return 1;
  889. }
  890. 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;
  891. e = GF_OK;
  892. split_duration = 0.0;
  893. split_start = -1.0;
  894. InterleavingTime = 0.5;
  895. import_fps = 0;
  896. import_flags = 0;
  897. split_size = 0;
  898. MTUSize = 1450;
  899. HintCopy = FullInter = HintInter = encode = do_log = old_interleave = do_saf = do_hash = verbose = 0;
  900. chunk_mode = dump_mode = Frag = force_ocr = remove_sys_tracks = agg_samples = remove_hint = keep_sys_tracks = remove_root_od = 0;
  901. x3d_info = conv_type = HintIt = needSave = print_sdp = print_info = regular_iod = dump_std = open_edit = dump_isom = dump_rtp = dump_cr = dump_srt = dump_ttxt = force_new = dump_ts = dump_m2ts = dump_cart = import_subtitle = 0;
  902. track_dump_type = 0;
  903. ismaCrypt = 0;
  904. file = NULL;
  905. itunes_tags = pes_dump = NULL;
  906. memset(&opts, 0, sizeof(opts));
  907. trackID = stat_level = hint_flags = 0;
  908. info_track_id = 0;
  909. do_flat = 0;
  910. inName = outName = mediaSource = input_ctx = output_ctx = drm_file = avi2raw = cprt = chap_file = pack_file = raw_cat = NULL;
  911. swf_flags = 0;
  912. swf_flatten_angle = 0.0f;
  913. tmpdir = NULL;
  914. /*parse our args*/
  915. for (i = 1; i < (u32) argc ; i++) {
  916. arg = argv[i];
  917. /*main file*/
  918. if (isalnum(arg[0]) || (arg[0]=='/') || (arg[0]=='.') || (arg[0]=='\\') ) {
  919. if (inName) { fprintf(stdout, "Error - 2 input names specified, please check usage\n"); return 1; }
  920. inName = arg;
  921. }
  922. else if (!stricmp(arg, "-?")) { PrintUsage(); return 0; }
  923. else if (!stricmp(arg, "-version")) { PrintVersion(); return 0; }
  924. else if (!stricmp(arg, "-sdp")) print_sdp = 1;
  925. else if (!stricmp(arg, "-quiet")) quiet = 1;
  926. else if (!stricmp(arg, "-info")) {
  927. print_info = 1;
  928. if ((i+1<(u32) argc) && (sscanf(argv[i+1], "%d", &info_track_id)==1)) {
  929. char szTk[20];
  930. sprintf(szTk, "%d", info_track_id);
  931. if (!strcmp(szTk, argv[i+1])) i++;
  932. else info_track_id=0;
  933. } else {
  934. info_track_id=0;
  935. }
  936. }
  937. else if (!stricmp(arg, "-raw")) {
  938. CHECK_NEXT_ARG
  939. track_dump_type = GF_EXPORT_NATIVE;
  940. trackID = atoi(argv[i+1]);
  941. i++;
  942. }
  943. else if (!stricmp(arg, "-qcp")) {
  944. CHECK_NEXT_ARG
  945. track_dump_type = GF_EXPORT_NATIVE | GF_EXPORT_USE_QCP;
  946. trackID = atoi(argv[i+1]);
  947. i++;
  948. }
  949. else if (!stricmp(arg, "-aviraw")) {
  950. CHECK_NEXT_ARG
  951. if (argv[i+1] && !stricmp(argv[i+1], "video")) trackID = 1;
  952. else if (argv[i+1] && !stricmp(argv[i+1], "audio")) {
  953. if (strlen(argv[i+1])==5) trackID = 2;
  954. else trackID = 1 + atoi(argv[i+1] + 5);
  955. }
  956. else { fprintf(stdout, "Usage: \"-aviraw video\" or \"-aviraw audio\"\n"); return 1; }
  957. track_dump_type = GF_EXPORT_AVI_NATIVE;
  958. i++;
  959. }
  960. else if (!stricmp(arg, "-raws")) {
  961. CHECK_NEXT_ARG
  962. track_dump_type = GF_EXPORT_RAW_SAMPLES;
  963. if (strchr(argv[i+1], ':')) {
  964. sscanf(argv[i+1], "%d:%d", &trackID, &raw_sample_num);
  965. } else {
  966. trackID = atoi(argv[i+1]);
  967. }
  968. i++;
  969. }
  970. else if (!stricmp(arg, "-nhnt")) {
  971. CHECK_NEXT_ARG
  972. track_dump_type = GF_EXPORT_NHNT;
  973. trackID = atoi(argv[i+1]);
  974. i++;
  975. }
  976. else if (!stricmp(arg, "-nhml")) {
  977. CHECK_NEXT_ARG
  978. track_dump_type = GF_EXPORT_NHML;
  979. if (argv[i+1][0]=='+') {
  980. track_dump_type |= GF_EXPORT_NHML_FULL;
  981. trackID = atoi(argv[i+1] + 1);
  982. } else {
  983. trackID = atoi(argv[i+1]);
  984. }
  985. i++;
  986. }
  987. else if (!stricmp(arg, "-avi")) {
  988. CHECK_NEXT_ARG
  989. track_dump_type = GF_EXPORT_AVI;
  990. trackID = atoi(argv[i+1]);
  991. i++;
  992. }
  993. else if (!stricmp(arg, "-node")) { CHECK_NEXT_ARG PrintNode(argv[i+1], 0); return (0); }
  994. else if (!stricmp(arg, "-xnode")) { CHECK_NEXT_ARG PrintNode(argv[i+1], 1); return (0); }
  995. else if (!stricmp(arg, "-snode")) { CHECK_NEXT_ARG PrintNode(argv[i+1], 2); return (0); }
  996. else if (!stricmp(arg, "-nodes")) { PrintBuiltInNodes(0); return (0); }
  997. else if (!stricmp(arg, "-xnodes")) { PrintBuiltInNodes(1); return (0); }
  998. else if (!stricmp(arg, "-snodes")) { PrintBuiltInNodes(2); return (0); }
  999. else if (!stricmp(arg, "-std")) dump_std = 1;
  1000. else if (!stricmp(arg, "-bt")) dump_mode = 1 + GF_SM_DUMP_BT;
  1001. else if (!stricmp(arg, "-xmt")) dump_mode = 1 + GF_SM_DUMP_XMTA;
  1002. else if (!stricmp(arg, "-wrl")) dump_mode = 1 + GF_SM_DUMP_VRML;
  1003. else if (!stricmp(arg, "-x3dv")) dump_mode = 1 + GF_SM_DUMP_X3D_VRML;
  1004. else if (!stricmp(arg, "-x3d")) dump_mode = 1 + GF_SM_DUMP_X3D_XML;
  1005. else if (!stricmp(arg, "-lsr")) dump_mode = 1 + GF_SM_DUMP_LASER;
  1006. else if (!stricmp(arg, "-svg")) dump_mode = 1 + GF_SM_DUMP_SVG;
  1007. else if (!stricmp(arg, "-stat")) stat_level = 1;
  1008. else if (!stricmp(arg, "-stats")) stat_level = 2;
  1009. else if (!stricmp(arg, "-statx")) stat_level = 3;
  1010. else if (!stricmp(arg, "-diso")) dump_isom = 1;
  1011. else if (!stricmp(arg, "-dump-cover")) dump_cart = 1;
  1012. else if (!stricmp(arg, "-hash")) do_hash = 1;
  1013. else if (!stricmp(arg, "-dmp4")) {
  1014. dump_isom = 1;
  1015. fprintf(stdout, "WARNING: \"-dmp4\" is deprecated - use \"-diso\" option\n");
  1016. }
  1017. else if (!stricmp(arg, "-drtp")) dump_rtp = 1;
  1018. else if (!stricmp(arg, "-dts")) dump_ts = 1;
  1019. else if (!stricmp(arg, "-dcr")) dump_cr = 1;
  1020. else if (!stricmp(arg, "-ttxt") || !stricmp(arg, "-srt")) {
  1021. if ((i+1<(u32) argc) && (sscanf(argv[i+1], "%d", &trackID)==1)) {
  1022. char szTk[20];
  1023. sprintf(szTk, "%d", trackID);
  1024. if (!strcmp(szTk, argv[i+1])) i++;
  1025. else trackID=0;
  1026. } else {
  1027. trackID = 0;
  1028. }
  1029. #ifdef GPAC_READ_ONLY
  1030. if (trackID) { fprintf(stdout, "Error: Read-Only version - subtitle conversion not available\n"); return 1; }
  1031. #endif
  1032. if (!stricmp(arg, "-ttxt")) dump_ttxt = 1;
  1033. else dump_srt = 1;
  1034. import_subtitle = 1;
  1035. } else if (!stricmp(arg, "-dm2ts")) {
  1036. dump_m2ts = 1;
  1037. if ( ((i+1<(u32) argc) && inName) || (i+2<(u32) argc) ) {
  1038. if (argv[i+1][0] != '-') pes_dump = argv[i+1];
  1039. i++;
  1040. }
  1041. }
  1042. #ifndef GPAC_READ_ONLY
  1043. /*SWF importer options*/
  1044. else if (!stricmp(arg, "-global")) swf_flags |= GF_SM_SWF_STATIC_DICT;
  1045. else if (!stricmp(arg, "-ctrl")) swf_flags |= GF_SM_SWF_SPLIT_TIMELINE;
  1046. else if (!stricmp(arg, "-no-text")) swf_flags |= GF_SM_SWF_NO_TEXT;
  1047. else if (!stricmp(arg, "-no-font")) swf_flags |= GF_SM_SWF_NO_FONT;
  1048. else if (!stricmp(arg, "-no-line")) swf_flags |= GF_SM_SWF_NO_LINE;
  1049. else if (!stricmp(arg, "-no-grad")) swf_flags |= GF_SM_SWF_NO_GRADIENT;
  1050. else if (!stricmp(arg, "-quad")) swf_flags |= GF_SM_SWF_QUAD_CURVE;
  1051. else if (!stricmp(arg, "-xlp")) swf_flags |= GF_SM_SWF_SCALABLE_LINE;
  1052. else if (!stricmp(arg, "-flatten")) {
  1053. CHECK_NEXT_ARG
  1054. swf_flatten_angle = (Float) atof(argv[i+1]);
  1055. i++;
  1056. }
  1057. else if (!stricmp(arg, "-isma")) { conv_type = GF_ISOM_CONV_TYPE_ISMA; open_edit = 1; }
  1058. else if (!stricmp(arg, "-3gp")) { conv_type = GF_ISOM_CONV_TYPE_3GPP; open_edit = 1; }
  1059. else if (!stricmp(arg, "-ipod")) { conv_type = GF_ISOM_CONV_TYPE_IPOD; open_edit = 1; }
  1060. else if (!stricmp(arg, "-ismax")) { conv_type = GF_ISOM_CONV_TYPE_ISMA_EX; open_edit = 1; }
  1061. else if (!stricmp(arg, "-no-sys") || !stricmp(arg, "-nosys")) { remove_sys_tracks = 1; open_edit = 1; }
  1062. else if (!stricmp(arg, "-no-iod")) { remove_root_od = 1; open_edit = 1; }
  1063. else if (!stricmp(arg, "-out")) { CHECK_NEXT_ARG outName = argv[i+1]; i++; }
  1064. else if (!stricmp(arg, "-tmp")) { CHECK_NEXT_ARG tmpdir = argv[i+1]; i++; }
  1065. else if (!stricmp(arg, "-cprt")) { CHECK_NEXT_ARG cprt = argv[i+1]; i++; open_edit = 1; }
  1066. else if (!stricmp(arg, "-chap")) { CHECK_NEXT_ARG chap_file = argv[i+1]; i++; open_edit = 1; }
  1067. else if (!stricmp(arg, "-inter") || !stricmp(arg, "-old-inter")) {
  1068. CHECK_NEXT_ARG
  1069. InterleavingTime = atof(argv[i+1]) / 1000;
  1070. open_edit = 1;
  1071. needSave = 1;
  1072. if (!stricmp(arg, "-old-inter")) old_interleave = 1;
  1073. i++;
  1074. } else if (!stricmp(arg, "-frag")) {
  1075. CHECK_NEXT_ARG
  1076. InterleavingTime = atof(argv[i+1]) / 1000;
  1077. open_edit = 1;
  1078. needSave = 1;
  1079. i++;
  1080. Frag = 1;
  1081. }
  1082. else if (!stricmp(arg, "-itags")) { CHECK_NEXT_ARG itunes_tags = argv[i+1]; i++; open_edit = 1; }
  1083. else if (!stricmp(arg, "-hint")) { open_edit = 1; HintIt = 1; }
  1084. else if (!stricmp(arg, "-unhint")) { open_edit = 1; remove_hint = 1; }
  1085. else if (!stricmp(arg, "-copy")) HintCopy = 1;
  1086. else if (!stricmp(arg, "-tight")) {
  1087. FullInter = 1;
  1088. open_edit = 1;
  1089. needSave = 1;
  1090. } else if (!stricmp(arg, "-ocr")) force_ocr = 1;
  1091. else if (!stricmp(arg, "-latm")) hint_flags |= GP_RTP_PCK_USE_LATM_AAC;
  1092. else if (!stricmp(arg, "-rap")) hint_flags |= GP_RTP_PCK_SIGNAL_RAP;
  1093. else if (!stricmp(arg, "-ts")) hint_flags |= GP_RTP_PCK_SIGNAL_TS;
  1094. else if (!stricmp(arg, "-size")) hint_flags |= GP_RTP_PCK_SIGNAL_SIZE;
  1095. else if (!stricmp(arg, "-idx")) hint_flags |= GP_RTP_PCK_SIGNAL_AU_IDX;
  1096. else if (!stricmp(arg, "-static")) hint_flags |= GP_RTP_PCK_USE_STATIC_ID;
  1097. else if (!stricmp(arg, "-multi")) {
  1098. hint_flags |= GP_RTP_PCK_USE_MULTI;
  1099. if ((i+1<(u32) argc) && (sscanf(argv[i+1], "%d", &max_ptime)==1)) {
  1100. char szPt[20];
  1101. sprintf(szPt, "%d", max_ptime);
  1102. if (!strcmp(szPt, argv[i+1])) i++;
  1103. else max_ptime=0;
  1104. }
  1105. }
  1106. else if (!stricmp(arg, "-mpeg4")) {
  1107. hint_flags |= GP_RTP_PCK_FORCE_MPEG4;
  1108. import_flags |= GF_IMPORT_FORCE_MPEG4;
  1109. }
  1110. else if (!stricmp(arg, "-mtu")) { CHECK_NEXT_ARG MTUSize = atoi(argv[i+1]); i++; }
  1111. else if (!stricmp(arg, "-cardur")) { CHECK_NEXT_ARG car_dur = atoi(argv[i+1]); i++; }
  1112. else if (!stricmp(arg, "-rate")) { CHECK_NEXT_ARG rtp_rate = atoi(argv[i+1]); i++; }
  1113. else if (!stricmp(arg, "-add-sdp") || !stricmp(arg, "-sdp_ex")) {
  1114. char *id;
  1115. CHECK_NEXT_ARG
  1116. if (nb_sdp_ex>=MAX_CUMUL_OPS) {
  1117. fprintf(stdout, "Sorry - no more than %d extra SDP lines allowed\n", MAX_CUMUL_OPS);
  1118. return 1;
  1119. }
  1120. id = strchr(argv[i+1], ':');
  1121. if (id) {
  1122. id[0] = 0;
  1123. if (sscanf(argv[i+1], "%d", &sdp_lines[0].trackID)==1) {
  1124. id[0] = ':';
  1125. sdp_lines[nb_sdp_ex].line = id+1;
  1126. } else {
  1127. id[0] = ':';
  1128. sdp_lines[nb_sdp_ex].line = argv[i+1];
  1129. sdp_lines[nb_sdp_ex].trackID = 0;
  1130. }
  1131. } else {
  1132. sdp_lines[nb_sdp_ex].line = argv[i+1];
  1133. sdp_lines[nb_sdp_ex].trackID = 0;
  1134. }
  1135. nb_sdp_ex++;
  1136. i++;
  1137. }
  1138. else if (!stricmp(arg, "-single")) {
  1139. CHECK_NEXT_ARG
  1140. track_dump_type = GF_EXPORT_MP4;
  1141. trackID = atoi(argv[i+1]);
  1142. i++;
  1143. }
  1144. else if (!stricmp(arg, "-iod")) regular_iod = 1;
  1145. else if (!stricmp(arg, "-flat")) do_flat = 1;
  1146. else if (!stricmp(arg, "-new")) force_new = 1;
  1147. else if (!stricmp(arg, "-add") || !stricmp(arg, "-import") || !stricmp(arg, "-convert")) {
  1148. CHECK_NEXT_ARG
  1149. if (!stricmp(arg, "-import")) fprintf(stdout, "\tWARNING: \"-import\" is deprecated - use \"-add\"\n");
  1150. else if (!stricmp(arg, "-convert")) fprintf(stdout, "\tWARNING: \"-convert\" is deprecated - use \"-add\"\n");
  1151. if (nb_add>=MAX_CUMUL_OPS) {
  1152. fprintf(stdout, "Sorry - no more than %d add operations allowed\n", MAX_CUMUL_OPS);
  1153. return 1;
  1154. }
  1155. szTracksToAdd[nb_add] = argv[i+1];
  1156. nb_add++;
  1157. i++;
  1158. }
  1159. else if (!stricmp(arg, "-cat")) {
  1160. CHECK_NEXT_ARG
  1161. if (nb_cat>=MAX_CUMUL_OPS) {
  1162. fprintf(stdout, "Sorry - no more than %d cat operations allowed\n", MAX_CUMUL_OPS);
  1163. return 1;
  1164. }
  1165. szFilesToCat[nb_cat] = argv[i+1];
  1166. nb_cat++;
  1167. i++;
  1168. }
  1169. else if (!stricmp(arg, "-raw-cat")) {
  1170. CHECK_NEXT_ARG
  1171. raw_cat = argv[i+1];
  1172. i++;
  1173. }
  1174. else if (!stricmp(arg, "-rem")) {
  1175. CHECK_NEXT_ARG
  1176. if (nb_track_act>=MAX_CUMUL_OPS) {
  1177. fprintf(stdout, "Sorry - no more than %d track operations allowed\n", MAX_CUMUL_OPS);
  1178. return 1;
  1179. }
  1180. tracks[nb_track_act].act_type = 0;
  1181. tracks[nb_track_act].trackID = atoi(argv[i+1]);
  1182. open_edit = 1;
  1183. nb_track_act++;
  1184. i++;
  1185. }
  1186. else if (!stricmp(arg, "-par")) {
  1187. char szTK[20], *ext;
  1188. CHECK_NEXT_ARG
  1189. if (nb_track_act>=MAX_CUMUL_OPS) {
  1190. fprintf(stdout, "Sorry - no more than %d track operations all…

Large files files are truncated, but you can click here to view the full file