PageRenderTime 42ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/applications/mp4box/main.c

https://github.com/svettom/gpac
C | 4002 lines | 3614 code | 270 blank | 118 comment | 1275 complexity | a8e9766990d99a848ee548f6ce3807f1 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. /*
  2. * GPAC - Multimedia Framework C SDK
  3. *
  4. * Authors: Jean Le Feuvre
  5. * Copyright (c) Telecom ParisTech 2000-2012
  6. * All rights reserved
  7. *
  8. * This file is part of GPAC / mp4box application
  9. *
  10. * GPAC is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * GPAC is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; see the file COPYING. If not, write to
  22. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "../../include/gpac/download.h"
  26. #include "../../include/gpac/network.h"
  27. #ifndef GPAC_DISABLE_SMGR
  28. #include "../../include/gpac/scene_manager.h"
  29. #endif
  30. #ifdef GPAC_DISABLE_ISOM
  31. #error "Cannot compile MP4Box if GPAC is not built with ISO File Format support"
  32. #else
  33. #if defined(WIN32) && !defined(_WIN32_WCE)
  34. #include <io.h>
  35. #include <fcntl.h>
  36. #endif
  37. #include "../../include/gpac/media_tools.h"
  38. /*RTP packetizer flags*/
  39. #ifndef GPAC_DISABLE_STREAMING
  40. #include "../../include/gpac/ietf.h"
  41. #endif
  42. #ifndef GPAC_DISABLE_MCRYPT
  43. #include "../../include/gpac/ismacryp.h"
  44. #endif
  45. #include "../../include/gpac/constants.h"
  46. #include "../../include/gpac/internal/mpd.h"
  47. #include <time.h>
  48. #if defined(__MINGW32__) || defined(_MSC_VER)
  49. #include <mbstring.h>
  50. #endif
  51. #define BUFFSIZE 8192
  52. /*in fileimport.c*/
  53. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  54. void convert_file_info(char *inName, u32 trackID);
  55. #endif
  56. #ifndef GPAC_DISABLE_ISOM_WRITE
  57. GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double force_fps, u32 frames_per_sample);
  58. GF_Err split_isomedia_file(GF_ISOFile *mp4, Double split_dur, u32 split_size_kb, char *inName, Double interleaving_time, Double chunk_start, Bool adjust_split_end, char *outName, const char *tmpdir);
  59. 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, Bool align_timelines, Bool allow_add_in_command);
  60. #if !defined(GPAC_DISABLE_SCENE_ENCODER)
  61. GF_Err EncodeFile(char *in, GF_ISOFile *mp4, GF_SMEncodeOptions *opts, FILE *logs);
  62. GF_Err EncodeFileChunk(char *chunkFile, char *bifs, char *inputContext, char *outputContext, const char *tmpdir);
  63. #endif
  64. GF_ISOFile *package_file(char *file_name, char *fcc, const char *tmpdir, Bool make_wgt);
  65. #endif
  66. GF_Err dump_cover_art(GF_ISOFile *file, char *inName);
  67. GF_Err dump_chapters(GF_ISOFile *file, char *inName, Bool dump_ogg);
  68. u32 id3_get_genre_tag(const char *name);
  69. /*in filedump.c*/
  70. #ifndef GPAC_DISABLE_SCENE_DUMP
  71. GF_Err dump_file_text(char *file, char *inName, u32 dump_mode, Bool do_log);
  72. #endif
  73. #ifndef GPAC_DISABLE_SCENE_STATS
  74. void dump_scene_stats(char *file, char *inName, u32 stat_level);
  75. #endif
  76. void PrintNode(const char *name, u32 graph_type);
  77. void PrintBuiltInNodes(u32 graph_type);
  78. #ifndef GPAC_DISABLE_ISOM_DUMP
  79. void dump_isom_xml(GF_ISOFile *file, char *inName);
  80. #endif
  81. #ifndef GPAC_DISABLE_ISOM_HINTING
  82. #ifndef GPAC_DISABLE_ISOM_DUMP
  83. void dump_file_rtp(GF_ISOFile *file, char *inName);
  84. #endif
  85. void DumpSDP(GF_ISOFile *file, char *inName);
  86. #endif
  87. void dump_file_timestamps(GF_ISOFile *file, char *inName);
  88. void dump_file_nal(GF_ISOFile *file, u32 trackID, char *inName);
  89. #ifndef GPAC_DISABLE_ISOM_DUMP
  90. void dump_file_ismacryp(GF_ISOFile *file, char *inName);
  91. void dump_timed_text_track(GF_ISOFile *file, u32 trackID, char *inName, Bool is_convert, u32 dump_type);
  92. #endif /*GPAC_DISABLE_ISOM_DUMP*/
  93. void DumpTrackInfo(GF_ISOFile *file, u32 trackID, Bool full_dump);
  94. void DumpMovieInfo(GF_ISOFile *file);
  95. void PrintLanguages();
  96. const char *GetLanguageCode(char *lang);
  97. #ifndef GPAC_DISABLE_MPEG2TS
  98. void dump_mpeg2_ts(char *mpeg2ts_file, char *pes_out_name, Bool prog_num);
  99. #endif
  100. #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
  101. void PrintStreamerUsage();
  102. int stream_file_rtp(int argc, char **argv);
  103. int live_session(int argc, char **argv);
  104. void PrintLiveUsage();
  105. #endif
  106. #if !defined(GPAC_DISABLE_STREAMING)
  107. u32 grab_live_m2ts(const char *grab_m2ts, const char *outName);
  108. #endif
  109. int mp4boxTerminal(int argc, char **argv);
  110. u32 quiet = 0;
  111. Bool dvbhdemux =0;
  112. Bool keep_sys_tracks = 0;
  113. /*some global vars for swf import :(*/
  114. u32 swf_flags = 0;
  115. Float swf_flatten_angle = 0;
  116. s32 laser_resolution = 0;
  117. typedef struct { u32 code; const char *name; const char *comment; } itunes_tag;
  118. static const itunes_tag itags[] = {
  119. {GF_ISOM_ITUNE_ALBUM_ARTIST, "album_artist", "usage: album_artist=album artist"},
  120. {GF_ISOM_ITUNE_ALBUM, "album", "usage: album=name" },
  121. {GF_ISOM_ITUNE_TRACKNUMBER, "tracknum", "usage: track=x/N"},
  122. {GF_ISOM_ITUNE_TRACK, "track", "usage: track=name"},
  123. {GF_ISOM_ITUNE_ARTIST, "artist", "usage: artist=name"},
  124. {GF_ISOM_ITUNE_COMMENT, "comment", "usage: comment=any comment"},
  125. {GF_ISOM_ITUNE_COMPILATION, "compilation", "usage: compilation=yes,no"},
  126. {GF_ISOM_ITUNE_COMPOSER, "composer", "usage: composer=name"},
  127. {GF_ISOM_ITUNE_CREATED, "created", "usage: created=time"},
  128. {GF_ISOM_ITUNE_DISK, "disk", "usage: disk=x/N"},
  129. {GF_ISOM_ITUNE_TOOL, "tool", "usage: tool=name"},
  130. {GF_ISOM_ITUNE_GENRE, "genre", "usage: genre=name"},
  131. {GF_ISOM_ITUNE_NAME, "name", "usage: name=name"},
  132. {GF_ISOM_ITUNE_TEMPO, "tempo", "usage: tempo=integer"},
  133. {GF_ISOM_ITUNE_WRITER, "writer", "usage: writer=name"},
  134. {GF_ISOM_ITUNE_GROUP, "group", "usage: group=name"},
  135. {GF_ISOM_ITUNE_COVER_ART, "cover", "usage: cover=file.jpg,file.png"},
  136. {GF_ISOM_ITUNE_ENCODER, "encoder", "usage: encoder=name"},
  137. {GF_ISOM_ITUNE_GAPLESS, "gapless", "usage: gapless=yes,no"},
  138. };
  139. u32 nb_itunes_tags = sizeof(itags) / sizeof(itunes_tag);
  140. void PrintVersion()
  141. {
  142. fprintf(stderr, "MP4Box - GPAC version " GPAC_FULL_VERSION "\n"
  143. #ifdef GPAC_CONFIG_EXTRA_INFORMATION
  144. GPAC_CONFIG_EXTRA_INFORMATION "\n"
  145. #endif
  146. "GPAC Copyright (c) Telecom ParisTech 2000-2012\n"
  147. "GPAC Configuration: " GPAC_CONFIGURATION "\n"
  148. "Features: %s\n", gpac_features());
  149. }
  150. void PrintGeneralUsage()
  151. {
  152. fprintf(stderr, "General Options:\n"
  153. #ifdef GPAC_MEMORY_TRACKING
  154. " -mem-track: enables memory tracker\n"
  155. #endif
  156. " -strict-error exits after the first error is reported\n"
  157. " -inter time_in_ms interleaves file data (track chunks of time_in_ms)\n"
  158. " * Note 1: Interleaving is 0.5s by default\n"
  159. " * Note 2: Performs drift checking accross tracks\n"
  160. " * Note 3: a value of 0 disables interleaving\n"
  161. " -old-inter time same as -inter but doesn't perform drift checking\n"
  162. " -tight performs tight interleaving (sample based) of the file\n"
  163. " * Note: reduces disk seek but increases file size\n"
  164. " -flat stores file with all media data first, non-interleaved\n"
  165. " -frag time_in_ms fragments file (track fragments of time_in_ms)\n"
  166. " * Note: Always disables interleaving\n"
  167. " -ffspace size inserts free space before moof in fragmented files\n"
  168. " -out filename specifies output file name\n"
  169. " * Note: By default input (MP4,3GP) file is overwritten\n"
  170. " -tmp dirname specifies directory for temporary file creation\n"
  171. " * Note: Default temp dir is OS-dependent\n"
  172. " -write-buffer SIZE specifies write buffer in bytes for ISOBMF files\n"
  173. " -no-sys removes all MPEG-4 Systems info except IOD (profiles)\n"
  174. " * Note: Set by default whith '-add' and '-cat'\n"
  175. " -no-iod removes InitialObjectDescriptor from file\n"
  176. " -isma rewrites the file as an ISMA 1.0 AV file\n"
  177. " -ismax same as \'-isma\' and removes all clock references\n"
  178. " -3gp rewrites as 3GPP(2) file (no more MPEG-4 Systems Info)\n"
  179. " * Note 1: some tracks may be removed in the process\n"
  180. " * Note 2: always on for *.3gp *.3g2 *.3gpp\n"
  181. " -ipod rewrites the file for iPod\n"
  182. " -psp rewrites the file for PSP devices\n"
  183. " -brand ABCD[:v] sets major brand of file, with optional version\n"
  184. " -ab ABCD adds given brand to file's alternate brand list\n"
  185. " -rb ABCD removes given brand from file's alternate brand list\n"
  186. " -cprt string adds copyright string to movie\n"
  187. " -chap file adds chapter information contained in file\n"
  188. " -rem trackID removes track from file\n"
  189. " -enable trackID enables track\n"
  190. " -disable trackID disables track\n"
  191. " -new forces creation of a new destination file\n"
  192. " -lang [tkID=]LAN sets track language. LAN is the ISO 639-2 code (eng, und)\n"
  193. " -delay tkID=TIME sets track start delay in ms.\n"
  194. " -par tkID=PAR sets visual track pixel aspect ratio (PAR=N:D or \"none\")\n"
  195. " -name tkID=NAME sets track handler name\n"
  196. " * NAME can indicate a UTF-8 file (\"file://file name\"\n"
  197. " -itags tag1[:tag2] sets iTunes tags to file - more info: MP4Box -tag-list.\n"
  198. " -split time_sec splits in files of time_sec max duration\n"
  199. " * Note: this removes all MPEG-4 Systems media\n"
  200. " -split-size size splits in files of max filesize kB. same as -splits.\n"
  201. " * Note: this removes all MPEG-4 Systems media\n"
  202. " -split-rap splits in files begining at each RAP. same as -splitr.\n"
  203. " * Note: this removes all MPEG-4 Systems media\n"
  204. " -split-chunk S:E extracts a new file from Start to End (in seconds). same as -splitx\n"
  205. " * Note: this removes all MPEG-4 Systems media\n"
  206. " -splitz S:E same as -split-chunk, but adjust the end time to be before the last RAP sample\n"
  207. " * Note: this removes all MPEG-4 Systems media\n"
  208. " -group-add fmt creates a new grouping information in the file. Format is\n"
  209. " a colon-separated list of following options:\n"
  210. " refTrack=ID: ID of the track used as a group reference.\n"
  211. " If not set, the track will belong to the same group as the previous trackID specified.\n"
  212. " If 0 or no previous track specified, a new alternate group will be created\n"
  213. " switchID=ID: ID of the switch group to create.\n"
  214. " If 0, a new ID will be computed for you\n"
  215. " If <0, disables SwitchGroup\n"
  216. " criteria=string: list of space-separated 4CCs.\n"
  217. " trackID=ID: ID of the track to add to this group.\n"
  218. "\n"
  219. " *WARNING* Options modify state as they are parsed:\n"
  220. " trackID=1:criteria=lang:trackID=2\n"
  221. " is different from:\n"
  222. " criteria=lang:trackID=1:trackID=2\n"
  223. "\n"
  224. " -group-rem-track ID removes track from its group\n"
  225. " -group-rem ID removes the track's group\n"
  226. " -group-clean removes all group information from all tracks\n"
  227. " -group-single puts all tracks in a single group\n"
  228. " -ref id:XXXX:refID adds a reference of type 4CC from track ID to track refID\n"
  229. " -keep-utc keeps UTC timing in the file after edit\n"
  230. "\n");
  231. }
  232. void PrintDASHUsage()
  233. {
  234. fprintf(stderr, "DASH Options:\n"
  235. " -dash dur enables DASH-ing of the file(s) with a segment duration of DUR ms\n"
  236. " Note: the duration of a fragment (subsegment) is set\n"
  237. " using the -frag switch.\n"
  238. " Note: for onDemand profile, sets duration of a subsegment\n"
  239. " -frag time_in_ms Specifies a fragment duration of time_in_ms.\n"
  240. " * Note: By default, this is the DASH duration\n"
  241. " -out filename specifies output MPD file name.\n"
  242. " -tmp dirname specifies directory for temporary file creation\n"
  243. " * Note: Default temp dir is OS-dependent\n"
  244. " -profile NAME specifies the target DASH profile: \"onDemand\", \"live\", \"main\", \"simple\", \"full\"\n"
  245. " * This will set default option values to ensure conformance to the desired profile\n"
  246. " * Default profile is \"full\" in static mode, \"live\" in dynamic mode\n"
  247. "\n"
  248. "Input media files to dash can use the following modifiers\n"
  249. " \"#trackID=N\" only uses the track ID N from the source file\n"
  250. " \"#video\" only uses the first video track from the source file\n"
  251. " \"#audio\" only uses the first video track from the source file\n"
  252. " \":id=NAME\" sets the representation ID to NAME\n"
  253. " \":period=NAME\" sets the representation's period to NAME. Multiple periods may be used\n"
  254. " period appear in the MPD in the same order as specified with this option\n"
  255. " \":bandwidth=VALUE\" sets the representation's bandwidth to a given value\n"
  256. " \":role=VALUE\" sets the role of this representation (cf DASH spec).\n"
  257. " media with different roles belong to different adaptation sets.\n"
  258. "\n"
  259. " -rap segments begin with random access points\n"
  260. " Note: segment duration may not be exactly what asked by\n"
  261. " \"-dash\" since encoded video data is not modified\n"
  262. " -frag-rap All fragments begin with random access points\n"
  263. " Note: fragment duration may not be exactly what is asked by\n"
  264. " \"-frag\" since encoded video data is not modified\n"
  265. " -segment-name name sets the segment name for generated segments\n"
  266. " If not set (default), segments are concatenated in output file\n"
  267. " except in \"live\" profile where dash_%%s is used\n"
  268. " -segment-ext name sets the segment extension. Default is m4s, \"null\" means no extension\n"
  269. " -segment-timeline Uses SegmentTimeline when generating segments. NOT SUPPORTED BY LIVE/CTX MODE YET.\n"
  270. " -segment-marker MARK Adds a box of type \'MARK\' at the end of each DASH segment. MARK shall be a 4CC identifier\n"
  271. " -base-url string sets Base url at MPD level. Can be used several times.\n"
  272. " -mpd-title string sets MPD title.\n"
  273. " -mpd-source string sets MPD source.\n"
  274. " -mpd-info-url string sets MPD info url.\n"
  275. " -cprt string adds copyright string to MPD\n"
  276. " -dash-live[=F] dur generates a live DASH session using dur segment duration, optionnally writing live context to F\n"
  277. " MP4Box will run the live session until \'q\' is pressed or a fatal error occurs.\n"
  278. " -ddbg-live[=F] dur same as -dash-live without time regulation for debug purposes.\n"
  279. " -dash-ctx FILE stores/restore DASH timing from FILE.\n"
  280. " -dynamic uses dynamic MPD type instead of static.\n"
  281. " -mpd-refresh TIME specifies MPD update time in seconds.\n"
  282. " -time-shift TIME specifies MPD time shift buffer depth in seconds (default 0). Specify -1 to keep all files\n"
  283. " -subdur DUR specifies maximum duration in ms of the input file to be dashed in LIVE or context mode.\n"
  284. " NOTE: This does not change the segment duration: dashing stops once segments produced exceeded the duration.\n"
  285. " -min-buffer TIME specifies MPD min buffer time in milliseconds\n"
  286. " -ast-offset TIME specifies MPD AvailabilityStartTime offset in seconds. Default is 1 sec delay\n"
  287. " -dash-scale SCALE specifies that timing for -dash and -frag are expressed in SCALE units per seconds\n"
  288. " -mem-frags fragments will be produced in memory rather than on disk before flushing to disk\n"
  289. " -pssh-moof stores PSSH boxes in first moof of each segments. By default PSSH are stored in movie box.\n"
  290. "\n"
  291. "Advanced Options, should not be needed when using -dash-profile:\n"
  292. " -subsegs-per-sidx N sets the number of subsegments to be written in each SIDX box\n"
  293. " If 0, a single SIDX box is used per segment\n"
  294. " If -1, no SIDX box is used\n"
  295. " -url-template uses SegmentTemplate instead of explicit sources in segments.\n"
  296. " Ignored if segments are stored in the output file.\n"
  297. " -daisy-chain uses daisy-chain SIDX instead of hierarchical. Ignored if frags/sidx is 0.\n"
  298. " -single-segment uses a single segment for the whole file (OnDemand profile). \n"
  299. " -single-file uses a single file for the whole file (default). \n"
  300. " -bs-switching MODE sets bitstream switching to \"inband\" (default), \"merge\", \"no\" or \"single\" to test with single input.\n"
  301. " -moof-sn N sets sequence number of first moof to N\n"
  302. " -tfdt N sets TFDT of first traf to N in SCALE units (cf -dash-scale)\n"
  303. " -no-frag-default disables default flags in fragments\n"
  304. " -dash-ts-prog N program_number to be considered in case of an MPTS input file.\n"
  305. "\n");
  306. }
  307. void PrintFormats()
  308. {
  309. fprintf(stderr, "Suppported raw formats and file extensions:\n"
  310. " NHNT .media .nhnt .info\n"
  311. " NHML .nhml (opt: .media .info)\n"
  312. " MPEG-1-2 Video .m1v .m2v\n"
  313. " MPEG-4 Video .cmp .m4v\n"
  314. " H263 Video .263 .h263\n"
  315. " AVC/H264 Video .h264 .h26L .264 .26L\n"
  316. " JPEG Images .jpg .jpeg\n"
  317. " PNG Images .png\n"
  318. " MPEG 1-2 Audio .mp3, .m1a, .m2a\n"
  319. " ADTS-AAC Audio .aac\n"
  320. " AMR(WB) Audio .amr .awb\n"
  321. " EVRC Audio .evc\n"
  322. " SMV Audio .smv\n"
  323. "\n"
  324. "Supported containers and file extensions:\n"
  325. " AVI .avi\n"
  326. " MPEG-2 PS .mpg .mpeg .vob .vcd .svcd\n"
  327. " MPEG-2 TS .ts .m2t\n"
  328. " QCP .qcp\n"
  329. " OGG .ogg\n"
  330. " ISO-Media files no extension checking\n"
  331. "\n"
  332. "Supported text formats:\n"
  333. " SRT Subtitles .srt\n"
  334. " SUB Subtitles .sub\n"
  335. " GPAC Timed Text .ttxt\n"
  336. " QuickTime TeXML Text .xml (cf QT documentation)\n"
  337. "\n"
  338. "Supported Scene formats:\n"
  339. " MPEG-4 XMT-A .xmt .xmta .xmt.gz .xmta.gz\n"
  340. " MPEG-4 BT .bt .bt.gz\n"
  341. " VRML .wrl .wrl.gz\n"
  342. " X3D-XML .x3d .x3d.gz\n"
  343. " X3D-VRML .x3dv .x3dv.gz\n"
  344. " MacroMedia Flash .swf (very limited import support only)\n"
  345. "\n"
  346. );
  347. }
  348. void PrintImportUsage()
  349. {
  350. fprintf(stderr, "Importing Options\n"
  351. "\nFile importing syntax:\n"
  352. " \"#video\" \"#audio\" base import for most AV files\n"
  353. " \"#trackID=ID\" track import for IsoMedia and other files\n"
  354. " \"#pid=ID\" stream import from MPEG-2 TS\n"
  355. " \":dur=D\" imports only the first D seconds\n"
  356. " \":lang=LAN\" sets imported media language code\n"
  357. " \":delay=delay_ms\" sets imported media initial delay in ms\n"
  358. " \":par=PAR\" sets visual pixel aspect ratio (PAR=Num:Den)\n"
  359. " \":name=NAME\" sets track handler name\n"
  360. " \":ext=EXT\" overrides file extension when importing\n"
  361. " \":hdlr=code\" sets track handler type to the given code point (4CC)\n"
  362. " \":disable\" imported track(s) will be disabled\n"
  363. " \":group=G\" adds the track as part of the G alternate group.\n"
  364. " If G is 0, the first available GroupID will be picked.\n"
  365. " \":fps=VAL\" same as -fps option\n"
  366. " \":agg=VAL\" same as -agg option\n"
  367. " \":par=VAL\" same as -par option\n"
  368. " \":dref\" same as -dref option\n"
  369. " \":nodrop\" same as -nodrop option\n"
  370. " \":packed\" same as -packed option\n"
  371. " \":sbr\" same as -sbr option\n"
  372. " \":sbrx\" same as -sbrx option\n"
  373. " \":ps\" same as -ps option\n"
  374. " \":psx\" same as -psx option\n"
  375. " \":ovsbr\" same as -ovsbr option\n"
  376. " \":mpeg4\" same as -mpeg4 option\n"
  377. " \":svc\" import SVC with explicit signaling (no AVC base compatibility)\n"
  378. " \":nosvc\" discard SVC data when importing\n"
  379. " \":svcmode=MODE\" sets SVC import mode:\n"
  380. " \" split : each AVC/SVC layer is in its own track\n"
  381. " \" merge : all AVC/SVC layers are merged in a single track\n"
  382. " \" splitbase : all SVC layers are merged in a track, and the AVC base in another\n"
  383. " \":subsamples\" adds SubSample information for AVC+SVC\n"
  384. " \":forcesync\" forces non IDR samples with I slices to be marked as sync points (AVC GDR)\n"
  385. " !! RESULTING FILE IS NOT COMPLIANT WITH THE SPEC but will fix seeking in most players\n"
  386. " \":font=name\" specifies font name for text import (default \"Serif\")\n"
  387. " \":size=s\" specifies font size for text import (default 18)\n"
  388. " \":stype=4CC\" forces the sample description type to a different value\n"
  389. " !! THIS MAY BREAK THE FILE WRITING !!\n"
  390. " \":chap\" specifies the track is a chapter track\n"
  391. " \":chapter=NAME\" adds a single chapter (old nero format) with given name lasting the entire file\n"
  392. " This command can be used in -cat as well\n"
  393. " \":chapfile=file\" adds a chapter file (old nero format)\n"
  394. " This command can be used in -cat as well\n"
  395. " \":profile\" forces the profile for the H.264 content\n"
  396. " - high444, high, extended, main, baseline\n"
  397. " *WARNING* wrong value may cause playback issue\n"
  398. " \":compat\" forces the profile compatibity flags for the H.264 content\n"
  399. " *WARNING* wrong value may cause playback issue\n"
  400. " \":level\" forces the level for the H.264 content\n"
  401. " *Note: If value < 6, interpreted as decimal expression\n"
  402. " \":vidformat\" forces the video_format flag in VUI for the H.264 content\n"
  403. " - component, pal, ntsc, secam, mac, undef\n"
  404. " \":fullrange\" forces the video_full_range_flag in VUI for the H.264 content\n"
  405. " - on, off\n"
  406. " \":colorprim\" forces the colour_primaries flag in VUI for the H.264 content\n"
  407. " - bt709, undef, bt470m, bt470bg, smpte170m, smpte240m, film\n"
  408. " \":transfer\" forces the transfer_characteristics flag in VUI for the H.264 content\n"
  409. " - bt709, undef, bt470m, bt470bg, smpte170m, smpte240m, linear\n"
  410. " log100, log316\n"
  411. " \":colmatrix\" forces the matrix_coefficients flag in VUI for the H.264 content\n"
  412. " - GBR, bt709, undef, fcc, bt470bg, smpte170m, smpte240m, YCgCo\n"
  413. " \":layout=WxHxXxY\" specifies the track layout\n"
  414. " - if W (resp H) = 0, the max width (resp height) of\n"
  415. " the tracks in the file are used.\n"
  416. " - if Y=-1, the layout is moved to the bottom of the\n"
  417. " track area\n"
  418. " - X and Y can be omitted (:layout=WxH)\n"
  419. " \":rescale=TS\" forces media timescale to TS !! changes the media duration\n"
  420. " \":timescale=TS\" sets import timescale to TS\n"
  421. " \":swf-global\" all SWF defines are placed in first scene replace\n"
  422. " * Note: By default SWF defines are sent when needed\n"
  423. " \":swf-no-ctrl\" uses a single stream for movie control and dictionary\n"
  424. " * Note: this will disable ActionScript\n"
  425. " \":swf-no-text\" removes all SWF text\n"
  426. " \":swf-no-font\" removes all embedded SWF Fonts (terminal fonts used)\n"
  427. " \":swf-no-line\" removes all lines from SWF shapes\n"
  428. " \":swf-no-grad\" removes all gradients from swf shapes\n"
  429. " \":swf-quad\" uses quadratic bezier curves instead of cubic ones\n"
  430. " \":swf-xlp\" support for lines transparency and scalability\n"
  431. " \":swf-flatten=ang\" complementary angle below which 2 lines are merged\n"
  432. " * Note: angle \'0\' means no flattening\n"
  433. "\n"
  434. " \":negctts\" uses negative CTS-DTS offsets (ISO4 brand)\n"
  435. " -add file add file tracks to (new) output file\n"
  436. " -cat file concatenates file samples to (new) output file\n"
  437. " * Note: creates tracks if needed\n"
  438. " * Note: aligns initial timestamp of the file to be concatenated.\n"
  439. " -catx file same as cat but new tracks can be imported before concatenation by specifying '+ADD_COMMAND'\n"
  440. " where ADD_COMMAND is a regular -add syntax\n"
  441. " -unalign-cat does not attempt to align timestamps of samples inbetween tracks\n"
  442. " -force-cat skips media configuration check when concatenating file\n"
  443. " !!! THIS MAY BREAK THE CONCATENATED TRACK(S) !!!\n"
  444. " -keep-sys keeps all MPEG-4 Systems info when using '-add' / 'cat'\n"
  445. " -keep-all keeps all existing tracks when using '-add'\n"
  446. " * Note: only used when adding IsoMedia files\n"
  447. "\n"
  448. "All the following options can be specified as default or for each track.\n"
  449. "When specified by track the syntax is \":opt\" or \":opt=val\".\n\n"
  450. " -dref keeps media data in original file\n"
  451. " -no-drop forces constant FPS when importing AVI video\n"
  452. " -packed forces packed bitstream when importing raw ASP\n"
  453. " -sbr backward compatible signaling of AAC-SBR\n"
  454. " -sbrx non-backward compatible signaling of AAC-SBR\n"
  455. " -ps backward compatible signaling of AAC-PS\n"
  456. " -psx non-backward compatible signaling of AAC-PS\n"
  457. " -ovsbr oversample SBR\n"
  458. " * Note: SBR AAC, PS AAC and oversampled SBR cannot be detected at import time\n"
  459. " -fps FPS forces frame rate for video and SUB subtitles import\n"
  460. " FPS is either a number or expressed as timescale-increment\n"
  461. " * For raw H263 import, default FPS is 15\n"
  462. " * For all other imports, default FPS is 25\n"
  463. " !! THIS IS IGNORED FOR IsoMedia IMPORT !!\n"
  464. " -mpeg4 forces MPEG-4 sample descriptions when possible (3GPP2)\n"
  465. " For AAC, forces MPEG-4 AAC signaling even if MPEG-2\n"
  466. " -agg N aggregates N audio frames in 1 sample (3GP media only)\n"
  467. " * Note: Maximum value is 15 - Disabled by default\n"
  468. "\n"
  469. );
  470. }
  471. void PrintEncodeUsage()
  472. {
  473. fprintf(stderr, "MPEG-4 Scene Encoding Options\n"
  474. " -mp4 specify input file is for encoding.\n"
  475. " -def encode DEF names\n"
  476. " -sync time_in_ms forces BIFS sync sample generation every time_in_ms\n"
  477. " * Note: cannot be used with -shadow\n"
  478. " -shadow time_ms forces BIFS sync shadow sample generation every time_ms.\n"
  479. " * Note: cannot be used with -sync\n"
  480. " -log generates scene codec log file if available\n"
  481. " -ms file specifies file for track importing\n"
  482. "\nChunk Processing\n"
  483. " -ctx-in file specifies initial context (MP4/BT/XMT)\n"
  484. " * Note: input file must be a commands-only file\n"
  485. " -ctx-out file specifies storage of updated context (MP4/BT/XMT)\n"
  486. "\n"
  487. "LASeR Encoding options\n"
  488. " -resolution res resolution factor (-8 to 7, default 0)\n"
  489. " all coords are multiplied by 2^res before truncation\n"
  490. " -coord-bits bits bits used for encoding truncated coordinates\n"
  491. " (0 to 31, default 12)\n"
  492. " -scale-bits bits extra bits used for encoding truncated scales\n"
  493. " (0 to 4, default 0)\n"
  494. " -auto-quant res resolution is given as if using -resolution\n"
  495. " but coord-bits and scale-bits are infered\n"
  496. );
  497. }
  498. void PrintEncryptUsage()
  499. {
  500. fprintf(stderr, "ISMA Encryption/Decryption Options\n"
  501. " -crypt drm_file crypts a specific track using ISMA AES CTR 128\n"
  502. " -decrypt [drm_file] decrypts a specific track using ISMA AES CTR 128\n"
  503. " * Note: drm_file can be omitted if keys are in file\n"
  504. " -set-kms kms_uri changes KMS location for all tracks or a given one.\n"
  505. " * to adress a track, use \'tkID=kms_uri\'\n"
  506. "\n"
  507. "DRM file syntax for GPAC ISMACryp:\n"
  508. " File is XML and shall start with xml header\n"
  509. " File root is an \"ISMACryp\" element\n"
  510. " File is a list of \"cryptrack\" elements\n"
  511. "\n"
  512. "cryptrack attributes are\n"
  513. " TrackID ID of track to en/decrypt\n"
  514. " key AES-128 key formatted (hex string \'0x\'+32 chars)\n"
  515. " salt CTR IV salt key (64 bits) (hex string \'0x\'+16 chars)\n"
  516. "\nEncryption only attributes:\n"
  517. " Scheme_URI URI of scheme used\n"
  518. " KMS_URI URI of key management system\n"
  519. " * Note: \'self\' writes key and salt in the file\n"
  520. " selectiveType selective encryption type - understood values are:\n"
  521. " \"None\" all samples encrypted (default)\n"
  522. " \"RAP\" only encrypts random access units\n"
  523. " \"Non-RAP\" only encrypts non-random access units\n"
  524. " \"Rand\" random selection is performed\n"
  525. " \"X\" Encrypts every first sample out of X (uint)\n"
  526. " \"RandX\" Encrypts one random sample out of X (uint)\n"
  527. "\n"
  528. " ipmpType IPMP Signaling Type: None, IPMP, IPMPX\n"
  529. " ipmpDescriptorID IPMP_Descriptor ID to use if IPMP(X) is used\n"
  530. " * If not set MP4Box will generate one for you\n"
  531. "\n"
  532. );
  533. }
  534. void PrintHintUsage()
  535. {
  536. fprintf(stderr, "Hinting Options\n"
  537. " -hint hints the file for RTP/RTSP\n"
  538. " -mtu size specifies RTP MTU (max size) in bytes. Default size is 1450\n"
  539. " * Note: this includes the RTP header (12 bytes)\n"
  540. " -copy copies media data to hint track rather than reference\n"
  541. " * Note: speeds up server but takes much more space\n"
  542. " -multi [maxptime] enables frame concatenation in RTP packets if possible\n"
  543. " maxptime max packet duration in ms (optional, default 100ms)\n"
  544. " -rate ck_rate specifies rtp rate in Hz when no default for payload\n"
  545. " * Note: default value is 90000 (MPEG rtp rates)\n"
  546. " -mpeg4 forces MPEG-4 generic payload whenever possible\n"
  547. " -latm forces MPG4-LATM transport for AAC streams\n"
  548. " -static enables static RTP payload IDs whenever possible\n"
  549. " * By default, dynamic payloads are always used\n"
  550. "\n"
  551. "MPEG-4 Generic Payload Options\n"
  552. " -ocr forces all streams to be synchronized\n"
  553. " * Most RTSP servers only support synchronized streams\n"
  554. " -rap signals random access points in RTP packets\n"
  555. " -ts signals AU Time Stamps in RTP packets\n"
  556. " -size signals AU size in RTP packets\n"
  557. " -idx signals AU sequence numbers in RTP packets\n"
  558. " -iod prevents systems tracks embedding in IOD\n"
  559. " * Note: shouldn't be used with -isma option\n"
  560. "\n"
  561. " -add-sdp string adds sdp string to (hint) track (\"-add-sdp tkID:string\")\n"
  562. " or movie. This will take care of SDP lines ordering\n"
  563. " -unhint removes all hinting information.\n"
  564. "\n");
  565. }
  566. void PrintExtractUsage()
  567. {
  568. fprintf(stderr, "Extracting Options:\n"
  569. " -raw TrackID extracts track in raw format when supported\n"
  570. " :output=FileName sets the output filename for this extraction \n"
  571. " -raws TrackID extract each track sample to a file\n"
  572. " * Note: \"TrackID:N\" extracts Nth sample\n"
  573. " -nhnt TrackID extracts track in nhnt format\n"
  574. " -nhml TrackID extracts track in nhml format (XML nhnt).\n"
  575. " * Note: \"-nhml TrackID:full\" for full dump\n"
  576. " -webvtt-raw TrackID extracts raw media track in WebVTT as metadata.\n"
  577. " * Note: \"-webvtt-raw TrackID:embedded\" to include media data in the WebVTT file\n"
  578. " -six TrackID extracts raw media track in experimental XML streaming instructions.\n"
  579. " -single TrackID extracts track to a new mp4 file\n"
  580. " -avi TrackID extracts visual track to an avi file\n"
  581. " -qcp TrackID same as \'-raw\' but defaults to QCP file for EVRC/SMV\n"
  582. " -aviraw TK extracts AVI track in raw format\n"
  583. " $TK can be one of \"video\" \"audio\" \"audioN\"\n"
  584. " -saf remux file to SAF multiplex\n"
  585. " -dvbhdemux demux DVB-H file into IP Datagrams\n"
  586. " * Note: can be used when encoding scene descriptions\n"
  587. " -raw-layer ID same as -raw but skips SVC/MVC extractors when extracting\n"
  588. " -diod extracts file IOD in raw format when supported\n"
  589. "\n"
  590. #if !defined(GPAC_DISABLE_STREAMING)
  591. " -grab-ts IP:port grabs TS over UDP or RTP at IP:port location to output TS file\n"
  592. #endif
  593. "\n");
  594. }
  595. void PrintDumpUsage()
  596. {
  597. fprintf(stderr, "Dumping Options\n"
  598. " -stdb dumps/write to stdout and assumes stdout is opened in binary mode\n"
  599. " -std dumps/write to stdout and try to reopen stdout in binary mode.\n"
  600. " -info [trackID] prints movie info / track info if trackID specified\n"
  601. " * Note: for non IsoMedia files, gets import options\n"
  602. " -bt scene to bt format - removes unknown MPEG4 nodes\n"
  603. " -xmt scene to XMT-A format - removes unknown MPEG4 nodes\n"
  604. " -wrl scene VRML format - removes unknown VRML nodes\n"
  605. " -x3d scene to X3D/XML format - removes unknown X3D nodes\n"
  606. " -x3dv scene to X3D/VRML format - removes unknown X3D nodes\n"
  607. " -lsr scene to LASeR format\n"
  608. " -diso scene IsoMedia file boxes in XML output\n"
  609. " -drtp rtp hint samples structure to XML output\n"
  610. " -dts prints sample timing to text output\n"
  611. " -dnal trackID prints NAL sample info of given track\n"
  612. " -sdp dumps SDP description of hinted file\n"
  613. " -dcr ISMACryp samples structure to XML output\n"
  614. " -dump-cover Extracts cover art\n"
  615. " -dump-chap Extracts chapter file\n"
  616. "\n"
  617. #ifndef GPAC_DISABLE_ISOM_WRITE
  618. " -ttxt Converts input subtitle to GPAC TTXT format\n"
  619. #endif
  620. " -ttxt TrackID Dumps Text track to GPAC TTXT format\n"
  621. #ifndef GPAC_DISABLE_ISOM_WRITE
  622. " -srt Converts input subtitle to SRT format\n"
  623. #endif
  624. " -srt TrackID Dumps Text track to SRT format\n"
  625. "\n"
  626. " -stat generates node/field statistics for scene\n"
  627. " -stats generates node/field statistics per MPEG-4 Access Unit\n"
  628. " -statx generates node/field statistics for scene after each AU\n"
  629. "\n"
  630. " -hash generates SHA-1 Hash of the input file\n"
  631. "\n");
  632. }
  633. void PrintMetaUsage()
  634. {
  635. fprintf(stderr, "Meta handling Options\n"
  636. " -set-meta args sets given meta type - syntax: \"ABCD[:tk=ID]\"\n"
  637. " * ABCD: four char meta type (NULL or 0 to remove meta)\n"
  638. " * [:tk=ID]: if not set use root (file) meta\n"
  639. " if ID is 0 use moov meta\n"
  640. " if ID is not 0 use track meta\n"
  641. " -add-item args adds resource to meta\n"
  642. " * syntax: file_path + options (\':\' separated):\n"
  643. " tk=ID: meta adressing (file, moov, track)\n"
  644. " name=str: item name\n"
  645. " mime=mtype: item mime type\n"
  646. " encoding=enctype: item content-encoding type\n"
  647. " * file_path \"this\" or \"self\": item is the file itself\n"
  648. " -rem-item args removes resource from meta - syntax: item_ID[:tk=ID]\n"
  649. " -set-primary args sets item as primary for meta - syntax: item_ID[:tk=ID]\n"
  650. " -set-xml args sets meta XML data\n"
  651. " * syntax: xml_file_path[:tk=ID][:binary]\n"
  652. " -rem-xml [tk=ID] removes meta XML data\n"
  653. " -dump-xml args dumps meta XML to file - syntax file_path[:tk=ID]\n"
  654. " -dump-item args dumps item to file - syntax item_ID[:tk=ID][:path=fileName]\n"
  655. " -package packages input XML file into an ISO container\n"
  656. " * all media referenced except hyperlinks are added to file\n"
  657. " -mgt packages input XML file into an MPEG-U widget with ISO container.\n"
  658. " * all files contained in the current folder are added to the widget package\n"
  659. "\n");
  660. }
  661. void PrintSWFUsage()
  662. {
  663. fprintf(stderr,
  664. "SWF Importer Options\n"
  665. "\n"
  666. "MP4Box can import simple Macromedia Flash files (\".SWF\")\n"
  667. "You can specify a SWF input file with \'-bt\', \'-xmt\' and \'-mp4\' options\n"
  668. "\n"
  669. " -global all SWF defines are placed in first scene replace\n"
  670. " * Note: By default SWF defines are sent when needed\n"
  671. " -no-ctrl uses a single stream for movie control and dictionary\n"
  672. " * Note: this will disable ActionScript\n"
  673. " -no-text removes all SWF text\n"
  674. " -no-font removes all embedded SWF Fonts (terminal fonts used)\n"
  675. " -no-line removes all lines from SWF shapes\n"
  676. " -no-grad removes all gradients from swf shapes\n"
  677. " -quad uses quadratic bezier curves instead of cubic ones\n"
  678. " -xlp support for lines transparency and scalability\n"
  679. " -flatten ang complementary angle below which 2 lines are merged\n"
  680. " * Note: angle \'0\' means no flattening\n"
  681. "\n"
  682. );
  683. }
  684. void PrintUsage()
  685. {
  686. fprintf (stderr, "MP4Box [option] input [option]\n"
  687. " -h general general options help\n"
  688. " -h hint hinting options help\n"
  689. " -h dash DASH segmenter help\n"
  690. " -h import import options help\n"
  691. " -h encode encode options help\n"
  692. " -h meta meta handling options help\n"
  693. " -h extract extraction options help\n"
  694. " -h dump dump options help\n"
  695. " -h swf Flash (SWF) options help\n"
  696. " -h crypt ISMA E&A options help\n"
  697. " -h format supported formats help\n"
  698. " -h rtp file streamer help\n"
  699. " -h live BIFS streamer help\n"
  700. " -h all all options are printed\n"
  701. "\n"
  702. " -nodes lists supported MPEG4 nodes\n"
  703. " -node NodeName gets MPEG4 node syntax and QP info\n"
  704. " -xnodes lists supported X3D nodes\n"
  705. " -xnode NodeName gets X3D node syntax\n"
  706. " -snodes lists supported SVG nodes\n"
  707. " -snode NodeName gets SVG node syntax\n"
  708. " -languages lists supported ISO 639 languages\n"
  709. "\n"
  710. " -quiet quiet mode\n"
  711. " -noprog disables progress\n"
  712. " -v verbose mode\n"
  713. " -logs set log tools and levels, formatted as a ':'-separated list of toolX[:toolZ]@levelX\n"
  714. " -version gets build version\n"
  715. " -- INPUT escape option if INPUT starts with - character\n"
  716. "\n"
  717. );
  718. }
  719. extern char *split_file_name(char *path)
  720. {
  721. char *file_name;
  722. #if defined(__MINGW32__) || defined(_MSC_VER)
  723. if ((file_name = _mbsrchr(path, '\\'))
  724. || (file_name = strrchr(path, '/')))
  725. #else
  726. if ((file_name = strrchr(path, GF_PATH_SEPARATOR)))
  727. #endif
  728. file_name++;
  729. if (!file_name)
  730. file_name = path;
  731. return file_name;
  732. }
  733. void scene_coding_log(void *cbk, u32 log_level, u32 log_tool, const char *fmt, va_list vlist)
  734. {
  735. FILE *logs = cbk;
  736. if (log_tool != GF_LOG_CODING) return;
  737. vfprintf(logs, fmt, vlist);
  738. fflush(logs);
  739. }
  740. #ifndef GPAC_DISABLE_ISOM_HINTING
  741. /*
  742. MP4 File Hinting
  743. */
  744. void SetupClockReferences(GF_ISOFile *file)
  745. {
  746. u32 i, count, ocr_id;
  747. count = gf_isom_get_track_count(file);
  748. if (count==1) return;
  749. ocr_id = 0;
  750. for (i=0; i<count; i++) {
  751. if (!gf_isom_is_track_in_root_od(file, i+1)) continue;
  752. ocr_id = gf_isom_get_track_id(file, i+1);
  753. break;
  754. }
  755. /*doesn't look like MP4*/
  756. if (!ocr_id) return;
  757. for (i=0; i<count; i++) {
  758. GF_ESD *esd = gf_isom_get_esd(file, i+1, 1);
  759. if (esd) {
  760. esd->OCRESID = ocr_id;
  761. gf_isom_change_mpeg4_description(file, i+1, 1, esd);
  762. gf_odf_desc_del((GF_Descriptor *) esd);
  763. }
  764. }
  765. }
  766. /*base RTP payload type used (you can specify your own types if needed)*/
  767. #define BASE_PAYT 96
  768. 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)
  769. {
  770. GF_ESD *esd;
  771. GF_InitialObjectDescriptor *iod;
  772. u32 i, val, res, streamType;
  773. u32 sl_mode, prev_ocr, single_ocr, nb_done, tot_bw, bw, flags, spec_type;
  774. GF_Err e;
  775. char szPayload[30];
  776. GF_RTPHinter *hinter;
  777. Bool copy, has_iod, single_av;
  778. u8 init_payt = BASE_PAYT;
  779. u32 iod_mode, mtype;
  780. u32 media_group = 0;
  781. u8 media_prio = 0;
  782. tot_bw = 0;
  783. prev_ocr = 0;
  784. single_ocr = 1;
  785. has_iod = 1;
  786. iod = (GF_InitialObjectDescriptor *) gf_isom_get_root_od(file);
  787. if (!iod) has_iod = 0;
  788. else {
  789. if (!gf_list_count(iod->ESDescriptors)) has_iod = 0;
  790. gf_odf_desc_del((GF_Descriptor *) iod);
  791. }
  792. spec_type = gf_isom_guess_specification(file);
  793. single_av = single_group ? 1 : gf_isom_is_single_av(file);
  794. /*first make sure we use a systems track as base OCR*/
  795. for (i=0; i<gf_isom_get_track_count(file); i++) {
  796. res = gf_isom_get_media_type(file, i+1);
  797. if ((res==GF_ISOM_MEDIA_SCENE) || (res==GF_ISOM_MEDIA_OD)) {
  798. if (gf_isom_is_track_in_root_od(file, i+1)) {
  799. gf_isom_set_default_sync_track(file, i+1);
  800. break;
  801. }
  802. }
  803. }
  804. nb_done = 0;
  805. for (i=0; i<gf_isom_get_track_count(file); i++) {
  806. sl_mode = base_flags;
  807. copy = copy_data;
  808. /*skip emty tracks (mainly MPEG-4 interaction streams...*/
  809. if (!gf_isom_get_sample_count(file, i+1)) continue;
  810. if (!gf_isom_is_track_enabled(file, i+1)) {
  811. fprintf(stderr, "Track ID %d disabled - skipping hint\n", gf_isom_get_track_id(file, i+1) );
  812. continue;
  813. }
  814. mtype = gf_isom_get_media_type(file, i+1);
  815. switch (mtype) {
  816. case GF_ISOM_MEDIA_VISUAL:
  817. if (single_av) {
  818. media_group = 2;
  819. media_prio = 2;
  820. }
  821. break;
  822. case GF_ISOM_MEDIA_AUDIO:
  823. if (single_av) {
  824. media_group = 2;
  825. media_prio = 1;
  826. }
  827. break;
  828. case GF_ISOM_MEDIA_HINT:
  829. continue;
  830. default:
  831. /*no hinting of systems track on isma*/
  832. if (spec_type==GF_4CC('I','S','M','A')) continue;
  833. }
  834. mtype = gf_isom_get_media_subtype(file, i+1, 1);
  835. if ((mtype==GF_ISOM_SUBTYPE_MPEG4) || (mtype==GF_ISOM_SUBTYPE_MPEG4_CRYP) ) mtype = gf_isom_get_mpeg4_subtype(file, i+1, 1);
  836. if (!single_av) {
  837. /*one media per group only (we should prompt user for group selection)*/
  838. media_group ++;
  839. media_prio = 1;
  840. }
  841. streamType = 0;
  842. esd = gf_isom_get_esd(file, i+1, 1);
  843. if (esd) {
  844. streamType = esd->decoderConfig->streamType;
  845. if (!prev_ocr) {
  846. prev_ocr = esd->OCRESID;
  847. if (!esd->OCRESID) prev_ocr = esd->ESID;
  848. } else if (esd->OCRESID && prev_ocr != esd->OCRESID) {
  849. single_ocr = 0;
  850. }
  851. /*OD MUST BE WITHOUT REFERENCES*/
  852. if (streamType==1) copy = 1;
  853. }
  854. gf_odf_desc_del((GF_Descriptor *) esd);
  855. if (!regular_iod && gf_isom_is_track_in_root_od(file, i+1)) {
  856. /*single AU - check if base64 would fit in ESD (consider 33% overhead of base64), otherwise stream*/
  857. if (gf_isom_get_sample_count(file, i+1)==1) {
  858. GF_ISOSample *samp = gf_isom_get_sample(file, i+1, 1, &val);
  859. if (streamType) {
  860. res = gf_hinter_can_embbed_data(samp->data, samp->dataLength, streamType);
  861. } else {
  862. /*not a system track, we shall hint it*/
  863. res = 0;
  864. }
  865. if (samp) gf_isom_sample_del(&samp);
  866. if (res) continue;
  867. }
  868. }
  869. if (interleave) sl_mode |= GP_RTP_PCK_USE_INTERLEAVING;
  870. hinter = gf_hinter_track_new(file, i+1, MTUSize, max_ptime, rtp_rate, sl_mode, init_payt, copy, media_group, media_prio, &e);
  871. if (!hinter) {
  872. if (e) {
  873. fprintf(stderr, "Cannot create hinter (%s)\n", gf_error_to_string(e));
  874. if (!nb_done) return e;
  875. }
  876. continue;
  877. }
  878. bw = gf_hinter_track_get_bandwidth(hinter);
  879. tot_bw += bw;
  880. flags = gf_hinter_track_get_flags(hinter);
  881. //set extraction mode for AVC/SVC
  882. gf_isom_set_nalu_extract_mode(file, i+1, GF_ISOM_NALU_EXTRACT_LAYER_ONLY);
  883. gf_hinter_track_get_payload_name(hinter, szPayload);
  884. fprintf(stderr, "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);
  885. if (flags & GP_RTP_PCK_SYSTEMS_CAROUSEL) fprintf(stderr, "\tMPEG-4 Systems stream carousel enabled\n");
  886. /*
  887. if (flags & GP_RTP_PCK_FORCE_MPEG4) fprintf(stderr, "\tMPEG4 transport forced\n");
  888. if (flags & GP_RTP_PCK_USE_MULTI) fprintf(stderr, "\tRTP aggregation enabled\n");
  889. */
  890. e = gf_hinter_track_process(hinter);
  891. if (!e) e = gf_hinter_track_finalize(hinter, has_iod);
  892. gf_hinter_track_del(hinter);
  893. if (e) {
  894. fprintf(stderr, "Error while hinting (%s)\n", gf_error_to_string(e));
  895. if (!nb_done) return e;
  896. }
  897. init_payt++;
  898. nb_done ++;
  899. }
  900. if (has_iod) {
  901. iod_mode = GF_SDP_IOD_ISMA;
  902. if (regular_iod) iod_mode = GF_SDP_IOD_REGULAR;
  903. } else {
  904. iod_mode = GF_SDP_IOD_NONE;
  905. }
  906. gf_hinter_finalize(file, iod_mode, tot_bw);
  907. if (!single_ocr)
  908. fprintf(stderr, "Warning: at least 2 timelines found in the file\nThis may not be supported by servers/players\n\n");
  909. return GF_OK;
  910. }
  911. #endif /*GPAC_DISABLE_ISOM_HINTING*/
  912. #if !defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_AV_PARSERS)
  913. static void check_media_profile(GF_ISOFile *file, u32 track)
  914. {
  915. u8 PL;
  916. GF_M4ADecSpecInfo dsi;
  917. GF_ESD *esd = gf_isom_get_esd(file, track, 1);
  918. if (!esd) return;
  919. switch (esd->decoderConfig->streamType) {
  920. case 0x04:
  921. PL = gf_isom_get_pl_indication(file, GF_ISOM_PL_VISUAL);
  922. if (esd->decoderConfig->objectTypeIndication==GPAC_OTI_VIDEO_MPEG4_PART2) {
  923. GF_M4VDecSpecInfo dsi;
  924. gf_m4v_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &dsi);
  925. if (dsi.VideoPL > PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, dsi.VideoPL);
  926. } else if ((esd->decoderConfig->objectTypeIndication==GPAC_OTI_VIDEO_AVC) || (esd->decoderConfig->objectTypeIndication==GPAC_OTI_VIDEO_SVC)) {
  927. gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0x15);
  928. } else if (!PL) {
  929. gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0xFE);
  930. }
  931. break;
  932. case 0x05:
  933. PL = gf_isom_get_pl_indication(file, GF_ISOM_PL_AUDIO);
  934. switch (esd->decoderConfig->objectTypeIndication) {
  935. case GPAC_OTI_AUDIO_AAC_MPEG2_MP:
  936. case GPAC_OTI_AUDIO_AAC_MPEG2_LCP:
  937. case GPAC_OTI_AUDIO_AAC_MPEG2_SSRP:
  938. case GPAC_OTI_AUDIO_AAC_MPEG4:
  939. gf_m4a_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &dsi);
  940. if (dsi.audioPL > PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, dsi.audioPL);
  941. break;
  942. default:
  943. if (!PL) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0xFE);
  944. }
  945. break;
  946. }
  947. gf_odf_desc_del((GF_Descriptor *) esd);
  948. }
  949. void remove_systems_tracks(GF_ISOFile *file)
  950. {
  951. u32 i, count;
  952. count = gf_isom_get_track_count(file);
  953. if (count==1) return;
  954. /*force PL rewrite*/
  955. gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0);
  956. gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0);
  957. gf_isom_set_pl_indication(file, GF_ISOM_PL_OD, 1); /*the lib always remove IOD when no profiles are specified..*/
  958. for (i=0; i<gf_isom_get_track_count(file); i++) {
  959. switch (gf_isom_get_media_type(file, i+1)) {
  960. case GF_ISOM_MEDIA_VISUAL:
  961. case GF_ISOM_MEDIA_AUDIO:
  962. case GF_ISOM_MEDIA_TEXT:
  963. case GF_ISOM_MEDIA_SUBT:
  964. gf_isom_remove_track_from_root_od(file, i+1);
  965. check_media_profile(file, i+1);
  966. break;
  967. /*only remove real systems tracks (eg, delaing with scene description & presentation)
  968. but keep meta & all unknown tracks*/
  969. case GF_ISOM_MEDIA_SCENE:
  970. switch (gf_isom_get_media_subtype(file, i+1, 1)) {
  971. case GF_ISOM_MEDIA_DIMS:
  972. gf_isom_remove_track_from_root_od(file, i+1);
  973. continue;
  974. default:
  975. break;
  976. }
  977. case GF_ISOM_MEDIA_OD:
  978. case GF_ISOM_MEDIA_OCR:
  979. case GF_ISOM_MEDIA_MPEGJ:
  980. gf_isom_remove_track(file, i+1);
  981. i--;
  982. break;
  983. default:
  984. break;
  985. }
  986. }
  987. /*none required*/
  988. if (!gf_isom_get_pl_indication(file, GF_ISOM_PL_AUDIO)) gf_isom_set_pl_indication(file, GF_ISOM_PL_AUDIO, 0xFF);
  989. if (!gf_isom_get_pl_indication(file, GF_ISOM_PL_VISUAL)) gf_isom_set_pl_indication(file, GF_ISOM_PL_VISUAL, 0xFF);
  990. gf_isom_set_pl_indication(file, GF_ISOM_PL_OD, 0xFF);
  991. gf_isom_set_pl_indication(file, GF_ISOM_PL_SCENE, 0xFF);
  992. gf_isom_set_pl_indication(file, GF_ISOM_PL_GRAPHICS, 0xFF);
  993. gf_isom_set_pl_indication(file, GF_ISOM_PL_INLINE, 0);
  994. }
  995. #endif /*!defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_AV_PARSERS)*/
  996. /*return value:
  997. 0: not supported
  998. 1: ISO media
  999. 2: input bt file (.bt, .wrl)
  1000. 3: input XML file (.xmt)
  1001. 4: input SVG file (.svg)
  1002. 5: input SWF file (.swf)
  1003. 6: input LASeR file (.lsr or .saf)
  1004. */
  1005. u32 get_file_type_by_ext(char *inName)
  1006. {
  1007. u32 type = 0;
  1008. char *file_name = split_file_name(inName);
  1009. char *ext = strrchr(file_name, '.');
  1010. if (ext) {
  1011. char *sep;
  1012. if (!strcmp(ext, ".gz")) {
  1013. char *gz_ext = ext;
  1014. while (ext != file_name) {
  1015. ext--;
  1016. if (ext[0] == '.')
  1017. break;
  1018. }
  1019. if (ext == file_name)
  1020. ext = gz_ext;
  1021. }
  1022. ext+=1;
  1023. sep = strchr(ext, '.');
  1024. if (sep) sep[0] = 0;
  1025. if (!stricmp(ext, "mp4") || !stricmp(ext, "3gp") || !stricmp(ext, "mov") || !stricmp(ext, "3g2") || !stricmp(ext, "3gs")) type = 1;
  1026. else if (!stricmp(ext, "bt") || !stricmp(ext, "wrl") || !stricmp(ext, "x3dv")) type = 2;
  1027. else if (!stricmp(ext, "xmt") || !stricmp(ext, "x3d")) type = 3;
  1028. else if (!stricmp(ext, "lsr") || !stricmp(ext, "saf")) type = 6;
  1029. else if (!stricmp(ext, "svg")) type = 4;
  1030. else if (!stricmp(ext, "xsr")) type = 4;
  1031. else if (!stricmp(ext, "xml")) type = 4;
  1032. else if (!stricmp(ext, "swf")) type = 5;
  1033. else if (!stricmp(ext, "jp2")) {
  1034. if (sep) sep[0] = '.';
  1035. return 0;
  1036. }
  1037. else type = 0;
  1038. if (sep) sep[0] = '.';
  1039. }
  1040. /*try open file in read mode*/
  1041. if (!type && gf_isom_probe_file(inName)) type = 1;
  1042. return type;
  1043. }
  1044. #ifndef GPAC_DISABLE_ISOM_WRITE
  1045. static Bool can_convert_to_isma(GF_ISOFile *file)
  1046. {
  1047. u32 spec = gf_isom_guess_specification(file);
  1048. if (spec==GF_4CC('I','S','M','A')) return 1;
  1049. return 0;
  1050. }
  1051. #endif
  1052. static void progress_quiet(const void *cbck, const char *title, u64 done, u64 total) { }
  1053. typedef struct
  1054. {
  1055. u32 trackID;
  1056. char *line;
  1057. } SDPLine;
  1058. typedef struct
  1059. {
  1060. /*actions:
  1061. 0: set meta type
  1062. 1: add item
  1063. 2: rem item
  1064. 3: set item primary
  1065. 4: set XML
  1066. 5: set binary XML
  1067. 6: rem XML
  1068. 7: dump item
  1069. 8: dump XML
  1070. */
  1071. u32 act_type;
  1072. Bool root_meta, use_dref;
  1073. u32 trackID;
  1074. u32 meta_4cc;
  1075. char szPath[GF_MAX_PATH];
  1076. char szName[1024], mime_type[1024], enc_type[1024];
  1077. u32 item_id;
  1078. } MetaAction;
  1079. #ifndef GPAC_DISABLE_ISOM_WRITE
  1080. static Bool parse_meta_args(MetaAction *meta, char *opts)
  1081. {
  1082. Bool ret = 0;
  1083. char szSlot[1024], *next;
  1084. meta->mime_type[0] = 0;
  1085. meta->enc_type[0] = 0;
  1086. meta->szName[0] = 0;
  1087. meta->szPath[0] = 0;
  1088. meta->trackID = 0;
  1089. meta->root_meta = 1;
  1090. if (!opts) return 0;
  1091. while (1) {
  1092. if (!opts || !opts[0]) return ret;
  1093. if (opts[0]==':') opts += 1;
  1094. strcpy(szSlot, opts);
  1095. next = strchr(szSlot, ':');
  1096. /*use ':' as separator, but beware DOS paths...*/
  1097. if (next && next[1]=='\\') next = strchr(szSlot+2, ':');
  1098. if (next) next[0] = 0;
  1099. if (!strnicmp(szSlot, "tk=", 3)) {
  1100. sscanf(szSlot, "tk=%u", &meta->trackID);
  1101. meta->root_meta = 0;
  1102. ret = 1;
  1103. }
  1104. else if (!strnicmp(szSlot, "name=", 5)) { strcpy(meta->szName, szSlot+5); ret = 1; }
  1105. else if (!strnicmp(szSlot, "path=", 5)) { strcpy(meta->szPath, szSlot+5); ret = 1; }
  1106. else if (!strnicmp(szSlot, "mime=", 5)) { strcpy(meta->mime_type, szSlot+5); ret = 1; }
  1107. else if (!strnicmp(szSlot, "encoding=", 9)) { strcpy(meta->enc_type, szSlot+9); ret = 1; }
  1108. else if (!strnicmp(szSlot, "dref", 4)) { meta->use_dref = 1; ret = 1; }
  1109. else if (!stricmp(szSlot, "binary")) {
  1110. if (meta->act_type==4) meta->act_type=5;
  1111. ret = 1;
  1112. }
  1113. else if (!strchr(szSlot, '=')) {
  1114. switch (meta->act_type) {
  1115. case 0:
  1116. if (!stricmp(szSlot, "null") || !stricmp(szSlot, "0")) meta->meta_4cc = 0;
  1117. else meta->meta_4cc = GF_4CC(szSlot[0], szSlot[1], szSlot[2], szSlot[3]);
  1118. ret = 1;
  1119. break;
  1120. case 1:
  1121. case 4:
  1122. case 7:
  1123. strcpy(meta->szPath, szSlot);
  1124. ret = 1;
  1125. break;
  1126. case 2:
  1127. case 3:
  1128. case 8:
  1129. meta->item_id = atoi(szSlot);
  1130. ret = 1;
  1131. break;
  1132. }
  1133. }
  1134. opts += strlen(szSlot);
  1135. }
  1136. return ret;
  1137. }
  1138. #endif
  1139. typedef struct
  1140. {
  1141. /*0: set tsel param - 1 remove tsel - 2 remove all tsel info in alternate group - 3 remove all tsel info in file*/
  1142. u32 act_type;
  1143. u32 trackID;
  1144. u32 refTrackID;
  1145. u32 criteria[30];
  1146. u32 nb_criteria;
  1147. Bool is_switchGroup;
  1148. u32 switchGroupID;
  1149. } TSELAction;
  1150. static Bool parse_tsel_args(TSELAction **__tsel_list, char *opts, u32 *nb_tsel_act)
  1151. {
  1152. u32 act;
  1153. u32 refTrackID = 0;
  1154. Bool has_switch_id;
  1155. u32 switch_id = 0;
  1156. u32 criteria[30];
  1157. u32 nb_criteria = 0;
  1158. TSELAction *tsel_act;
  1159. char szSlot[1024], *next;
  1160. TSELAction *tsel_list = *__tsel_list;
  1161. has_switch_id = 0;
  1162. act = tsel_list[*nb_tsel_act].act_type;
  1163. if (!opts) return 0;
  1164. while (1) {
  1165. if (!opts || !opts[0]) return 1;
  1166. if (opts[0]==':') opts += 1;
  1167. strcpy(szSlot, opts);
  1168. next = strchr(szSlot, ':');
  1169. /*use ':' as separator, but beware DOS paths...*/
  1170. if (next && next[1]=='\\') next = strchr(szSlot+2, ':');
  1171. if (next) next[0] = 0;
  1172. if (!strnicmp(szSlot, "ref=", 4)) refTrackID = atoi(szSlot+4);
  1173. else if (!strnicmp(szSlot, "switchID=", 9)) {
  1174. if (atoi(szSlot+9)<0) {
  1175. switch_id = 0;
  1176. has_switch_id = 0;
  1177. } else {
  1178. switch_id = atoi(szSlot+9);
  1179. has_switch_id = 1;
  1180. }
  1181. }
  1182. else if (!strnicmp(szSlot, "switchID", 8)) {
  1183. switch_id = 0;
  1184. has_switch_id = 1;
  1185. }
  1186. else if (!strnicmp(szSlot, "criteria=", 9)) {
  1187. u32 j=9;
  1188. nb_criteria = 0;
  1189. while (j+3<strlen(szSlot)) {
  1190. criteria[nb_criteria] = GF_4CC(szSlot[j], szSlot[j+1], szSlot[j+2], szSlot[j+3]);
  1191. j+=5;
  1192. nb_criteria++;
  1193. }
  1194. }
  1195. else if (!strnicmp(szSlot, "trackID=", 8) || !strchr(szSlot, '=') ) {
  1196. __tsel_list = gf_realloc(__tsel_list, sizeof(TSELAction) * (*nb_tsel_act + 1));
  1197. tsel_list = *__tsel_list;
  1198. tsel_act = &tsel_list[*nb_tsel_act];
  1199. memset(tsel_act, 0, sizeof(TSELAction));
  1200. tsel_act->act_type = act;
  1201. tsel_act->trackID = strchr(szSlot, '=') ? atoi(szSlot+8) : atoi(szSlot);
  1202. tsel_act->refTrackID = refTrackID;
  1203. tsel_act->switchGroupID = switch_id;
  1204. tsel_act->is_switchGroup = has_switch_id;
  1205. tsel_act->nb_criteria = nb_criteria;
  1206. memcpy(tsel_act->criteria, criteria, sizeof(u32)*nb_criteria);
  1207. if (!refTrackID)
  1208. refTrackID = tsel_act->trackID;
  1209. (*nb_tsel_act) ++;
  1210. }
  1211. opts += strlen(szSlot);
  1212. }
  1213. return 1;
  1214. }
  1215. #define CHECK_NEXT_ARG if (i+1==(u32)argc) { fprintf(stderr, "Missing arg - please check usage\n"); MP4BOX_EXIT_WITH_CODE(1); }
  1216. typedef struct
  1217. {
  1218. /*
  1219. 0: rem track
  1220. 1: set track language
  1221. 2: set track delay
  1222. 3: set track KMS URI
  1223. 4: set visual track PAR if possible
  1224. 5: set track handler name
  1225. 6: enables track
  1226. 7: disables track
  1227. 8: referenceTrack
  1228. 9: raw extraction
  1229. */
  1230. u32 act_type;
  1231. /*track ID*/
  1232. u32 trackID;
  1233. char lang[4];
  1234. s32 delay_ms;
  1235. const char *kms;
  1236. const char *hdl_name;
  1237. s32 par_num, par_den;
  1238. u32 dump_type, sample_num;
  1239. char *out_name;
  1240. } TrackAction;
  1241. enum
  1242. {
  1243. GF_ISOM_CONV_TYPE_ISMA = 1,
  1244. GF_ISOM_CONV_TYPE_ISMA_EX,
  1245. GF_ISOM_CONV_TYPE_3GPP,
  1246. GF_ISOM_CONV_TYPE_IPOD,
  1247. GF_ISOM_CONV_TYPE_PSP
  1248. };
  1249. #define MP4BOX_EXIT_WITH_CODE(__ret_code) \
  1250. if (mpd_base_urls) gf_free(mpd_base_urls); \
  1251. if (sdp_lines) gf_free(sdp_lines); \
  1252. if (metas) gf_free(metas); \
  1253. if (tracks) { \
  1254. for (i=0; i<nb_track_act; i++) { \
  1255. if (tracks[i].out_name) \
  1256. gf_free(tracks[i].out_name); \
  1257. } \
  1258. gf_free(tracks); \
  1259. }\
  1260. if (tsel_acts) gf_free(tsel_acts); \
  1261. if (brand_add) gf_free(brand_add); \
  1262. if (brand_rem) gf_free(brand_rem); \
  1263. if (dash_inputs) gf_free(dash_inputs); \
  1264. gf_sys_close(); \
  1265. return __ret_code; \
  1266. GF_DashSegmenterInput *set_dash_input(GF_DashSegmenterInput *dash_inputs, char *name, u32 *nb_dash_inputs)
  1267. {
  1268. GF_DashSegmenterInput *di;
  1269. char *sep = strchr(name, ':');
  1270. if (sep && (sep[1]=='\\')) sep = strchr(sep+1, ':');
  1271. dash_inputs = gf_realloc(dash_inputs, sizeof(GF_DashSegmenterInput) * (*nb_dash_inputs + 1) );
  1272. memset(&dash_inputs[*nb_dash_inputs], 0, sizeof(GF_DashSegmenterInput) );
  1273. di = &dash_inputs[*nb_dash_inputs];
  1274. (*nb_dash_inputs)++;
  1275. if (sep) {
  1276. char *opts = sep+1;
  1277. sep[0] = 0;
  1278. while (opts) {
  1279. sep = strchr(opts, ':');
  1280. if (sep) sep[0] = 0;
  1281. if (!strnicmp(opts, "id=", 3)) strncpy(di->representationID, opts+3, 99);
  1282. else if (!strnicmp(opts, "period=", 7)) strncpy(di->periodID, opts+7, 99);
  1283. else if (!strnicmp(opts, "bandwidth=", 10)) di->bandwidth = atoi(opts+10);
  1284. else if (!strnicmp(opts, "role=", 5)) strncpy(di->role, opts+5, 99);
  1285. if (!sep) break;
  1286. sep[0] = ':';
  1287. opts = sep+1;
  1288. }
  1289. }
  1290. di->file_name = name;
  1291. if (!strlen(di->representationID)) sprintf(di->representationID, "%d", *nb_dash_inputs);
  1292. return dash_inputs;
  1293. }
  1294. static GF_Err parse_track_action_params(char *string, TrackAction *action)
  1295. {
  1296. char *param = string;
  1297. while (param) {
  1298. param = strchr(param, ':');
  1299. if (param) {
  1300. *param = 0;
  1301. param++;
  1302. if (!strncmp("vttnomerge", param, 10)) {
  1303. action->dump_type |= GF_EXPORT_WEBVTT_NOMERGE;
  1304. } else if (!strncmp("layer", param, 5)) {
  1305. action->dump_type |= GF_EXPORT_SVC_LAYER;
  1306. } else if (!strncmp("full", param, 4)) {
  1307. action->dump_type |= GF_EXPORT_NHML_FULL;
  1308. } else if (!strncmp("embedded", param, 8)) {
  1309. action->dump_type |= GF_EXPORT_WEBVTT_META_EMBEDDED;
  1310. } else if (!strncmp("output=", param, 7)) {
  1311. action->out_name = gf_strdup(param+7);
  1312. } else if (action->dump_type == GF_EXPORT_RAW_SAMPLES) {
  1313. action->sample_num = atoi(param);
  1314. }
  1315. }
  1316. }
  1317. if (!strcmp(string, "*")) {
  1318. action->trackID = (u32) -1;
  1319. } else {
  1320. action->trackID = atoi(string);
  1321. }
  1322. return GF_OK;
  1323. }
  1324. static u32 create_new_track_action(char *string, TrackAction **actions, u32 *nb_track_act, u32 dump_type)
  1325. {
  1326. *actions = (TrackAction *)gf_realloc(*actions, sizeof(TrackAction) * (*nb_track_act+1));
  1327. memset(&(*actions)[*nb_track_act], 0, sizeof(TrackAction) );
  1328. (*actions)[*nb_track_act].act_type = 9;
  1329. (*actions)[*nb_track_act].dump_type = dump_type;
  1330. parse_track_action_params(string, &(*actions)[*nb_track_act]);
  1331. (*nb_track_act)++;
  1332. return dump_type;
  1333. }
  1334. static void on_gpac_log(void *cbk, u32 ll, u32 lm, const char *fmt, va_list list)
  1335. {
  1336. FILE *logs = cbk;
  1337. vfprintf(logs, fmt, list);
  1338. fflush(logs);
  1339. }
  1340. int mp4boxMain(int argc, char **argv)
  1341. {
  1342. char outfile[5000];
  1343. GF_Err e;
  1344. #ifndef GPAC_DISABLE_SCENE_ENCODER
  1345. GF_SMEncodeOptions opts;
  1346. #endif
  1347. SDPLine *sdp_lines = NULL;
  1348. Double interleaving_time, split_duration, split_start, import_fps, dash_duration, dash_subduration;
  1349. MetaAction *metas = NULL;
  1350. TrackAction *tracks = NULL;
  1351. TSELAction *tsel_acts = NULL;
  1352. u64 movie_time, initial_tfdt;
  1353. s32 subsegs_per_sidx;
  1354. u32 *brand_add = NULL;
  1355. u32 *brand_rem = NULL;
  1356. GF_DashSwitchingMode bitstream_switching_mode = GF_DASH_BSMODE_INBAND;
  1357. u32 i, stat_level, hint_flags, info_track_id, import_flags, nb_add, nb_cat, crypt, 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, dump_nal, time_shift_depth, dash_dynamic, initial_moof_sn;
  1358. Bool HintIt, needSave, FullInter, Frag, HintInter, dump_std, dump_rtp, dump_mode, regular_iod, remove_sys_tracks, remove_hint, force_new, remove_root_od, import_subtitle;
  1359. Bool print_sdp, print_info, open_edit, dump_isom, dump_cr, force_ocr, encode, do_log, do_flat, dump_srt, dump_ttxt, dump_timestamps, do_saf, dump_m2ts, dump_cart, do_hash, verbose, force_cat, align_cat, pack_wgt, single_group, dash_live, no_fragments_defaults;
  1360. 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_file;
  1361. u32 track_dump_type;
  1362. u32 trackID;
  1363. Double min_buffer = 1.5;
  1364. u32 ast_shift_sec = 1;
  1365. u32 dump_chap = 0;
  1366. char **mpd_base_urls = NULL;
  1367. u32 nb_mpd_base_urls=0;
  1368. u32 dash_scale = 1000;
  1369. #ifndef GPAC_DISABLE_MPD
  1370. Bool do_mpd = 0;
  1371. #endif
  1372. #ifndef GPAC_DISABLE_SCENE_ENCODER
  1373. Bool chunk_mode=0;
  1374. #endif
  1375. #ifndef GPAC_DISABLE_ISOM_HINTING
  1376. Bool HintCopy=0;
  1377. u32 MTUSize = 1450;
  1378. #endif
  1379. GF_ISOFile *file;
  1380. u32 mpd_update_time = 0;
  1381. Bool stream_rtp=0;
  1382. Bool live_scene=0;
  1383. Bool enable_mem_tracker = 0;
  1384. Bool dump_iod=0;
  1385. Bool pssh_in_moof=0;
  1386. Bool daisy_chain_sidx=0;
  1387. Bool single_segment=0;
  1388. Bool single_file=0;
  1389. Bool segment_timeline=0;
  1390. u32 segment_marker = 0;
  1391. GF_DashProfile dash_profile = GF_DASH_PROFILE_UNKNOWN;
  1392. Bool use_url_template=0;
  1393. Bool seg_at_rap=0;
  1394. Bool frag_at_rap=0;
  1395. Bool adjust_split_end = 0;
  1396. Bool memory_frags = 1;
  1397. Bool keep_utc = 0;
  1398. const char *do_wget = NULL;
  1399. GF_DashSegmenterInput *dash_inputs = NULL;
  1400. u32 nb_dash_inputs = 0;
  1401. char *gf_logs = NULL;
  1402. char *seg_ext = NULL;
  1403. const char *dash_title = NULL;
  1404. const char *dash_source = NULL;
  1405. const char *dash_more_info = NULL;
  1406. #if !defined(GPAC_DISABLE_STREAMING)
  1407. const char *grab_m2ts = NULL;
  1408. #endif
  1409. FILE *logfile = NULL;
  1410. Bool add_ext = 0;
  1411. 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;
  1412. e = GF_OK;
  1413. split_duration = 0.0;
  1414. split_start = -1.0;
  1415. interleaving_time = 0.0;
  1416. dash_duration = dash_subduration = 0.0;
  1417. import_fps = 0;
  1418. import_flags = 0;
  1419. split_size = 0;
  1420. movie_time = 0;
  1421. dump_nal = 0;
  1422. FullInter = HintInter = encode = do_log = old_interleave = do_saf = do_hash = verbose = 0;
  1423. dump_mode = Frag = force_ocr = remove_sys_tracks = agg_samples = remove_hint = keep_sys_tracks = remove_root_od = single_group = 0;
  1424. 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_timestamps = dump_m2ts = dump_cart = import_subtitle = force_cat = pack_wgt = dash_live = 0;
  1425. no_fragments_defaults = 0;
  1426. dash_dynamic = 0;
  1427. /*align cat is the new default behaviour for -cat*/
  1428. align_cat = 1;
  1429. subsegs_per_sidx = 0;
  1430. track_dump_type = 0;
  1431. crypt = 0;
  1432. time_shift_depth = 0;
  1433. file = NULL;
  1434. itunes_tags = pes_dump = NULL;
  1435. seg_name = dash_ctx_file = NULL;
  1436. initial_moof_sn = 0;
  1437. initial_tfdt = 0;
  1438. #ifndef GPAC_DISABLE_SCENE_ENCODER
  1439. memset(&opts, 0, sizeof(opts));
  1440. #endif
  1441. trackID = stat_level = hint_flags = 0;
  1442. program_number = 0;
  1443. info_track_id = 0;
  1444. do_flat = 0;
  1445. inName = outName = mediaSource = input_ctx = output_ctx = drm_file = avi2raw = cprt = chap_file = pack_file = raw_cat = NULL;
  1446. #ifndef GPAC_DISABLE_SWF_IMPORT
  1447. swf_flags = GF_SM_SWF_SPLIT_TIMELINE;
  1448. #endif
  1449. swf_flatten_angle = 0.0f;
  1450. tmpdir = NULL;
  1451. for (i = 1; i < (u32) argc ; i++) {
  1452. if (!strcmp(argv[i], "-mem-track")) {
  1453. #ifdef GPAC_MEMORY_TRACKING
  1454. enable_mem_tracker = 1;
  1455. #else
  1456. fprintf(stderr, "WARNING - GPAC not compiled with Memory Tracker - ignoring \"-mem-track\"\n");
  1457. #endif
  1458. break;
  1459. }
  1460. }
  1461. gf_sys_init(enable_mem_tracker);
  1462. if (argc < 2) {
  1463. PrintUsage();
  1464. MP4BOX_EXIT_WITH_CODE(1);
  1465. }
  1466. /*parse our args*/
  1467. for (i = 1; i < (u32) argc ; i++) {
  1468. arg = argv[i];
  1469. /*input file(s)*/
  1470. if ((arg[0] != '-') || !stricmp(arg, "--")) {
  1471. char *arg_val = arg;
  1472. if (!stricmp(arg, "--")) {
  1473. CHECK_NEXT_ARG
  1474. arg_val = argv[i+1];
  1475. i++;
  1476. }
  1477. if (argc < 3) {
  1478. fprintf(stderr, "Error - only one input file found as argument, please check usage\n");
  1479. MP4BOX_EXIT_WITH_CODE(1);
  1480. } else if (inName) {
  1481. if (dash_duration) {
  1482. if (!nb_dash_inputs) {
  1483. dash_inputs = set_dash_input(dash_inputs, inName, &nb_dash_inputs);
  1484. }
  1485. dash_inputs = set_dash_input(dash_inputs, arg_val, &nb_dash_inputs);
  1486. } else {
  1487. fprintf(stderr, "Error - 2 input names specified, please check usage\n");
  1488. MP4BOX_EXIT_WITH_CODE(1);
  1489. }
  1490. } else {
  1491. inName = arg_val;
  1492. }
  1493. }
  1494. else if (!stricmp(arg, "-?")) { PrintUsage(); MP4BOX_EXIT_WITH_CODE(0); }
  1495. else if (!stricmp(arg, "-version")) { PrintVersion(); MP4BOX_EXIT_WITH_CODE(0); }
  1496. else if (!stricmp(arg, "-sdp")) print_sdp = 1;
  1497. else if (!stricmp(arg, "-quiet")) quiet = 2;
  1498. else if (!strcmp(argv[i], "-mem-track")) continue;
  1499. else if (!stricmp(arg, "-logs")) {
  1500. CHECK_NEXT_ARG
  1501. gf_logs = argv[i+1];
  1502. if (gf_logs)
  1503. gf_log_set_tools_levels(gf_logs);
  1504. i++;
  1505. }
  1506. else if (!strcmp(arg, "-log-file") || !strcmp(arg, "-lf")) {
  1507. logfile = gf_f64_open(argv[i+1], "wt");
  1508. gf_log_set_callback(logfile, on_gpac_log);
  1509. i++;
  1510. }
  1511. else if (!stricmp(arg, "-noprog")) quiet = 1;
  1512. else if (!stricmp(arg, "-info")) {
  1513. print_info = 1;
  1514. if ((i+1<(u32) argc) && (sscanf(argv[i+1], "%u", &info_track_id)==1)) {
  1515. char szTk[20];
  1516. sprintf(szTk, "%u", info_track_id);
  1517. if (!strcmp(szTk, argv[i+1])) i++;
  1518. else info_track_id=0;
  1519. } else {
  1520. info_track_id=0;
  1521. }
  1522. }
  1523. #if !defined(GPAC_DISABLE_STREAMING)
  1524. else if (!stricmp(arg, "-grab-ts")) {
  1525. CHECK_NEXT_ARG
  1526. grab_m2ts = argv[i+1];
  1527. i++;
  1528. }
  1529. #endif
  1530. #if !defined(GPAC_DISABLE_CORE_TOOLS)
  1531. else if (!stricmp(arg, "-wget")) {
  1532. CHECK_NEXT_ARG
  1533. do_wget = argv[i+1];
  1534. i++;
  1535. }
  1536. #endif
  1537. /*******************************************************************************/
  1538. else if (!stricmp(arg, "-dvbhdemux")) {
  1539. dvbhdemux = 1;
  1540. }
  1541. /********************************************************************************/
  1542. #ifndef GPAC_DISABLE_MEDIA_EXPORT
  1543. else if (!stricmp(arg, "-raw")) {
  1544. CHECK_NEXT_ARG
  1545. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_NATIVE);
  1546. i++;
  1547. }
  1548. else if (!stricmp(arg, "-raw-layer")) {
  1549. CHECK_NEXT_ARG
  1550. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_NATIVE | GF_EXPORT_SVC_LAYER);
  1551. i++;
  1552. }
  1553. else if (!stricmp(arg, "-qcp")) {
  1554. CHECK_NEXT_ARG
  1555. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_NATIVE | GF_EXPORT_USE_QCP);
  1556. i++;
  1557. }
  1558. else if (!stricmp(arg, "-aviraw")) {
  1559. CHECK_NEXT_ARG
  1560. if (argv[i+1] && !stricmp(argv[i+1], "video")) trackID = 1;
  1561. else if (argv[i+1] && !stricmp(argv[i+1], "audio")) {
  1562. if (strlen(argv[i+1])==5) trackID = 2;
  1563. else trackID = 1 + atoi(argv[i+1] + 5);
  1564. }
  1565. else { fprintf(stderr, "Usage: \"-aviraw video\" or \"-aviraw audio\"\n"); MP4BOX_EXIT_WITH_CODE(1); }
  1566. track_dump_type = GF_EXPORT_AVI_NATIVE;
  1567. i++;
  1568. }
  1569. else if (!stricmp(arg, "-raws")) {
  1570. CHECK_NEXT_ARG
  1571. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_RAW_SAMPLES);
  1572. i++;
  1573. }
  1574. else if (!stricmp(arg, "-nhnt")) {
  1575. CHECK_NEXT_ARG
  1576. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_NHNT);
  1577. i++;
  1578. }
  1579. else if (!stricmp(arg, "-nhml")) {
  1580. CHECK_NEXT_ARG
  1581. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_NHML);
  1582. i++;
  1583. }
  1584. else if (!stricmp(arg, "-webvtt-raw")) {
  1585. CHECK_NEXT_ARG
  1586. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_WEBVTT_META);
  1587. i++;
  1588. }
  1589. else if (!stricmp(arg, "-six")) {
  1590. CHECK_NEXT_ARG
  1591. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_SIX);
  1592. i++;
  1593. }
  1594. else if (!stricmp(arg, "-avi")) {
  1595. CHECK_NEXT_ARG
  1596. track_dump_type = create_new_track_action(argv[i+1], &tracks, &nb_track_act, GF_EXPORT_AVI);
  1597. i++;
  1598. }
  1599. #endif /*GPAC_DISABLE_MEDIA_EXPORT*/
  1600. #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
  1601. else if (!stricmp(arg, "-rtp")) {
  1602. stream_rtp = 1;
  1603. }
  1604. else if (!stricmp(arg, "-live")) {
  1605. live_scene = 1;
  1606. }
  1607. #endif
  1608. else if (!stricmp(arg, "-diod")) {
  1609. dump_iod = 1;
  1610. }
  1611. #ifndef GPAC_DISABLE_VRML
  1612. else if (!stricmp(arg, "-node")) { CHECK_NEXT_ARG PrintNode(argv[i+1], 0); MP4BOX_EXIT_WITH_CODE(0); }
  1613. else if (!stricmp(arg, "-xnode")) { CHECK_NEXT_ARG PrintNode(argv[i+1], 1); MP4BOX_EXIT_WITH_CODE(0); }
  1614. else if (!stricmp(arg, "-nodes")) { PrintBuiltInNodes(0); MP4BOX_EXIT_WITH_CODE(0); }
  1615. else if (!stricmp(arg, "-xnodes")) { PrintBuiltInNodes(1); MP4BOX_EXIT_WITH_CODE(0); }
  1616. #endif
  1617. #ifndef GPAC_DISABLE_SVG
  1618. else if (!stricmp(arg, "-snode")) { CHECK_NEXT_ARG PrintNode(argv[i+1], 2); MP4BOX_EXIT_WITH_CODE(0); }
  1619. else if (!stricmp(arg, "-snodes")) { PrintBuiltInNodes(2); MP4BOX_EXIT_WITH_CODE(0); }
  1620. #endif
  1621. else if (!stricmp(arg, "-std")) dump_std = 2;
  1622. else if (!stricmp(arg, "-stdb")) dump_std = 1;
  1623. #if !defined(GPAC_DISABLE_MEDIA_EXPORT) && !defined(GPAC_DISABLE_SCENE_DUMP)
  1624. else if (!stricmp(arg, "-bt")) dump_mode = 1 + GF_SM_DUMP_BT;
  1625. else if (!stricmp(arg, "-xmt")) dump_mode = 1 + GF_SM_DUMP_XMTA;
  1626. else if (!stricmp(arg, "-wrl")) dump_mode = 1 + GF_SM_DUMP_VRML;
  1627. else if (!stricmp(arg, "-x3dv")) dump_mode = 1 + GF_SM_DUMP_X3D_VRML;
  1628. else if (!stricmp(arg, "-x3d")) dump_mode = 1 + GF_SM_DUMP_X3D_XML;
  1629. else if (!stricmp(arg, "-lsr")) dump_mode = 1 + GF_SM_DUMP_LASER;
  1630. else if (!stricmp(arg, "-svg")) dump_mode = 1 + GF_SM_DUMP_SVG;
  1631. #endif /*defined(GPAC_DISABLE_MEDIA_EXPORT) && !defined(GPAC_DISABLE_SCENE_DUMP)*/
  1632. else if (!stricmp(arg, "-stat")) stat_level = 1;
  1633. else if (!stricmp(arg, "-stats")) stat_level = 2;
  1634. else if (!stricmp(arg, "-statx")) stat_level = 3;
  1635. else if (!stricmp(arg, "-diso")) dump_isom = 1;
  1636. else if (!stricmp(arg, "-dump-cover")) dump_cart = 1;
  1637. else if (!stricmp(arg, "-dump-chap")) dump_chap = 1;
  1638. else if (!stricmp(arg, "-dump-chap-ogg")) dump_chap = 2;
  1639. else if (!stricmp(arg, "-hash")) do_hash = 1;
  1640. else if (!stricmp(arg, "-dmp4")) {
  1641. dump_isom = 1;
  1642. fprintf(stderr, "WARNING: \"-dmp4\" is deprecated - use \"-diso\" option\n");
  1643. }
  1644. else if (!stricmp(arg, "-drtp")) dump_rtp = 1;
  1645. else if (!stricmp(arg, "-dts")) {
  1646. dump_timestamps = 1;
  1647. if ( ((i+1<(u32) argc) && inName) || (i+2<(u32) argc) ) {
  1648. if (argv[i+1][0] != '-') program_number = atoi(argv[i+1]);
  1649. i++;
  1650. }
  1651. } else if (!stricmp(arg, "-dnal")) {
  1652. CHECK_NEXT_ARG
  1653. dump_nal = atoi(argv[i+1]);
  1654. i++;
  1655. }
  1656. else if (!stricmp(arg, "-dcr")) dump_cr = 1;
  1657. else if (!stricmp(arg, "-ttxt") || !stricmp(arg, "-srt")) {
  1658. if ((i+1<(u32) argc) && (sscanf(argv[i+1], "%u", &trackID)==1)) {
  1659. char szTk[20];
  1660. sprintf(szTk, "%d", trackID);
  1661. if (!strcmp(szTk, argv[i+1])) i++;
  1662. else trackID=0;
  1663. } else {
  1664. trackID = 0;
  1665. }
  1666. #ifdef GPAC_DISABLE_ISOM_WRITE
  1667. if (trackID) { fprintf(stderr, "Error: Read-Only version - subtitle conversion not available\n"); MP4BOX_EXIT_WITH_CODE(1); }
  1668. #endif
  1669. if (!stricmp(arg, "-ttxt")) dump_ttxt = 1;
  1670. else dump_srt = 1;
  1671. import_subtitle = 1;
  1672. } else if (!stricmp(arg, "-dm2ts")) {
  1673. dump_m2ts = 1;
  1674. if ( ((i+1<(u32) argc) && inName) || (i+2<(u32) argc) ) {
  1675. if (argv[i+1][0] != '-') pes_dump = argv[i+1];
  1676. i++;
  1677. }
  1678. }
  1679. #ifndef GPAC_DISABLE_SWF_IMPORT
  1680. /*SWF importer options*/
  1681. else if (!stricmp(arg, "-global")) swf_flags |= GF_SM_SWF_STATIC_DICT;
  1682. else if (!stricmp(arg, "-no-ctrl")) swf_flags &= ~GF_SM_SWF_SPLIT_TIMELINE;
  1683. else if (!stricmp(arg, "-no-text")) swf_flags |= GF_SM_SWF_NO_TEXT;
  1684. else if (!stricmp(arg, "-no-font")) swf_flags |= GF_SM_SWF_NO_FONT;
  1685. else if (!stricmp(arg, "-no-line")) swf_flags |= GF_SM_SWF_NO_LINE;
  1686. else if (!stricmp(arg, "-no-grad")) swf_flags |= GF_SM_SWF_NO_GRADIENT;
  1687. else if (!stricmp(arg, "-quad")) swf_flags |= GF_SM_SWF_QUAD_CURVE;
  1688. else if (!stricmp(arg, "-xlp")) swf_flags |= GF_SM_SWF_SCALABLE_LINE;
  1689. else if (!stricmp(arg, "-ic2d")) swf_flags |= GF_SM_SWF_USE_IC2D;
  1690. else if (!stricmp(arg, "-same-app")) swf_flags |= GF_SM_SWF_REUSE_APPEARANCE;
  1691. else if (!stricmp(arg, "-flatten")) {
  1692. CHECK_NEXT_ARG
  1693. swf_flatten_angle = (Float) atof(argv[i+1]);
  1694. i++;
  1695. }
  1696. #endif
  1697. #ifndef GPAC_DISABLE_ISOM_WRITE
  1698. else if (!stricmp(arg, "-isma")) { conv_type = GF_ISOM_CONV_TYPE_ISMA; open_edit = 1; }
  1699. else if (!stricmp(arg, "-3gp")) { conv_type = GF_ISOM_CONV_TYPE_3GPP; open_edit = 1; }
  1700. else if (!stricmp(arg, "-ipod")) { conv_type = GF_ISOM_CONV_TYPE_IPOD; open_edit = 1; }
  1701. else if (!stricmp(arg, "-psp")) { conv_type = GF_ISOM_CONV_TYPE_PSP; open_edit = 1; }
  1702. else if (!stricmp(arg, "-ismax")) { conv_type = GF_ISOM_CONV_TYPE_ISMA_EX; open_edit = 1; }
  1703. else if (!stricmp(arg, "-no-sys") || !stricmp(arg, "-nosys")) { remove_sys_tracks = 1; open_edit = 1; }
  1704. else if (!stricmp(arg, "-no-iod")) { remove_root_od = 1; open_edit = 1; }
  1705. else if (!stricmp(arg, "-out")) { CHECK_NEXT_ARG outName = argv[i+1]; i++; }
  1706. else if (!stricmp(arg, "-tmp")) {
  1707. CHECK_NEXT_ARG tmpdir = argv[i+1]; i++;
  1708. }
  1709. else if (!stricmp(arg, "-write-buffer")) {
  1710. CHECK_NEXT_ARG
  1711. gf_isom_set_output_buffering(NULL, atoi(argv[i+1]));
  1712. i++;
  1713. }
  1714. else if (!stricmp(arg, "-cprt")) { CHECK_NEXT_ARG cprt = argv[i+1]; i++; if (!dash_duration) open_edit = 1; }
  1715. else if (!stricmp(arg, "-chap")) { CHECK_NEXT_ARG chap_file = argv[i+1]; i++; open_edit = 1; }
  1716. else if (!strcmp(arg, "-strict-error")) {
  1717. gf_log_set_strict_error(1);
  1718. } else if (!stricmp(arg, "-inter") || !stricmp(arg, "-old-inter")) {
  1719. CHECK_NEXT_ARG
  1720. interleaving_time = atof(argv[i+1]) / 1000;
  1721. open_edit = 1;
  1722. needSave = 1;
  1723. if (!stricmp(arg, "-old-inter")) old_interleave = 1;
  1724. i++;
  1725. } else if (!stricmp(arg, "-frag")) {
  1726. CHECK_NEXT_ARG
  1727. interleaving_time = atof(argv[i+1]) / 1000;
  1728. needSave = 1;
  1729. i++;
  1730. Frag = 1;
  1731. } else if (!stricmp(arg, "-dash")) {
  1732. CHECK_NEXT_ARG
  1733. dash_duration = atof(argv[i+1]) / 1000;
  1734. i++;
  1735. } else if (!stricmp(arg, "-subdur")) {
  1736. CHECK_NEXT_ARG
  1737. dash_subduration = atof(argv[i+1]) / 1000;
  1738. i++;
  1739. } else if (!stricmp(arg, "-dash-scale")) {
  1740. CHECK_NEXT_ARG
  1741. dash_scale = atoi(argv[i+1]);
  1742. if (!dash_scale) {
  1743. fprintf(stderr, "\tERROR: \"-dash-scale\": invalid parameter %s\n", argv[i+1]);
  1744. MP4BOX_EXIT_WITH_CODE(1);
  1745. }
  1746. i++;
  1747. } else if (!stricmp(arg, "-dash-ts-prog")) {
  1748. CHECK_NEXT_ARG
  1749. program_number = atoi(argv[i+1]);
  1750. i++;
  1751. } else if (!stricmp(arg, "-subsegs-per-sidx") || !stricmp(arg, "-frags-per-sidx")) {
  1752. CHECK_NEXT_ARG
  1753. subsegs_per_sidx = atoi(argv[i+1]);
  1754. i++;
  1755. } else if (!stricmp(arg, "-segment-name")) {
  1756. CHECK_NEXT_ARG
  1757. seg_name = argv[i+1];
  1758. i++;
  1759. } else if (!stricmp(arg, "-segment-ext")) {
  1760. CHECK_NEXT_ARG
  1761. seg_ext = argv[i+1];
  1762. i++;
  1763. } else if (!stricmp(arg, "-bs-switching")) {
  1764. CHECK_NEXT_ARG
  1765. if (!stricmp(argv[i+1], "no") || !stricmp(argv[i+1], "off")) bitstream_switching_mode = GF_DASH_BSMODE_NONE;
  1766. else if (!stricmp(argv[i+1], "merge")) bitstream_switching_mode = GF_DASH_BSMODE_MERGED;
  1767. else if (!stricmp(argv[i+1], "single")) bitstream_switching_mode = GF_DASH_BSMODE_SINGLE;
  1768. else if (!stricmp(argv[i+1], "inband")) bitstream_switching_mode = GF_DASH_BSMODE_INBAND;
  1769. else bitstream_switching_mode = GF_DASH_BSMODE_INBAND;
  1770. i++;
  1771. }
  1772. else if (!stricmp(arg, "-dynamic")) { dash_dynamic = 1; }
  1773. else if (!strnicmp(arg, "-dash-live", 10) || !strnicmp(arg, "-ddbg-live", 10)) {
  1774. dash_dynamic = !strnicmp(arg, "-ddbg-live", 10) ? 2 : 1;
  1775. dash_live = 1;
  1776. if (arg[10]=='=') {
  1777. dash_ctx_file = arg+11;
  1778. }
  1779. CHECK_NEXT_ARG
  1780. dash_duration = atof(argv[i+1]) / 1000;
  1781. i++;
  1782. }
  1783. else if (!stricmp(arg, "-mpd-refresh")) { CHECK_NEXT_ARG mpd_update_time = atoi(argv[i+1]); i++; }
  1784. else if (!stricmp(arg, "-time-shift")) {
  1785. CHECK_NEXT_ARG
  1786. time_shift_depth = (u32) atoi(argv[i+1]);
  1787. i++;
  1788. }
  1789. else if (!stricmp(arg, "-min-buffer")) {
  1790. CHECK_NEXT_ARG
  1791. min_buffer = atoi(argv[i+1]);
  1792. min_buffer /= 1000;
  1793. i++;
  1794. }
  1795. else if (!stricmp(arg, "-ast-offset")) {
  1796. CHECK_NEXT_ARG
  1797. ast_shift_sec = (u32) atoi(argv[i+1]);
  1798. i++;
  1799. }
  1800. else if (!stricmp(arg, "-moof-sn")) {
  1801. CHECK_NEXT_ARG
  1802. initial_moof_sn = (u32) atoi(argv[i+1]);
  1803. i++;
  1804. }
  1805. else if (!stricmp(arg, "-tfdt")) {
  1806. CHECK_NEXT_ARG
  1807. sscanf(argv[i+1], LLU, &initial_tfdt);
  1808. i++;
  1809. }
  1810. else if (!stricmp(arg, "-no-frags-default")) { no_fragments_defaults = 1; }
  1811. else if (!stricmp(arg, "-mpd-title")) { CHECK_NEXT_ARG dash_title = argv[i+1]; i++; }
  1812. else if (!stricmp(arg, "-mpd-source")) { CHECK_NEXT_ARG dash_source = argv[i+1]; i++; }
  1813. else if (!stricmp(arg, "-mpd-info-url")) { CHECK_NEXT_ARG dash_more_info = argv[i+1]; i++; }
  1814. else if (!stricmp(arg, "-base-url")) {
  1815. CHECK_NEXT_ARG
  1816. dash_more_info = argv[i+1];
  1817. mpd_base_urls = gf_realloc(mpd_base_urls, (nb_mpd_base_urls+1)*sizeof(char**));
  1818. mpd_base_urls[nb_mpd_base_urls] = argv[i+1];
  1819. nb_mpd_base_urls++;
  1820. i++;
  1821. }
  1822. else if (!stricmp(arg, "-dash-ctx")) {
  1823. CHECK_NEXT_ARG
  1824. dash_ctx_file = argv[i+1];
  1825. i++;
  1826. } else if (!stricmp(arg, "-daisy-chain")) {
  1827. daisy_chain_sidx = 1;
  1828. } else if (!stricmp(arg, "-single-segment")) {
  1829. single_segment = 1;
  1830. } else if (!stricmp(arg, "-single-file")) {
  1831. single_file = 1;
  1832. } else if (!stricmp(arg, "-pssh-moof")) {
  1833. pssh_in_moof = 1;
  1834. } else if (!stricmp(arg, "-dash-profile") || !stricmp(arg, "-profile")) {
  1835. CHECK_NEXT_ARG
  1836. if (!stricmp(argv[i+1], "live") || !stricmp(argv[i+1], "simple")) dash_profile = GF_DASH_PROFILE_LIVE;
  1837. else if (!stricmp(argv[i+1], "onDemand")) dash_profile = GF_DASH_PROFILE_ONDEMAND;
  1838. else if (!stricmp(argv[i+1], "main")) dash_profile = GF_DASH_PROFILE_MAIN;
  1839. else dash_profile = GF_DASH_PROFILE_FULL;
  1840. i++;
  1841. } else if (!strnicmp(arg, "-url-template", 13)) {
  1842. use_url_template = 1;
  1843. if ((arg[13]=='=') && arg[14]) {
  1844. if (!strcmp( &arg[14], "simulate")) use_url_template = 2;
  1845. }
  1846. } else if (!stricmp(arg, "-segment-timeline")) {
  1847. segment_timeline = 1;
  1848. } else if (!stricmp(arg, "-mem-frags")) {
  1849. memory_frags = 1;
  1850. } else if (!stricmp(arg, "-segment-marker")) {
  1851. char *m;
  1852. CHECK_NEXT_ARG
  1853. m = argv[i+1];
  1854. segment_marker = GF_4CC(m[0], m[1], m[2], m[3]);
  1855. } else if (!stricmp(arg, "-itags")) { CHECK_NEXT_ARG itunes_tags = argv[i+1]; i++; open_edit = 1; }
  1856. #ifndef GPAC_DISABLE_ISOM_HINTING
  1857. else if (!stricmp(arg, "-hint")) { open_edit = 1; HintIt = 1; }
  1858. else if (!stricmp(arg, "-unhint")) { open_edit = 1; remove_hint = 1; }
  1859. else if (!stricmp(arg, "-copy")) HintCopy = 1;
  1860. else if (!stricmp(arg, "-tight")) {
  1861. FullInter = 1;
  1862. open_edit = 1;
  1863. needSave = 1;
  1864. } else if (!stricmp(arg, "-ocr")) force_ocr = 1;
  1865. else if (!stricmp(arg, "-latm")) hint_flags |= GP_RTP_PCK_USE_LATM_AAC;
  1866. else if (!stricmp(arg, "-rap")) {
  1867. hint_flags |= GP_RTP_PCK_SIGNAL_RAP;
  1868. seg_at_rap=1;
  1869. }
  1870. else if (!stricmp(arg, "-frag-rap")) {
  1871. frag_at_rap=1;
  1872. }
  1873. else if (!stricmp(arg, "-ts")) hint_flags |= GP_RTP_PCK_SIGNAL_TS;
  1874. else if (!stricmp(arg, "-size")) hint_flags |= GP_RTP_PCK_SIGNAL_SIZE;
  1875. else if (!stricmp(arg, "-idx")) hint_flags |= GP_RTP_PCK_SIGNAL_AU_IDX;
  1876. else if (!stricmp(arg, "-static")) hint_flags |= GP_RTP_PCK_USE_STATIC_ID;
  1877. else if (!stricmp(arg, "-multi")) {
  1878. hint_flags |= GP_RTP_PCK_USE_MULTI;
  1879. if ((i+1<(u32) argc) && (sscanf(argv[i+1], "%u", &max_ptime)==1)) {
  1880. char szPt[20];
  1881. sprintf(szPt, "%u", max_ptime);
  1882. if (!strcmp(szPt, argv[i+1])) i++;
  1883. else max_ptime=0;
  1884. }
  1885. }
  1886. #endif
  1887. else if (!stricmp(arg, "-mpeg4")) {
  1888. #ifndef GPAC_DISABLE_ISOM_HINTING
  1889. hint_flags |= GP_RTP_PCK_FORCE_MPEG4;
  1890. #endif
  1891. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  1892. import_flags |= GF_IMPORT_FORCE_MPEG4;
  1893. #endif
  1894. }
  1895. #ifndef GPAC_DISABLE_ISOM_HINTING
  1896. else if (!stricmp(arg, "-mtu")) { CHECK_NEXT_ARG MTUSize = atoi(argv[i+1]); i++; }
  1897. else if (!stricmp(arg, "-cardur")) { CHECK_NEXT_ARG car_dur = atoi(argv[i+1]); i++; }
  1898. else if (!stricmp(arg, "-rate")) { CHECK_NEXT_ARG rtp_rate = atoi(argv[i+1]); i++; }
  1899. #ifndef GPAC_DISABLE_SENG
  1900. else if (!stricmp(arg, "-add-sdp") || !stricmp(arg, "-sdp_ex")) {
  1901. char *id;
  1902. CHECK_NEXT_ARG
  1903. sdp_lines = gf_realloc(sdp_lines, sizeof(SDPLine) * (nb_sdp_ex+1) );
  1904. id = strchr(argv[i+1], ':');
  1905. if (id) {
  1906. id[0] = 0;
  1907. if (sscanf(argv[i+1], "%u", &sdp_lines[0].trackID)==1) {
  1908. id[0] = ':';
  1909. sdp_lines[nb_sdp_ex].line = id+1;
  1910. } else {
  1911. id[0] = ':';
  1912. sdp_lines[nb_sdp_ex].line = argv[i+1];
  1913. sdp_lines[nb_sdp_ex].trackID = 0;
  1914. }
  1915. } else {
  1916. sdp_lines[nb_sdp_ex].line = argv[i+1];
  1917. sdp_lines[nb_sdp_ex].trackID = 0;
  1918. }
  1919. open_edit = 1;
  1920. nb_sdp_ex++;
  1921. i++;
  1922. }
  1923. #endif /*GPAC_DISABLE_SENG*/
  1924. #endif /*GPAC_DISABLE_ISOM_HINTING*/
  1925. else if (!stricmp(arg, "-single")) {
  1926. #ifndef GPAC_DISABLE_MEDIA_EXPORT
  1927. CHECK_NEXT_ARG
  1928. track_dump_type = GF_EXPORT_MP4;
  1929. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  1930. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  1931. tracks[nb_track_act].act_type = 9;
  1932. tracks[nb_track_act].trackID = atoi(argv[i+1]);
  1933. tracks[nb_track_act].dump_type = GF_EXPORT_MP4;
  1934. nb_track_act++;
  1935. i++;
  1936. #endif
  1937. }
  1938. else if (!stricmp(arg, "-iod")) regular_iod = 1;
  1939. else if (!stricmp(arg, "-flat")) do_flat = 1;
  1940. else if (!stricmp(arg, "-keep-utc")) keep_utc = 1;
  1941. else if (!stricmp(arg, "-new")) force_new = 1;
  1942. else if (!stricmp(arg, "-add") || !stricmp(arg, "-import") || !stricmp(arg, "-convert")) {
  1943. CHECK_NEXT_ARG
  1944. if (!stricmp(arg, "-import")) fprintf(stderr, "\tWARNING: \"-import\" is deprecated - use \"-add\"\n");
  1945. else if (!stricmp(arg, "-convert")) fprintf(stderr, "\tWARNING: \"-convert\" is deprecated - use \"-add\"\n");
  1946. nb_add++;
  1947. i++;
  1948. }
  1949. else if (!stricmp(arg, "-cat") || !stricmp(arg, "-catx")) {
  1950. CHECK_NEXT_ARG
  1951. nb_cat++;
  1952. i++;
  1953. }
  1954. else if (!stricmp(arg, "-time")) {
  1955. struct tm time;
  1956. CHECK_NEXT_ARG
  1957. memset(&time, 0, sizeof(struct tm));
  1958. sscanf(argv[i+1], "%d/%d/%d-%d:%d:%d", &time.tm_mday, &time.tm_mon, &time.tm_year, &time.tm_hour, &time.tm_min, &time.tm_sec);
  1959. time.tm_isdst=0;
  1960. time.tm_year -= 1900;
  1961. time.tm_mon -= 1;
  1962. open_edit = 1;
  1963. movie_time = 2082758400;
  1964. movie_time += mktime(&time);
  1965. i++;
  1966. }
  1967. else if (!stricmp(arg, "-force-cat")) force_cat = 1;
  1968. else if (!stricmp(arg, "-align-cat")) align_cat = 1;
  1969. else if (!stricmp(arg, "-unalign-cat")) align_cat = 0;
  1970. else if (!stricmp(arg, "-raw-cat")) {
  1971. CHECK_NEXT_ARG
  1972. raw_cat = argv[i+1];
  1973. i++;
  1974. }
  1975. else if (!stricmp(arg, "-rem") || !stricmp(arg, "-disable") || !stricmp(arg, "-enable")) {
  1976. CHECK_NEXT_ARG
  1977. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  1978. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  1979. if (!stricmp(arg, "-enable")) tracks[nb_track_act].act_type = 6;
  1980. else if (!stricmp(arg, "-disable")) tracks[nb_track_act].act_type = 7;
  1981. else tracks[nb_track_act].act_type = 0;
  1982. tracks[nb_track_act].trackID = atoi(argv[i+1]);
  1983. open_edit = 1;
  1984. nb_track_act++;
  1985. i++;
  1986. }
  1987. else if (!stricmp(arg, "-par")) {
  1988. char szTK[20], *ext;
  1989. CHECK_NEXT_ARG
  1990. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  1991. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  1992. tracks[nb_track_act].act_type = 4;
  1993. assert(strlen(argv[i+1])+1 <= sizeof(szTK));
  1994. strncpy(szTK, argv[i+1], sizeof(szTK));
  1995. ext = strchr(szTK, '=');
  1996. if (!ext) {
  1997. fprintf(stderr, "Bad format for track par - expecting ID=PAR_NUM:PAR_DEN got %s\n", argv[i+1]);
  1998. MP4BOX_EXIT_WITH_CODE(1);
  1999. }
  2000. if (!stricmp(ext+1, "none")) {
  2001. tracks[nb_track_act].par_num = tracks[nb_track_act].par_den = -1;
  2002. } else {
  2003. sscanf(ext+1, "%d", &tracks[nb_track_act].par_num);
  2004. ext = strchr(ext+1, ':');
  2005. if (!ext) {
  2006. fprintf(stderr, "Bad format for track par - expecting ID=PAR_NUM:PAR_DEN got %s\n", argv[i+1]);
  2007. MP4BOX_EXIT_WITH_CODE(1);
  2008. }
  2009. sscanf(ext+1, "%d", &tracks[nb_track_act].par_den);
  2010. }
  2011. ext[0] = 0;
  2012. tracks[nb_track_act].trackID = atoi(szTK);
  2013. open_edit = 1;
  2014. nb_track_act++;
  2015. i++;
  2016. }
  2017. else if (!stricmp(arg, "-lang")) {
  2018. char szTK[20], *ext;
  2019. CHECK_NEXT_ARG
  2020. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  2021. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  2022. tracks[nb_track_act].act_type = 1;
  2023. tracks[nb_track_act].lang[3] = 0;
  2024. tracks[nb_track_act].trackID = 0;
  2025. strcpy(szTK, argv[i+1]);
  2026. ext = strchr(szTK, '=');
  2027. if (!strnicmp(argv[i+1], "all=", 4)) {
  2028. strncpy(tracks[nb_track_act].lang, argv[i+1]+1, 3);
  2029. } else if (!ext) {
  2030. strncpy(tracks[nb_track_act].lang, argv[i+1], 3);
  2031. } else {
  2032. strncpy(tracks[nb_track_act].lang, ext+1, 3);
  2033. ext[0] = 0;
  2034. tracks[nb_track_act].trackID = atoi(szTK);
  2035. ext[0] = '=';
  2036. }
  2037. open_edit = 1;
  2038. nb_track_act++;
  2039. i++;
  2040. }
  2041. else if (!stricmp(arg, "-delay")) {
  2042. char szTK[20], *ext;
  2043. CHECK_NEXT_ARG
  2044. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  2045. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  2046. strcpy(szTK, argv[i+1]);
  2047. ext = strchr(szTK, '=');
  2048. if (!ext) {
  2049. fprintf(stderr, "Bad format for track delay - expecting ID=DLAY got %s\n", argv[i+1]);
  2050. MP4BOX_EXIT_WITH_CODE(1);
  2051. }
  2052. tracks[nb_track_act].act_type = 2;
  2053. tracks[nb_track_act].delay_ms = atoi(ext+1);
  2054. ext[0] = 0;
  2055. tracks[nb_track_act].trackID = atoi(szTK);
  2056. open_edit = 1;
  2057. nb_track_act++;
  2058. i++;
  2059. }
  2060. else if (!stricmp(arg, "-ref")) {
  2061. char *szTK, *ext;
  2062. CHECK_NEXT_ARG
  2063. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  2064. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  2065. szTK = argv[i+1];
  2066. ext = strchr(szTK, ':');
  2067. if (!ext) {
  2068. fprintf(stderr, "Bad format for track reference - expecting ID:XXXX:refID got %s\n", argv[i+1]);
  2069. MP4BOX_EXIT_WITH_CODE(1);
  2070. }
  2071. tracks[nb_track_act].act_type = 8;
  2072. ext[0] = 0; tracks[nb_track_act].trackID = atoi(szTK); ext[0] = ':'; szTK = ext+1;
  2073. ext = strchr(szTK, ':');
  2074. if (!ext) {
  2075. fprintf(stderr, "Bad format for track reference - expecting ID:XXXX:refID got %s\n", argv[i+1]);
  2076. MP4BOX_EXIT_WITH_CODE(1);
  2077. }
  2078. ext[0] = 0;
  2079. strncpy(tracks[nb_track_act].lang, szTK, 4);
  2080. ext[0] = ':';
  2081. tracks[nb_track_act].delay_ms = (s32) atoi(ext+1);
  2082. open_edit = 1;
  2083. nb_track_act++;
  2084. i++;
  2085. }
  2086. else if (!stricmp(arg, "-name")) {
  2087. char szTK[GF_MAX_PATH], *ext;
  2088. CHECK_NEXT_ARG
  2089. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  2090. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  2091. strcpy(szTK, argv[i+1]);
  2092. ext = strchr(szTK, '=');
  2093. if (!ext) {
  2094. fprintf(stderr, "Bad format for track name - expecting ID=name got %s\n", argv[i+1]);
  2095. MP4BOX_EXIT_WITH_CODE(1);
  2096. }
  2097. tracks[nb_track_act].act_type = 5;
  2098. tracks[nb_track_act].hdl_name = strchr(argv[i+1], '=') + 1;
  2099. ext[0] = 0;
  2100. tracks[nb_track_act].trackID = atoi(szTK);
  2101. ext[0] = '=';
  2102. open_edit = 1;
  2103. nb_track_act++;
  2104. i++;
  2105. }
  2106. #if !defined(GPAC_DISABLE_MEDIA_EXPORT) && !defined(GPAC_DISABLE_MEDIA_IMPORT)
  2107. else if (!stricmp(arg, "-dref")) import_flags |= GF_IMPORT_USE_DATAREF;
  2108. else if (!stricmp(arg, "-no-drop") || !stricmp(arg, "-nodrop")) import_flags |= GF_IMPORT_NO_FRAME_DROP;
  2109. else if (!stricmp(arg, "-packed")) import_flags |= GF_IMPORT_FORCE_PACKED;
  2110. else if (!stricmp(arg, "-sbr")) import_flags |= GF_IMPORT_SBR_IMPLICIT;
  2111. else if (!stricmp(arg, "-sbrx")) import_flags |= GF_IMPORT_SBR_EXPLICIT;
  2112. else if (!stricmp(arg, "-ps")) import_flags |= GF_IMPORT_PS_IMPLICIT;
  2113. else if (!stricmp(arg, "-psx")) import_flags |= GF_IMPORT_PS_EXPLICIT;
  2114. else if (!stricmp(arg, "-ovsbr")) import_flags |= GF_IMPORT_OVSBR;
  2115. else if (!stricmp(arg, "-fps")) {
  2116. CHECK_NEXT_ARG
  2117. if (!strcmp(argv[i+1], "auto")) import_fps = GF_IMPORT_AUTO_FPS;
  2118. else if (strchr(argv[i+1], '-')) {
  2119. u32 ticks, dts_inc;
  2120. sscanf(argv[i+1], "%u-%u", &ticks, &dts_inc);
  2121. if (!dts_inc) dts_inc=1;
  2122. import_fps = ticks;
  2123. import_fps /= dts_inc;
  2124. } else import_fps = atof(argv[i+1]);
  2125. i++;
  2126. }
  2127. else if (!stricmp(arg, "-agg")) { CHECK_NEXT_ARG agg_samples = atoi(argv[i+1]); i++; }
  2128. else if (!stricmp(arg, "-keep-all") || !stricmp(arg, "-keepall")) import_flags |= GF_IMPORT_KEEP_ALL_TRACKS;
  2129. #endif /*!defined(GPAC_DISABLE_MEDIA_EXPORT) && !defined(GPAC_DISABLE_MEDIA_IMPORT*/
  2130. else if (!stricmp(arg, "-keep-sys") || !stricmp(arg, "-keepsys")) keep_sys_tracks = 1;
  2131. else if (!stricmp(arg, "-ms")) { CHECK_NEXT_ARG mediaSource = argv[i+1]; i++; }
  2132. else if (!stricmp(arg, "-mp4")) { encode = 1; open_edit = 1; }
  2133. else if (!stricmp(arg, "-saf")) { do_saf = 1; }
  2134. else if (!stricmp(arg, "-log")) { do_log = 1; }
  2135. #ifndef GPAC_DISABLE_MPD
  2136. else if (!stricmp(arg, "-mpd")) {
  2137. do_mpd = 1;
  2138. CHECK_NEXT_ARG
  2139. outName = argv[i+1];
  2140. i++;
  2141. }
  2142. #endif
  2143. #ifndef GPAC_DISABLE_SCENE_ENCODER
  2144. else if (!stricmp(arg, "-def")) opts.flags |= GF_SM_ENCODE_USE_NAMES;
  2145. else if (!stricmp(arg, "-sync")) {
  2146. CHECK_NEXT_ARG
  2147. opts.flags |= GF_SM_ENCODE_RAP_INBAND;
  2148. opts.rap_freq = atoi(argv[i+1]);
  2149. i++;
  2150. } else if (!stricmp(arg, "-shadow")) {
  2151. CHECK_NEXT_ARG
  2152. opts.flags &= ~GF_SM_ENCODE_RAP_INBAND;
  2153. opts.flags |= GF_SM_ENCODE_RAP_SHADOW;
  2154. opts.rap_freq = atoi(argv[i+1]);
  2155. i++;
  2156. } else if (!stricmp(arg, "-carousel")) {
  2157. CHECK_NEXT_ARG
  2158. opts.flags &= ~(GF_SM_ENCODE_RAP_INBAND | GF_SM_ENCODE_RAP_SHADOW);
  2159. opts.rap_freq = atoi(argv[i+1]);
  2160. i++;
  2161. }
  2162. /*LASeR options*/
  2163. else if (!stricmp(arg, "-resolution")) {
  2164. CHECK_NEXT_ARG
  2165. opts.resolution = atoi(argv[i+1]);
  2166. i++;
  2167. }
  2168. #ifndef GPAC_DISABLE_SCENE_STATS
  2169. else if (!stricmp(arg, "-auto-quant")) {
  2170. CHECK_NEXT_ARG
  2171. opts.resolution = atoi(argv[i+1]);
  2172. opts.auto_quant = 1;
  2173. i++;
  2174. }
  2175. #endif
  2176. else if (!stricmp(arg, "-coord-bits")) {
  2177. CHECK_NEXT_ARG
  2178. opts.coord_bits = atoi(argv[i+1]);
  2179. i++;
  2180. }
  2181. else if (!stricmp(arg, "-scale-bits")) {
  2182. CHECK_NEXT_ARG
  2183. opts.scale_bits = atoi(argv[i+1]);
  2184. i++;
  2185. }
  2186. else if (!stricmp(arg, "-global-quant")) {
  2187. CHECK_NEXT_ARG
  2188. opts.resolution = atoi(argv[i+1]);
  2189. opts.auto_quant = 2;
  2190. i++;
  2191. }
  2192. /*chunk encoding*/
  2193. else if (!stricmp(arg, "-ctx-out") || !stricmp(arg, "-outctx")) { CHECK_NEXT_ARG output_ctx = argv[i+1]; i++; }
  2194. else if (!stricmp(arg, "-ctx-in") || !stricmp(arg, "-inctx")) {
  2195. CHECK_NEXT_ARG
  2196. chunk_mode = 1;
  2197. input_ctx = argv[i+1];
  2198. i++;
  2199. }
  2200. #endif /*GPAC_DISABLE_SCENE_ENCODER*/
  2201. else if (!strcmp(arg, "-crypt")) {
  2202. CHECK_NEXT_ARG
  2203. crypt = 1;
  2204. drm_file = argv[i+1];
  2205. open_edit = 1;
  2206. i += 1;
  2207. }
  2208. else if (!strcmp(arg, "-decrypt")) {
  2209. CHECK_NEXT_ARG
  2210. crypt = 2;
  2211. if (get_file_type_by_ext(argv[i+1])!=1) {
  2212. drm_file = argv[i+1];
  2213. i += 1;
  2214. }
  2215. open_edit = 1;
  2216. }
  2217. else if (!stricmp(arg, "-set-kms")) {
  2218. char szTK[20], *ext;
  2219. CHECK_NEXT_ARG
  2220. tracks = gf_realloc(tracks, sizeof(TrackAction) * (nb_track_act+1));
  2221. memset(&tracks[nb_track_act], 0, sizeof(TrackAction) );
  2222. strncpy(szTK, argv[i+1], 19);
  2223. ext = strchr(szTK, '=');
  2224. tracks[nb_track_act].act_type = 3;
  2225. tracks[nb_track_act].trackID = 0;
  2226. if (!strnicmp(argv[i+1], "all=", 4)) {
  2227. tracks[nb_track_act].kms = argv[i+1] + 4;
  2228. } else if (!ext) {
  2229. tracks[nb_track_act].kms = argv[i+1];
  2230. } else {
  2231. tracks[nb_track_act].kms = ext+1;
  2232. ext[0] = 0;
  2233. tracks[nb_track_act].trackID = atoi(szTK);
  2234. ext[0] = '=';
  2235. }
  2236. open_edit = 1;
  2237. nb_track_act++;
  2238. i++;
  2239. }
  2240. else if (!stricmp(arg, "-split")) {
  2241. CHECK_NEXT_ARG
  2242. split_duration = atof(argv[i+1]);
  2243. if (split_duration<0) split_duration=0;;
  2244. i++;
  2245. split_size = 0;
  2246. }
  2247. else if (!stricmp(arg, "-split-rap") || !stricmp(arg, "-splitr")) {
  2248. CHECK_NEXT_ARG
  2249. split_duration = -1;
  2250. split_size = -1;
  2251. }
  2252. else if (!stricmp(arg, "-split-size") || !stricmp(arg, "-splits")) {
  2253. CHECK_NEXT_ARG
  2254. split_size = atoi(argv[i+1]);
  2255. if (split_size<0) split_size = 0;
  2256. i++;
  2257. split_duration = 0;
  2258. }
  2259. else if (!stricmp(arg, "-split-chunk") || !stricmp(arg, "-splitx") || !stricmp(arg, "-splitz")) {
  2260. CHECK_NEXT_ARG
  2261. if (!strstr(argv[i+1], ":")) {
  2262. fprintf(stderr, "Chunk extraction usage: \"-splitx start:end\" expressed in seconds\n");
  2263. MP4BOX_EXIT_WITH_CODE(1);
  2264. }
  2265. if (strstr(argv[i+1], "end")) {
  2266. sscanf(argv[i+1], "%lf:end", &split_start);
  2267. split_duration = -2;
  2268. } else {
  2269. sscanf(argv[i+1], "%lf:%lf", &split_start, &split_duration);
  2270. split_duration -= split_start;
  2271. }
  2272. split_size = 0;
  2273. if (!stricmp(arg, "-splitz")) adjust_split_end = 1;
  2274. i++;
  2275. }
  2276. /*meta*/
  2277. else if (!stricmp(arg, "-set-meta")) {
  2278. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2279. metas[nb_meta_act].act_type = 0;
  2280. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2281. nb_meta_act++;
  2282. open_edit = 1;
  2283. i++;
  2284. }
  2285. else if (!stricmp(arg, "-add-item")) {
  2286. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2287. metas[nb_meta_act].act_type = 1;
  2288. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2289. nb_meta_act++;
  2290. open_edit = 1;
  2291. i++;
  2292. }
  2293. else if (!stricmp(arg, "-rem-item")) {
  2294. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2295. metas[nb_meta_act].act_type = 2;
  2296. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2297. nb_meta_act++;
  2298. open_edit = 1;
  2299. i++;
  2300. }
  2301. else if (!stricmp(arg, "-set-primary")) {
  2302. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2303. metas[nb_meta_act].act_type = 3;
  2304. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2305. nb_meta_act++;
  2306. open_edit = 1;
  2307. i++;
  2308. }
  2309. else if (!stricmp(arg, "-set-xml")) {
  2310. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2311. metas[nb_meta_act].act_type = 4;
  2312. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2313. nb_meta_act++;
  2314. open_edit = 1;
  2315. i++;
  2316. }
  2317. else if (!stricmp(arg, "-rem-xml")) {
  2318. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2319. metas[nb_meta_act].act_type = 6;
  2320. if (parse_meta_args(&metas[nb_meta_act], argv[i+1])) i++;
  2321. nb_meta_act++;
  2322. open_edit = 1;
  2323. }
  2324. else if (!stricmp(arg, "-dump-xml")) {
  2325. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2326. metas[nb_meta_act].act_type = 7;
  2327. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2328. nb_meta_act++;
  2329. i++;
  2330. }
  2331. else if (!stricmp(arg, "-dump-item")) {
  2332. metas = gf_realloc(metas, sizeof(MetaAction) * (nb_meta_act+1));
  2333. metas[nb_meta_act].act_type = 8;
  2334. parse_meta_args(&metas[nb_meta_act], argv[i+1]);
  2335. nb_meta_act++;
  2336. i++;
  2337. }
  2338. else if (!stricmp(arg, "-group-add") || !stricmp(arg, "-group-rem-track") || !stricmp(arg, "-group-rem")) {
  2339. tsel_acts[nb_tsel_acts].act_type = !stricmp(arg, "-group-rem") ? 2 : ( !stricmp(arg, "-group-rem-track") ? 1 : 0 );
  2340. if (parse_tsel_args(&tsel_acts, argv[i+1], &nb_tsel_acts)==0) {
  2341. fprintf(stderr, "Invalid group syntax - check usage\n");
  2342. MP4BOX_EXIT_WITH_CODE(1);
  2343. }
  2344. open_edit=1;
  2345. i++;
  2346. }
  2347. else if (!stricmp(arg, "-group-clean")) {
  2348. tsel_acts[nb_tsel_acts].act_type = 3;
  2349. nb_tsel_acts++;
  2350. open_edit=1;
  2351. }
  2352. else if (!stricmp(arg, "-group-single")) {
  2353. single_group = 1;
  2354. }
  2355. else if (!stricmp(arg, "-package")) {
  2356. CHECK_NEXT_ARG
  2357. pack_file = argv[i+1];
  2358. i++;
  2359. }
  2360. else if (!stricmp(arg, "-mgt")) {
  2361. CHECK_NEXT_ARG
  2362. pack_file = argv[i+1];
  2363. pack_wgt = 1;
  2364. i++;
  2365. }
  2366. else if (!stricmp(arg, "-brand")) {
  2367. char *b = argv[i+1];
  2368. CHECK_NEXT_ARG
  2369. major_brand = GF_4CC(b[0], b[1], b[2], b[3]);
  2370. open_edit = 1;
  2371. if (b[4]==':') minor_version = atoi(b+5);
  2372. i++;
  2373. }
  2374. else if (!stricmp(arg, "-ab")) {
  2375. char *b = argv[i+1];
  2376. CHECK_NEXT_ARG
  2377. brand_add = gf_realloc(brand_add, sizeof(u32) * (nb_alt_brand_add+1));
  2378. brand_add[nb_alt_brand_add] = GF_4CC(b[0], b[1], b[2], b[3]);
  2379. nb_alt_brand_add++;
  2380. open_edit = 1;
  2381. i++;
  2382. }
  2383. else if (!stricmp(arg, "-rb")) {
  2384. char *b = argv[i+1];
  2385. CHECK_NEXT_ARG
  2386. brand_rem = gf_realloc(brand_rem, sizeof(u32) * (nb_alt_brand_rem+1));
  2387. brand_rem[nb_alt_brand_rem] = GF_4CC(b[0], b[1], b[2], b[3]);
  2388. nb_alt_brand_rem++;
  2389. open_edit = 1;
  2390. i++;
  2391. }
  2392. #endif
  2393. else if (!stricmp(arg, "-languages")) {
  2394. PrintLanguages();
  2395. MP4BOX_EXIT_WITH_CODE(0);
  2396. }
  2397. else if (!stricmp(arg, "-h")) {
  2398. if (i+1== (u32) argc) PrintUsage();
  2399. else if (!strcmp(argv[i+1], "general")) PrintGeneralUsage();
  2400. else if (!strcmp(argv[i+1], "extract")) PrintExtractUsage();
  2401. else if (!strcmp(argv[i+1], "dash")) PrintDASHUsage();
  2402. else if (!strcmp(argv[i+1], "dump")) PrintDumpUsage();
  2403. else if (!strcmp(argv[i+1], "import")) PrintImportUsage();
  2404. else if (!strcmp(argv[i+1], "format")) PrintFormats();
  2405. else if (!strcmp(argv[i+1], "hint")) PrintHintUsage();
  2406. else if (!strcmp(argv[i+1], "encode")) PrintEncodeUsage();
  2407. else if (!strcmp(argv[i+1], "crypt")) PrintEncryptUsage();
  2408. else if (!strcmp(argv[i+1], "meta")) PrintMetaUsage();
  2409. else if (!strcmp(argv[i+1], "swf")) PrintSWFUsage();
  2410. #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
  2411. else if (!strcmp(argv[i+1], "rtp")) PrintStreamerUsage();
  2412. else if (!strcmp(argv[i+1], "live")) PrintLiveUsage ();
  2413. #endif
  2414. else if (!strcmp(argv[i+1], "all")) {
  2415. PrintGeneralUsage();
  2416. PrintExtractUsage();
  2417. PrintDASHUsage();
  2418. PrintDumpUsage();
  2419. PrintImportUsage();
  2420. PrintFormats();
  2421. PrintHintUsage();
  2422. PrintEncodeUsage();
  2423. PrintEncryptUsage();
  2424. PrintMetaUsage();
  2425. PrintSWFUsage();
  2426. #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
  2427. PrintStreamerUsage();
  2428. PrintLiveUsage ();
  2429. #endif
  2430. }
  2431. else PrintUsage();
  2432. MP4BOX_EXIT_WITH_CODE(0);
  2433. }
  2434. else if (!stricmp(arg, "-v")) verbose++;
  2435. else if (!stricmp(arg, "-tag-list")) {
  2436. fprintf(stderr, "Supported iTunes tag modifiers:\n");
  2437. for (i=0; i<nb_itunes_tags; i++) {
  2438. fprintf(stderr, "\t%s\t%s\n", itags[i].name, itags[i].comment);
  2439. }
  2440. MP4BOX_EXIT_WITH_CODE(0);
  2441. } else if (!live_scene && !stream_rtp) {
  2442. fprintf(stderr, "Option %s unknown. Please check usage\n", arg);
  2443. MP4BOX_EXIT_WITH_CODE(1);
  2444. }
  2445. }
  2446. if (!inName && dump_std)
  2447. inName = "std";
  2448. if (!inName) {
  2449. PrintUsage();
  2450. MP4BOX_EXIT_WITH_CODE(1);
  2451. }
  2452. if (!strcmp(inName, "std")) dump_std = 2;
  2453. if (!strcmp(inName, "stdb")) {
  2454. inName = "std";
  2455. dump_std = 1;
  2456. }
  2457. if (!interleaving_time) {
  2458. /*by default use single fragment per dash segment*/
  2459. if (dash_duration)
  2460. interleaving_time = dash_duration;
  2461. else
  2462. interleaving_time = 0.5;
  2463. }
  2464. if (dump_std)
  2465. outName = "std";
  2466. if (dump_std==2) {
  2467. #ifdef WIN32
  2468. if ( _setmode(_fileno(stdout), _O_BINARY) == -1 )
  2469. #else
  2470. if ( freopen(NULL, "wb", stdout) == NULL)
  2471. #endif
  2472. {
  2473. fprintf(stderr, "Fatal error: cannot reopen stdout in binary mode.\n");
  2474. MP4BOX_EXIT_WITH_CODE(1);
  2475. }
  2476. }
  2477. #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)
  2478. if (live_scene) {
  2479. int ret = live_session(argc, argv);
  2480. MP4BOX_EXIT_WITH_CODE(ret);
  2481. }
  2482. if (stream_rtp) {
  2483. int ret = stream_file_rtp(argc, argv);
  2484. MP4BOX_EXIT_WITH_CODE(ret);
  2485. }
  2486. #endif
  2487. if (raw_cat) {
  2488. char chunk[4096];
  2489. FILE *fin, *fout;
  2490. s64 to_copy, done;
  2491. fin = gf_f64_open(raw_cat, "rb");
  2492. if (!fin) MP4BOX_EXIT_WITH_CODE(1);
  2493. fout = gf_f64_open(inName, "a+b");
  2494. if (!fout) {
  2495. fclose(fin);
  2496. MP4BOX_EXIT_WITH_CODE(1);
  2497. }
  2498. gf_f64_seek(fin, 0, SEEK_END);
  2499. to_copy = gf_f64_tell(fin);
  2500. gf_f64_seek(fin, 0, SEEK_SET);
  2501. done = 0;
  2502. while (1) {
  2503. u32 nb_bytes = (u32) fread(chunk, 1, 4096, fin);
  2504. gf_fwrite(chunk, 1, nb_bytes, fout);
  2505. done += nb_bytes;
  2506. fprintf(stderr, "Appending file %s - %02.2f done\r", raw_cat, 100.0*done/to_copy);
  2507. if (done >= to_copy) break;
  2508. }
  2509. fclose(fin);
  2510. fclose(fout);
  2511. MP4BOX_EXIT_WITH_CODE(0);
  2512. }
  2513. #if !defined(GPAC_DISABLE_STREAMING)
  2514. if (grab_m2ts) {
  2515. return grab_live_m2ts(grab_m2ts, inName);
  2516. }
  2517. #endif
  2518. /*init libgpac*/
  2519. if (enable_mem_tracker) {
  2520. gf_sys_close();
  2521. gf_sys_init(enable_mem_tracker);
  2522. }
  2523. if (gf_logs) {
  2524. //gf_log_set_tools_levels(gf_logs);
  2525. } else {
  2526. u32 level = verbose ? GF_LOG_DEBUG : GF_LOG_INFO;
  2527. gf_log_set_tool_level(GF_LOG_CONTAINER, level);
  2528. gf_log_set_tool_level(GF_LOG_SCENE, level);
  2529. gf_log_set_tool_level(GF_LOG_PARSER, level);
  2530. gf_log_set_tool_level(GF_LOG_AUTHOR, level);
  2531. gf_log_set_tool_level(GF_LOG_CODING, level);
  2532. #ifdef GPAC_MEMORY_TRACKING
  2533. if (enable_mem_tracker)
  2534. gf_log_set_tool_level(GF_LOG_MEMORY, level);
  2535. #endif
  2536. if (quiet) {
  2537. if (quiet==2) gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_QUIET);
  2538. gf_set_progress_callback(NULL, progress_quiet);
  2539. }
  2540. }
  2541. #if !defined(DISABLE_CORE_TOOLS)
  2542. if (do_wget != NULL) {
  2543. e = gf_dm_wget(do_wget, inName, 0, 0);
  2544. if (e != GF_OK) {
  2545. fprintf(stderr, "Cannot retrieve %s: %s\n", do_wget, gf_error_to_string(e) );
  2546. }
  2547. MP4BOX_EXIT_WITH_CODE(1);
  2548. }
  2549. #endif
  2550. #ifndef GPAC_DISABLE_MPD
  2551. if (do_mpd) {
  2552. Bool remote = 0;
  2553. char *mpd_base_url = gf_strdup(inName);
  2554. if (!strnicmp(inName, "http://", 7)) {
  2555. #if !defined(GPAC_DISABLE_CORE_TOOLS)
  2556. e = gf_dm_wget(inName, "tmp_main.m3u8", 0, 0);
  2557. if (e != GF_OK) {
  2558. fprintf(stderr, "Cannot retrieve M3U8 (%s): %s\n", inName, gf_error_to_string(e));
  2559. gf_free(mpd_base_url);
  2560. MP4BOX_EXIT_WITH_CODE(1);
  2561. }
  2562. inName = "tmp_main.m3u8";
  2563. remote = 1;
  2564. #else
  2565. fprintf(stderr, "HTTP Downloader disabled in this build\n");
  2566. MP4BOX_EXIT_WITH_CODE(1);
  2567. #endif
  2568. }
  2569. e = gf_m3u8_to_mpd(inName, mpd_base_url, (outName ? outName : inName), 0, "video/mp2t", 1, use_url_template, NULL);
  2570. gf_free(mpd_base_url);
  2571. if (remote) {
  2572. //gf_delete_file("tmp_main.m3u8");
  2573. }
  2574. if (e != GF_OK) {
  2575. fprintf(stderr, "Error converting M3U8 (%s) to MPD (%s): %s\n", inName, outName, gf_error_to_string(e));
  2576. MP4BOX_EXIT_WITH_CODE(1);
  2577. } else {
  2578. fprintf(stderr, "Done converting M3U8 (%s) to MPD (%s)\n", inName, outName);
  2579. MP4BOX_EXIT_WITH_CODE(0);
  2580. }
  2581. }
  2582. #endif
  2583. if (dash_duration && !nb_dash_inputs) {
  2584. dash_inputs = set_dash_input(dash_inputs, inName, &nb_dash_inputs);
  2585. }
  2586. if (do_saf && !encode) {
  2587. switch (get_file_type_by_ext(inName)) {
  2588. case 2: case 3: case 4:
  2589. encode = 1;
  2590. break;
  2591. }
  2592. }
  2593. #ifndef GPAC_DISABLE_SCENE_DUMP
  2594. if (dump_mode == 1 + GF_SM_DUMP_SVG) {
  2595. if (strstr(inName, ".srt") || strstr(inName, ".ttxt")) import_subtitle = 2;
  2596. }
  2597. #endif
  2598. if (import_subtitle && !trackID) {
  2599. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  2600. GF_MediaImporter import;
  2601. file = gf_isom_open("ttxt_convert", GF_ISOM_OPEN_WRITE, NULL);
  2602. memset(&import, 0, sizeof(GF_MediaImporter));
  2603. import.dest = file;
  2604. import.in_name = inName;
  2605. e = gf_media_import(&import);
  2606. if (e) {
  2607. fprintf(stderr, "Error importing %s: %s\n", inName, gf_error_to_string(e));
  2608. gf_isom_delete(file);
  2609. gf_delete_file("ttxt_convert");
  2610. MP4BOX_EXIT_WITH_CODE(1);
  2611. }
  2612. strcpy(outfile, outName ? outName : inName);
  2613. if (strchr(split_file_name(outfile), '.')) {
  2614. while (outfile[strlen(outfile)-1] != '.') outfile[strlen(outfile)-1] = 0;
  2615. outfile[strlen(outfile)-1] = 0;
  2616. }
  2617. #ifndef GPAC_DISABLE_ISOM_DUMP
  2618. dump_timed_text_track(file, gf_isom_get_track_id(file, 1), dump_std ? NULL : outfile, 1, (import_subtitle==2) ? 2 : dump_srt);
  2619. #endif
  2620. gf_isom_delete(file);
  2621. gf_delete_file("ttxt_convert");
  2622. if (e) {
  2623. fprintf(stderr, "Error converting %s: %s\n", inName, gf_error_to_string(e));
  2624. MP4BOX_EXIT_WITH_CODE(1);
  2625. }
  2626. MP4BOX_EXIT_WITH_CODE(0);
  2627. #else
  2628. fprintf(stderr, "Feature not supported\n");
  2629. MP4BOX_EXIT_WITH_CODE(1);
  2630. #endif
  2631. }
  2632. #if !defined(GPAC_DISABLE_MEDIA_IMPORT) && !defined(GPAC_DISABLE_ISOM_WRITE)
  2633. if (nb_add) {
  2634. u8 open_mode = GF_ISOM_OPEN_EDIT;
  2635. if (force_new) {
  2636. open_mode = (do_flat) ? GF_ISOM_OPEN_WRITE : GF_ISOM_WRITE_EDIT;
  2637. } else {
  2638. FILE *test = gf_f64_open(inName, "rb");
  2639. if (!test) {
  2640. open_mode = (do_flat) ? GF_ISOM_OPEN_WRITE : GF_ISOM_WRITE_EDIT;
  2641. if (!outName) outName = inName;
  2642. } else {
  2643. fclose(test);
  2644. if (! gf_isom_probe_file(inName) ) {
  2645. open_mode = (do_flat) ? GF_ISOM_OPEN_WRITE : GF_ISOM_WRITE_EDIT;
  2646. if (!outName) outName = inName;
  2647. }
  2648. }
  2649. }
  2650. open_edit = 1;
  2651. file = gf_isom_open(inName, open_mode, tmpdir);
  2652. if (!file) {
  2653. fprintf(stderr, "Cannot open destination file %s: %s\n", inName, gf_error_to_string(gf_isom_last_error(NULL)) );
  2654. MP4BOX_EXIT_WITH_CODE(1);
  2655. }
  2656. for (i=0; i<(u32) argc; i++) {
  2657. if (!strcmp(argv[i], "-add")) {
  2658. char *src = argv[i+1];
  2659. e = import_file(file, src, import_flags, import_fps, agg_samples);
  2660. if (e) {
  2661. while (src) {
  2662. char *sep = strchr(src, '+');
  2663. if (sep) sep[0] = 0;
  2664. e = import_file(file, src, import_flags, import_fps, agg_samples);
  2665. if (sep) {
  2666. sep[0] = '+';
  2667. src = sep+1;
  2668. } else {
  2669. src= NULL;
  2670. }
  2671. if (e)
  2672. break;
  2673. }
  2674. if (e) {
  2675. fprintf(stderr, "Error importing %s: %s\n", argv[i+1], gf_error_to_string(e));
  2676. gf_isom_delete(file);
  2677. MP4BOX_EXIT_WITH_CODE(1);
  2678. }
  2679. }
  2680. i++;
  2681. }
  2682. }
  2683. /*unless explicitly asked, remove all systems tracks*/
  2684. if (!keep_sys_tracks) remove_systems_tracks(file);
  2685. needSave = 1;
  2686. /*JLF commented: if you want ISMA, just ask for it, no more auto-detect*/
  2687. // if (!conv_type && can_convert_to_isma(file)) conv_type = GF_ISOM_CONV_TYPE_ISMA;
  2688. }
  2689. if (nb_cat) {
  2690. if (!file) {
  2691. u8 open_mode = GF_ISOM_OPEN_EDIT;
  2692. if (force_new) {
  2693. open_mode = (do_flat) ? GF_ISOM_OPEN_WRITE : GF_ISOM_WRITE_EDIT;
  2694. } else {
  2695. FILE *test = gf_f64_open(inName, "rb");
  2696. if (!test) {
  2697. open_mode = (do_flat) ? GF_ISOM_OPEN_WRITE : GF_ISOM_WRITE_EDIT;
  2698. if (!outName) outName = inName;
  2699. }
  2700. else fclose(test);
  2701. }
  2702. open_edit = 1;
  2703. file = gf_isom_open(inName, open_mode, tmpdir);
  2704. if (!file) {
  2705. fprintf(stderr, "Cannot open destination file %s: %s\n", inName, gf_error_to_string(gf_isom_last_error(NULL)) );
  2706. MP4BOX_EXIT_WITH_CODE(1);
  2707. }
  2708. }
  2709. for (i=0; i<(u32)argc; i++) {
  2710. if (!strcmp(argv[i], "-cat") || !strcmp(argv[i], "-catx")) {
  2711. e = cat_isomedia_file(file, argv[i+1], import_flags, import_fps, agg_samples, tmpdir, force_cat, align_cat, !strcmp(argv[i], "-catx") ? GF_TRUE : GF_FALSE);
  2712. if (e) {
  2713. fprintf(stderr, "Error appending %s: %s\n", argv[i+1], gf_error_to_string(e));
  2714. gf_isom_delete(file);
  2715. MP4BOX_EXIT_WITH_CODE(1);
  2716. }
  2717. i++;
  2718. }
  2719. }
  2720. /*unless explicitly asked, remove all systems tracks*/
  2721. if (!keep_sys_tracks) remove_systems_tracks(file);
  2722. needSave = 1;
  2723. if (conv_type && can_convert_to_isma(file)) conv_type = GF_ISOM_CONV_TYPE_ISMA;
  2724. }
  2725. #endif
  2726. #if !defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_SCENE_ENCODER) && !defined(GPAC_DISABLE_MEDIA_IMPORT)
  2727. else if (chunk_mode) {
  2728. if (!inName) {
  2729. fprintf(stderr, "chunk encoding syntax: [-outctx outDump] -inctx inScene auFile\n");
  2730. MP4BOX_EXIT_WITH_CODE(1);
  2731. }
  2732. e = EncodeFileChunk(inName, outName ? outName : inName, input_ctx, output_ctx, tmpdir);
  2733. if (e) fprintf(stderr, "Error encoding chunk file %s\n", gf_error_to_string(e));
  2734. MP4BOX_EXIT_WITH_CODE( e ? 1 : 0 );
  2735. }
  2736. #endif
  2737. else if (encode) {
  2738. #if !defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_SCENE_ENCODER) && !defined(GPAC_DISABLE_MEDIA_IMPORT)
  2739. FILE *logs = NULL;
  2740. if (do_log) {
  2741. char logfile[5000];
  2742. strcpy(logfile, inName);
  2743. if (strchr(split_file_name(logfile), '.')) {
  2744. while (logfile[strlen(logfile)-1] != '.') logfile[strlen(logfile)-1] = 0;
  2745. logfile[strlen(logfile)-1] = 0;
  2746. }
  2747. strcat(logfile, "_enc.logs");
  2748. logs = gf_f64_open(logfile, "wt");
  2749. }
  2750. strcpy(outfile, outName ? outName : inName);
  2751. if (strchr(split_file_name(outfile), '.')) {
  2752. while (outfile[strlen(outfile)-1] != '.') outfile[strlen(outfile)-1] = 0;
  2753. outfile[strlen(outfile)-1] = 0;
  2754. }
  2755. strcat(outfile, ".mp4");
  2756. file = gf_isom_open(outfile, GF_ISOM_WRITE_EDIT, tmpdir);
  2757. opts.mediaSource = mediaSource ? mediaSource : outfile;
  2758. e = EncodeFile(inName, file, &opts, logs);
  2759. if (logs) fclose(logs);
  2760. if (e) goto err_exit;
  2761. needSave = 1;
  2762. if (do_saf) {
  2763. needSave = 0;
  2764. open_edit = 0;
  2765. }
  2766. #endif
  2767. }
  2768. #ifndef GPAC_DISABLE_ISOM_WRITE
  2769. else if (pack_file) {
  2770. char *fileName = strchr(pack_file, ':');
  2771. if (fileName && ((fileName - pack_file)==4)) {
  2772. fileName[0] = 0;
  2773. file = package_file(fileName + 1, pack_file, tmpdir, pack_wgt);
  2774. fileName[0] = ':';
  2775. } else {
  2776. file = package_file(pack_file, NULL, tmpdir, pack_wgt);
  2777. }
  2778. if (!outName) outName = inName;
  2779. needSave = 1;
  2780. open_edit = 1;
  2781. }
  2782. #endif
  2783. if (dash_duration) {
  2784. Bool del_file = GF_FALSE;
  2785. char szMPD[GF_MAX_PATH], *sep;
  2786. GF_Config *dash_ctx = NULL;
  2787. u32 do_abort = 0;
  2788. gf_log_set_tool_level(GF_LOG_DASH, GF_LOG_INFO);
  2789. strcpy(outfile, outName ? outName : gf_url_get_resource_name(inName) );
  2790. sep = strrchr(outfile, '.');
  2791. if (sep) sep[0] = 0;
  2792. if (!outName) strcat(outfile, "_dash");
  2793. strcpy(szMPD, outfile);
  2794. strcat(szMPD, ".mpd");
  2795. if (dash_dynamic)
  2796. fprintf(stderr, "Live DASH-ing - press 'q' to quit, 's' to save context and quit\n");
  2797. if (!dash_ctx_file && dash_live) {
  2798. dash_ctx = gf_cfg_new(NULL, NULL);
  2799. } else if (dash_ctx_file) {
  2800. if (force_new)
  2801. gf_delete_file(dash_ctx_file);
  2802. dash_ctx = gf_cfg_force_new(NULL, dash_ctx_file);
  2803. }
  2804. if (dash_profile==GF_DASH_PROFILE_UNKNOWN)
  2805. dash_profile = dash_dynamic ? GF_DASH_PROFILE_LIVE : GF_DASH_PROFILE_FULL;
  2806. if (!dash_dynamic) {
  2807. time_shift_depth = 0;
  2808. mpd_update_time = 0;
  2809. } else if ((dash_profile>=GF_DASH_PROFILE_MAIN) && !use_url_template && !mpd_update_time) {
  2810. /*use a default MPD update of dash_duration sec*/
  2811. mpd_update_time = (u32) (dash_subduration ? dash_subduration : dash_duration);
  2812. fprintf(stderr, "Using default MPD refresh of %d seconds\n", mpd_update_time);
  2813. }
  2814. if (file && needSave) {
  2815. gf_isom_close(file);
  2816. file = NULL;
  2817. del_file = GF_TRUE;
  2818. }
  2819. while (!do_abort) {
  2820. e = gf_dasher_segment_files(szMPD, dash_inputs, nb_dash_inputs, dash_profile, dash_title, dash_source, cprt, dash_more_info,
  2821. (const char **) mpd_base_urls, nb_mpd_base_urls,
  2822. use_url_template, segment_timeline, single_segment, single_file, bitstream_switching_mode,
  2823. seg_at_rap, dash_duration, seg_name, seg_ext, segment_marker,
  2824. interleaving_time, subsegs_per_sidx, daisy_chain_sidx, frag_at_rap, tmpdir,
  2825. dash_ctx, dash_dynamic, mpd_update_time, time_shift_depth, dash_subduration, min_buffer,
  2826. ast_shift_sec, dash_scale, memory_frags, initial_moof_sn, initial_tfdt, no_fragments_defaults, pssh_in_moof );
  2827. if (e) break;
  2828. if (dash_live) {
  2829. u32 sleep_for = gf_dasher_next_update_time(dash_ctx, mpd_update_time);
  2830. fprintf(stderr, "sleep for %d ms\n", sleep_for);
  2831. while (1) {
  2832. if (gf_prompt_has_input()) {
  2833. char c = (char) gf_prompt_get_char();
  2834. if (c=='q') { do_abort = 1; break; }
  2835. if (c=='s') { do_abort = 2; break; }
  2836. }
  2837. if (dash_dynamic == 2) {
  2838. break;
  2839. }
  2840. if (sleep_for<100)
  2841. break;
  2842. gf_sleep(100);
  2843. sleep_for = gf_dasher_next_update_time(dash_ctx, mpd_update_time);
  2844. }
  2845. } else {
  2846. break;
  2847. }
  2848. }
  2849. if (dash_ctx) {
  2850. if (do_abort==2) {
  2851. char szName[1024];
  2852. fprintf(stderr, "Enter file name to save dash context:\n");
  2853. if (scanf("%s", szName) == 1) {
  2854. gf_cfg_set_filename(dash_ctx, szName);
  2855. gf_cfg_save(dash_ctx);
  2856. }
  2857. }
  2858. gf_cfg_del(dash_ctx);
  2859. }
  2860. if (e) fprintf(stderr, "Error DASHing file: %s\n", gf_error_to_string(e));
  2861. if (file) gf_isom_delete(file);
  2862. if (del_file)
  2863. gf_delete_file(inName);
  2864. MP4BOX_EXIT_WITH_CODE( (e!=GF_OK) ? 1 : 0 );
  2865. }
  2866. else if (!file
  2867. #ifndef GPAC_DISABLE_MEDIA_EXPORT
  2868. && !(track_dump_type & GF_EXPORT_AVI_NATIVE)
  2869. #endif
  2870. ) {
  2871. FILE *st = gf_f64_open(inName, "rb");
  2872. Bool file_exists = 0;
  2873. if (st) {
  2874. file_exists = 1;
  2875. fclose(st);
  2876. }
  2877. switch (get_file_type_by_ext(inName)) {
  2878. case 1:
  2879. file = gf_isom_open(inName, (u8) (open_edit ? GF_ISOM_OPEN_EDIT : ( ((dump_isom>0) || print_info) ? GF_ISOM_OPEN_READ_DUMP : GF_ISOM_OPEN_READ) ), tmpdir);
  2880. if (!file && (gf_isom_last_error(NULL) == GF_ISOM_INCOMPLETE_FILE) && !open_edit) {
  2881. u64 missing_bytes;
  2882. e = gf_isom_open_progressive(inName, 0, 0, &file, &missing_bytes);
  2883. fprintf(stderr, "Truncated file - missing "LLD" bytes\n", missing_bytes);
  2884. }
  2885. if (!file) {
  2886. if (open_edit && nb_meta_act) {
  2887. file = gf_isom_open(inName, GF_ISOM_WRITE_EDIT, tmpdir);
  2888. if (!outName && file) outName = inName;
  2889. }
  2890. if (!file) {
  2891. fprintf(stderr, "Error opening file %s: %s\n", inName, gf_error_to_string(gf_isom_last_error(NULL)));
  2892. MP4BOX_EXIT_WITH_CODE(1);
  2893. }
  2894. }
  2895. break;
  2896. /*allowed for bt<->xmt*/
  2897. case 2:
  2898. case 3:
  2899. /*allowed for svg->lsr**/
  2900. case 4:
  2901. /*allowed for swf->bt, swf->xmt, swf->svg*/
  2902. case 5:
  2903. break;
  2904. /*used for .saf / .lsr dump*/
  2905. case 6:
  2906. #ifndef GPAC_DISABLE_SCENE_DUMP
  2907. if ((dump_mode==1+GF_SM_DUMP_LASER) || (dump_mode==1+GF_SM_DUMP_SVG)) {
  2908. break;
  2909. }
  2910. #endif
  2911. default:
  2912. if (!open_edit && file_exists && !gf_isom_probe_file(inName) && track_dump_type) {
  2913. }
  2914. #ifndef GPAC_DISABLE_ISOM_WRITE
  2915. else if (!open_edit && file_exists /* && !gf_isom_probe_file(inName) */ && !dump_mode) {
  2916. /*************************************************************************************************/
  2917. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  2918. if(dvbhdemux)
  2919. {
  2920. GF_MediaImporter import;
  2921. file = gf_isom_open("ttxt_convert", GF_ISOM_OPEN_WRITE, NULL);
  2922. memset(&import, 0, sizeof(GF_MediaImporter));
  2923. import.dest = file;
  2924. import.in_name = inName;
  2925. import.flags = GF_IMPORT_MPE_DEMUX;
  2926. e = gf_media_import(&import);
  2927. if (e) {
  2928. fprintf(stderr, "Error importing %s: %s\n", inName, gf_error_to_string(e));
  2929. gf_isom_delete(file);
  2930. gf_delete_file("ttxt_convert");
  2931. MP4BOX_EXIT_WITH_CODE(1);
  2932. }
  2933. }
  2934. #endif /*GPAC_DISABLE_MEDIA_IMPORT*/
  2935. if (dump_m2ts) {
  2936. #ifndef GPAC_DISABLE_MPEG2TS
  2937. dump_mpeg2_ts(inName, pes_dump, program_number);
  2938. #endif
  2939. } else if (dump_timestamps) {
  2940. #ifndef GPAC_DISABLE_MPEG2TS
  2941. dump_mpeg2_ts(inName, pes_dump, program_number);
  2942. #endif
  2943. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  2944. } else {
  2945. convert_file_info(inName, info_track_id);
  2946. #endif
  2947. }
  2948. MP4BOX_EXIT_WITH_CODE(0);
  2949. }
  2950. #endif /*GPAC_DISABLE_ISOM_WRITE*/
  2951. else if (open_edit) {
  2952. file = gf_isom_open(inName, GF_ISOM_WRITE_EDIT, tmpdir);
  2953. if (!outName && file) outName = inName;
  2954. } else if (!file_exists) {
  2955. fprintf(stderr, "Error creating file %s: %s\n", inName, gf_error_to_string(GF_URL_ERROR));
  2956. MP4BOX_EXIT_WITH_CODE(1);
  2957. } else {
  2958. fprintf(stderr, "Cannot open %s - extension not supported\n", inName);
  2959. MP4BOX_EXIT_WITH_CODE(1);
  2960. }
  2961. }
  2962. }
  2963. if (file && keep_utc && open_edit) {
  2964. gf_isom_keep_utc_times(file, 1);
  2965. }
  2966. strcpy(outfile, outName ? outName : inName);
  2967. if (strrchr(split_file_name(outfile), '.')) {
  2968. char *szExt = strrchr(split_file_name(outfile), '.');
  2969. /*turn on 3GP saving*/
  2970. if (!stricmp(szExt, ".3gp") || !stricmp(szExt, ".3gpp") || !stricmp(szExt, ".3g2"))
  2971. conv_type = GF_ISOM_CONV_TYPE_3GPP;
  2972. else if (!stricmp(szExt, ".m4a") || !stricmp(szExt, ".m4v"))
  2973. conv_type = GF_ISOM_CONV_TYPE_IPOD;
  2974. else if (!stricmp(szExt, ".psp"))
  2975. conv_type = GF_ISOM_CONV_TYPE_PSP;
  2976. while (outfile[strlen(outfile)-1] != '.') outfile[strlen(outfile)-1] = 0;
  2977. outfile[strlen(outfile)-1] = 0;
  2978. add_ext = outName ? 0 : 1;
  2979. }
  2980. #ifndef GPAC_DISABLE_MEDIA_EXPORT
  2981. if (track_dump_type & GF_EXPORT_AVI_NATIVE) {
  2982. char szFile[1024];
  2983. GF_MediaExporter mdump;
  2984. memset(&mdump, 0, sizeof(mdump));
  2985. mdump.in_name = inName;
  2986. mdump.flags = GF_EXPORT_AVI_NATIVE;
  2987. mdump.trackID = trackID;
  2988. if (dump_std) {
  2989. mdump.out_name = "std";
  2990. } else if (outName) {
  2991. mdump.out_name = outName;
  2992. } else if (trackID>2) {
  2993. sprintf(szFile, "%s_audio%d", outfile, trackID-1);
  2994. mdump.out_name = szFile;
  2995. } else {
  2996. sprintf(szFile, "%s_%s", outfile, (trackID==1) ? "video" : "audio");
  2997. mdump.out_name = szFile;
  2998. }
  2999. e = gf_media_export(&mdump);
  3000. if (e) goto err_exit;
  3001. MP4BOX_EXIT_WITH_CODE(0);
  3002. }
  3003. if (!open_edit && !gf_isom_probe_file(inName) && track_dump_type) {
  3004. GF_MediaExporter mdump;
  3005. char szFile[1024];
  3006. for (i=0; i<nb_track_act; i++) {
  3007. TrackAction *tka = &tracks[i];
  3008. if (tka->act_type != 9) continue;
  3009. memset(&mdump, 0, sizeof(mdump));
  3010. mdump.in_name = inName;
  3011. mdump.flags = tka->dump_type;
  3012. mdump.trackID = tka->trackID;
  3013. mdump.sample_num = raw_sample_num;
  3014. if (outName) {
  3015. mdump.out_name = outName;
  3016. mdump.flags |= GF_EXPORT_MERGE;
  3017. } else if (nb_track_act>1) {
  3018. sprintf(szFile, "%s_track%d", outfile, mdump.trackID);
  3019. mdump.out_name = szFile;
  3020. } else {
  3021. mdump.out_name = outfile;
  3022. }
  3023. if (add_ext)
  3024. mdump.flags |= GF_EXPORT_ADD_EXTENSION;
  3025. e = gf_media_export(&mdump);
  3026. if (e) goto err_exit;
  3027. }
  3028. MP4BOX_EXIT_WITH_CODE(0);
  3029. }
  3030. #endif /*GPAC_DISABLE_MEDIA_EXPORT*/
  3031. #ifndef GPAC_DISABLE_SCENE_DUMP
  3032. if (dump_mode) {
  3033. e = dump_file_text(inName, dump_std ? NULL : outfile, dump_mode-1, do_log);
  3034. if (e) goto err_exit;
  3035. }
  3036. #endif
  3037. #ifndef GPAC_DISABLE_SCENE_STATS
  3038. if (stat_level) dump_scene_stats(inName, dump_std ? NULL : outfile, stat_level);
  3039. #endif
  3040. #ifndef GPAC_DISABLE_ISOM_HINTING
  3041. if (!HintIt && print_sdp) DumpSDP(file, dump_std ? NULL : outfile);
  3042. #endif
  3043. if (print_info) {
  3044. if (!file) {
  3045. fprintf(stderr, "Cannot print info on a non ISOM file (%s)\n", inName);
  3046. } else {
  3047. if (info_track_id) DumpTrackInfo(file, info_track_id, 1);
  3048. else DumpMovieInfo(file);
  3049. }
  3050. }
  3051. #ifndef GPAC_DISABLE_ISOM_DUMP
  3052. if (dump_isom) dump_isom_xml(file, dump_std ? NULL : outfile);
  3053. if (dump_cr) dump_file_ismacryp(file, dump_std ? NULL : outfile);
  3054. if ((dump_ttxt || dump_srt) && trackID) dump_timed_text_track(file, trackID, dump_std ? NULL : outfile, 0, dump_srt);
  3055. #ifndef GPAC_DISABLE_ISOM_HINTING
  3056. if (dump_rtp) dump_file_rtp(file, dump_std ? NULL : outfile);
  3057. #endif
  3058. #endif
  3059. if (dump_timestamps) dump_file_timestamps(file, dump_std ? NULL : outfile);
  3060. if (dump_nal) dump_file_nal(file, dump_nal, dump_std ? NULL : outfile);
  3061. if (do_hash) {
  3062. u8 hash[20];
  3063. e = gf_media_get_file_hash(inName, hash);
  3064. if (e) goto err_exit;
  3065. fprintf(stderr, "File %s hash (SHA-1): ", inName);
  3066. for (i=0; i<20; i++) fprintf(stderr, "%02X", hash[i]);
  3067. fprintf(stderr, "\n");
  3068. }
  3069. if (dump_cart) dump_cover_art(file, outfile);
  3070. if (dump_chap) dump_chapters(file, outfile, (dump_chap==2) ? 1 : 0);
  3071. if (dump_iod) {
  3072. GF_InitialObjectDescriptor *iod = (GF_InitialObjectDescriptor *)gf_isom_get_root_od(file);
  3073. if (!iod) {
  3074. fprintf(stderr, "File %s has no IOD", inName);
  3075. } else {
  3076. char szName[GF_MAX_PATH];
  3077. FILE *iodf;
  3078. GF_BitStream *bs = NULL;
  3079. sprintf(szName, "%s.iod", outfile);
  3080. iodf = gf_f64_open(szName, "wb");
  3081. if (!iodf) {
  3082. fprintf(stderr, "Cannot open destination %s\n", szName);
  3083. } else {
  3084. char *desc;
  3085. u32 size;
  3086. bs = gf_bs_from_file(iodf, GF_BITSTREAM_WRITE);
  3087. if (gf_odf_desc_write((GF_Descriptor *)iod, &desc, &size)==GF_OK) {
  3088. gf_fwrite(desc, 1, size, iodf);
  3089. gf_free(desc);
  3090. } else {
  3091. fprintf(stderr, "Error writing IOD %s\n", szName);
  3092. }
  3093. fclose(iodf);
  3094. }
  3095. gf_free(bs);
  3096. }
  3097. }
  3098. #if !defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_MEDIA_IMPORT)
  3099. if (split_duration || split_size) {
  3100. split_isomedia_file(file, split_duration, split_size, inName, interleaving_time, split_start, adjust_split_end, outName, tmpdir);
  3101. /*never save file when splitting is desired*/
  3102. open_edit = 0;
  3103. needSave = 0;
  3104. }
  3105. #endif
  3106. #ifndef GPAC_DISABLE_MEDIA_EXPORT
  3107. if (track_dump_type) {
  3108. char szFile[1024];
  3109. GF_MediaExporter mdump;
  3110. for (i=0; i<nb_track_act; i++) {
  3111. TrackAction *tka = &tracks[i];
  3112. if (tka->act_type != 9) continue;
  3113. memset(&mdump, 0, sizeof(mdump));
  3114. mdump.file = file;
  3115. mdump.flags = tka->dump_type;
  3116. mdump.trackID = tka->trackID;
  3117. mdump.sample_num = raw_sample_num;
  3118. if (tka->out_name) {
  3119. mdump.out_name = tka->out_name;
  3120. } else if (outName) {
  3121. mdump.out_name = outName;
  3122. mdump.flags |= GF_EXPORT_MERGE;
  3123. } else {
  3124. sprintf(szFile, "%s_track%d", outfile, mdump.trackID);
  3125. mdump.out_name = szFile;
  3126. }
  3127. if (add_ext)
  3128. mdump.flags |= GF_EXPORT_ADD_EXTENSION;
  3129. if (tka->trackID==(u32) -1) {
  3130. u32 j;
  3131. for (j=0; j<gf_isom_get_track_count(file); j++) {
  3132. mdump.trackID = gf_isom_get_track_id(file, j+1);
  3133. sprintf(szFile, "%s_track%d", outfile, mdump.trackID);
  3134. mdump.out_name = szFile;
  3135. e = gf_media_export(&mdump);
  3136. if (e) goto err_exit;
  3137. }
  3138. } else {
  3139. e = gf_media_export(&mdump);
  3140. if (e) goto err_exit;
  3141. }
  3142. }
  3143. } else if (do_saf) {
  3144. GF_MediaExporter mdump;
  3145. memset(&mdump, 0, sizeof(mdump));
  3146. mdump.file = file;
  3147. mdump.flags = GF_EXPORT_SAF;
  3148. mdump.out_name = outfile;
  3149. e = gf_media_export(&mdump);
  3150. if (e) goto err_exit;
  3151. }
  3152. #endif
  3153. for (i=0; i<nb_meta_act; i++) {
  3154. u32 tk = 0;
  3155. Bool self_ref;
  3156. MetaAction *meta = &metas[i];
  3157. if (meta->trackID) tk = gf_isom_get_track_by_id(file, meta->trackID);
  3158. switch (meta->act_type) {
  3159. #ifndef GPAC_DISABLE_ISOM_WRITE
  3160. case 0:
  3161. /*note: we don't handle file brand modification, this is an author stuff and cannot be guessed from meta type*/
  3162. e = gf_isom_set_meta_type(file, meta->root_meta, tk, meta->meta_4cc);
  3163. gf_isom_modify_alternate_brand(file, GF_ISOM_BRAND_ISO2, 1);
  3164. needSave = 1;
  3165. break;
  3166. case 1:
  3167. self_ref = !stricmp(meta->szPath, "NULL") || !stricmp(meta->szPath, "this") || !stricmp(meta->szPath, "self");
  3168. e = gf_isom_add_meta_item(file, meta->root_meta, tk, self_ref, self_ref ? NULL : meta->szPath,
  3169. strlen(meta->szName) ? meta->szName : NULL,
  3170. strlen(meta->mime_type) ? meta->mime_type : NULL,
  3171. strlen(meta->enc_type) ? meta->enc_type : NULL,
  3172. meta->use_dref ? meta->szPath : NULL, NULL);
  3173. needSave = 1;
  3174. break;
  3175. case 2:
  3176. e = gf_isom_remove_meta_item(file, meta->root_meta, tk, meta->item_id);
  3177. needSave = 1;
  3178. break;
  3179. case 3:
  3180. e = gf_isom_set_meta_primary_item(file, meta->root_meta, tk, meta->item_id);
  3181. needSave = 1;
  3182. break;
  3183. case 4:
  3184. case 5:
  3185. e = gf_isom_set_meta_xml(file, meta->root_meta, tk, meta->szPath, (meta->act_type==5) ? 1 : 0);
  3186. needSave = 1;
  3187. break;
  3188. case 6:
  3189. if (gf_isom_get_meta_item_count(file, meta->root_meta, tk)) {
  3190. e = gf_isom_remove_meta_xml(file, meta->root_meta, tk);
  3191. needSave = 1;
  3192. } else {
  3193. fprintf(stderr, "No meta box in input file\n");
  3194. }
  3195. break;
  3196. case 8:
  3197. if (gf_isom_get_meta_item_count(file, meta->root_meta, tk)) {
  3198. e = gf_isom_extract_meta_item(file, meta->root_meta, tk, meta->item_id, strlen(meta->szPath) ? meta->szPath : NULL);
  3199. } else {
  3200. fprintf(stderr, "No meta box in input file\n");
  3201. }
  3202. break;
  3203. #endif
  3204. case 7:
  3205. if (gf_isom_has_meta_xml(file, meta->root_meta, tk)) {
  3206. e = gf_isom_extract_meta_xml(file, meta->root_meta, tk, meta->szPath, NULL);
  3207. } else {
  3208. fprintf(stderr, "No meta box in input file\n");
  3209. }
  3210. break;
  3211. }
  3212. if (e) goto err_exit;
  3213. }
  3214. if (!open_edit && !needSave) {
  3215. if (file) gf_isom_delete(file);
  3216. MP4BOX_EXIT_WITH_CODE(0);
  3217. }
  3218. #ifndef GPAC_DISABLE_ISOM_WRITE
  3219. for (i=0; i<nb_tsel_acts; i++) {
  3220. switch (tsel_acts[i].act_type) {
  3221. case 0:
  3222. e = gf_isom_set_track_switch_parameter(file,
  3223. gf_isom_get_track_by_id(file, tsel_acts[i].trackID),
  3224. tsel_acts[i].refTrackID ? gf_isom_get_track_by_id(file, tsel_acts[i].refTrackID) : 0,
  3225. tsel_acts[i].is_switchGroup ? 1 : 0,
  3226. &tsel_acts[i].switchGroupID,
  3227. tsel_acts[i].criteria, tsel_acts[i].nb_criteria);
  3228. if (e) goto err_exit;
  3229. needSave = 1;
  3230. break;
  3231. case 1:
  3232. e = gf_isom_reset_track_switch_parameter(file, gf_isom_get_track_by_id(file, tsel_acts[i].trackID), 0);
  3233. if (e) goto err_exit;
  3234. needSave = 1;
  3235. break;
  3236. case 2:
  3237. e = gf_isom_reset_track_switch_parameter(file, gf_isom_get_track_by_id(file, tsel_acts[i].trackID), 1);
  3238. if (e) goto err_exit;
  3239. needSave = 1;
  3240. break;
  3241. case 3:
  3242. e = gf_isom_reset_switch_parameters(file);
  3243. if (e) goto err_exit;
  3244. needSave = 1;
  3245. break;
  3246. }
  3247. }
  3248. if (remove_sys_tracks) {
  3249. #ifndef GPAC_DISABLE_AV_PARSERS
  3250. remove_systems_tracks(file);
  3251. #endif
  3252. needSave = 1;
  3253. if (conv_type < GF_ISOM_CONV_TYPE_ISMA_EX) conv_type = 0;
  3254. }
  3255. if (remove_root_od) {
  3256. gf_isom_remove_root_od(file);
  3257. needSave = 1;
  3258. }
  3259. #ifndef GPAC_DISABLE_ISOM_HINTING
  3260. if (remove_hint) {
  3261. for (i=0; i<gf_isom_get_track_count(file); i++) {
  3262. if (gf_isom_get_media_type(file, i+1) == GF_ISOM_MEDIA_HINT) {
  3263. fprintf(stderr, "Removing hint track ID %d\n", gf_isom_get_track_id(file, i+1));
  3264. gf_isom_remove_track(file, i+1);
  3265. i--;
  3266. }
  3267. }
  3268. gf_isom_sdp_clean(file);
  3269. needSave = 1;
  3270. }
  3271. #endif
  3272. if (!encode) {
  3273. if (!file) {
  3274. fprintf(stderr, "Nothing to do - exiting\n");
  3275. MP4BOX_EXIT_WITH_CODE(0);
  3276. }
  3277. if (outName) {
  3278. strcpy(outfile, outName);
  3279. } else {
  3280. #if defined(__MINGW32__) || defined(_MSC_VER)
  3281. char *rel_name = _mbsrchr(inName, GF_PATH_SEPARATOR);
  3282. #else
  3283. char *rel_name = strrchr(inName, GF_PATH_SEPARATOR);
  3284. #endif
  3285. if (!rel_name) rel_name = strrchr(inName, '/');
  3286. strcpy(outfile, "");
  3287. if (tmpdir) {
  3288. strcpy(outfile, tmpdir);
  3289. if (!strchr("\\/", tmpdir[strlen(tmpdir)-1])) strcat(outfile, "/");
  3290. }
  3291. if (!pack_file) strcat(outfile, "out_");
  3292. strcat(outfile, rel_name ? rel_name + 1 : inName);
  3293. if (pack_file) {
  3294. strcpy(outfile, rel_name ? rel_name + 1 : inName);
  3295. rel_name = strrchr(split_file_name(outfile), '.');
  3296. if (rel_name) rel_name[0] = 0;
  3297. strcat(outfile, ".m21");
  3298. }
  3299. }
  3300. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  3301. if ((conv_type == GF_ISOM_CONV_TYPE_ISMA) || (conv_type == GF_ISOM_CONV_TYPE_ISMA_EX)) {
  3302. fprintf(stderr, "Converting to ISMA Audio-Video MP4 file...\n");
  3303. /*keep ESIDs when doing ISMACryp*/
  3304. e = gf_media_make_isma(file, crypt ? 1 : 0, 0, (conv_type==GF_ISOM_CONV_TYPE_ISMA_EX) ? 1 : 0);
  3305. if (e) goto err_exit;
  3306. needSave = 1;
  3307. }
  3308. if (conv_type == GF_ISOM_CONV_TYPE_3GPP) {
  3309. fprintf(stderr, "Converting to 3GP file...\n");
  3310. e = gf_media_make_3gpp(file);
  3311. if (e) goto err_exit;
  3312. needSave = 1;
  3313. }
  3314. if (conv_type == GF_ISOM_CONV_TYPE_PSP) {
  3315. fprintf(stderr, "Converting to PSP file...\n");
  3316. e = gf_media_make_psp(file);
  3317. if (e) goto err_exit;
  3318. needSave = 1;
  3319. }
  3320. #endif /*GPAC_DISABLE_MEDIA_IMPORT*/
  3321. if (conv_type == GF_ISOM_CONV_TYPE_IPOD) {
  3322. u32 major_brand = 0;
  3323. fprintf(stderr, "Setting up iTunes/iPod file...\n");
  3324. for (i=0; i<gf_isom_get_track_count(file); i++) {
  3325. u32 mType = gf_isom_get_media_type(file, i+1);
  3326. switch (mType) {
  3327. case GF_ISOM_MEDIA_VISUAL:
  3328. major_brand = GF_4CC('M','4','V',' ');
  3329. gf_isom_set_ipod_compatible(file, i+1);
  3330. #if 0
  3331. switch (gf_isom_get_media_subtype(file, i+1, 1)) {
  3332. case GF_ISOM_SUBTYPE_AVC_H264:
  3333. case GF_ISOM_SUBTYPE_AVC2_H264:
  3334. case GF_ISOM_SUBTYPE_AVC3_H264:
  3335. case GF_ISOM_SUBTYPE_AVC4_H264:
  3336. fprintf(stderr, "Forcing AVC/H264 SAR to 1:1...\n");
  3337. gf_media_change_par(file, i+1, 1, 1);
  3338. break;
  3339. }
  3340. #endif
  3341. break;
  3342. case GF_ISOM_MEDIA_AUDIO:
  3343. if (!major_brand) major_brand = GF_4CC('M','4','A',' ');
  3344. else gf_isom_modify_alternate_brand(file, GF_4CC('M','4','A',' '), 1);
  3345. break;
  3346. case GF_ISOM_MEDIA_TEXT:
  3347. /*this is a text track track*/
  3348. if (gf_isom_get_media_subtype(file, i+1, 1) == GF_4CC('t','x','3','g')) {
  3349. u32 j;
  3350. Bool is_chap = 0;
  3351. for (j=0; j<gf_isom_get_track_count(file); j++) {
  3352. s32 count = gf_isom_get_reference_count(file, j+1, GF_4CC('c','h','a','p'));
  3353. if (count>0) {
  3354. u32 tk, k;
  3355. for (k=0; k<(u32) count; k++) {
  3356. gf_isom_get_reference(file, j+1, GF_4CC('c','h','a','p'), k+1, &tk);
  3357. if (tk==i+1) {
  3358. is_chap = 1;
  3359. break;
  3360. }
  3361. }
  3362. if (is_chap) break;
  3363. }
  3364. if (is_chap) break;
  3365. }
  3366. /*this is a subtitle track*/
  3367. if (!is_chap)
  3368. gf_isom_set_media_type(file, i+1, GF_ISOM_MEDIA_SUBT);
  3369. }
  3370. break;
  3371. }
  3372. }
  3373. gf_isom_set_brand_info(file, major_brand, 1);
  3374. gf_isom_modify_alternate_brand(file, GF_ISOM_BRAND_MP42, 1);
  3375. needSave = 1;
  3376. }
  3377. #ifndef GPAC_DISABLE_MCRYPT
  3378. if (crypt) {
  3379. if (!drm_file) {
  3380. fprintf(stderr, "Missing DRM file location - usage '-%s drm_file input_file\n", (crypt==1) ? "crypt" : "decrypt");
  3381. e = GF_BAD_PARAM;
  3382. goto err_exit;
  3383. }
  3384. if (crypt == 1) {
  3385. e = gf_crypt_file(file, drm_file);
  3386. } else if (crypt ==2) {
  3387. e = gf_decrypt_file(file, drm_file);
  3388. }
  3389. if (e) goto err_exit;
  3390. needSave = 1;
  3391. }
  3392. #endif /*GPAC_DISABLE_MCRYPT*/
  3393. } else if (outName) {
  3394. strcpy(outfile, outName);
  3395. }
  3396. for (i=0; i<nb_track_act; i++) {
  3397. TrackAction *tka = &tracks[i];
  3398. u32 track = tka->trackID ? gf_isom_get_track_by_id(file, tka->trackID) : 0;
  3399. u32 timescale = gf_isom_get_timescale(file);
  3400. switch (tka->act_type) {
  3401. case 0:
  3402. e = gf_isom_remove_track(file, track);
  3403. if (e) {
  3404. fprintf(stderr, "Error Removing track ID %d: %s\n", tka->trackID, gf_error_to_string(e));
  3405. } else {
  3406. fprintf(stderr, "Removing track ID %d\n", tka->trackID);
  3407. }
  3408. needSave = 1;
  3409. break;
  3410. case 1:
  3411. for (i=0; i<gf_isom_get_track_count(file); i++) {
  3412. if (track && (track != i+1)) continue;
  3413. e = gf_isom_set_media_language(file, i+1, (char *) GetLanguageCode(tka->lang));
  3414. if (e) goto err_exit;
  3415. needSave = 1;
  3416. }
  3417. needSave = 1;
  3418. break;
  3419. case 2:
  3420. if (tka->delay_ms) {
  3421. u64 tk_dur;
  3422. gf_isom_remove_edit_segments(file, track);
  3423. tk_dur = gf_isom_get_track_duration(file, track);
  3424. if (gf_isom_get_edit_segment_count(file, track))
  3425. needSave = 1;
  3426. if (tka->delay_ms>0) {
  3427. gf_isom_append_edit_segment(file, track, (timescale*tka->delay_ms)/1000, 0, GF_ISOM_EDIT_EMPTY);
  3428. gf_isom_append_edit_segment(file, track, tk_dur, 0, GF_ISOM_EDIT_NORMAL);
  3429. needSave = 1;
  3430. } else {
  3431. u64 to_skip = (timescale*(-tka->delay_ms))/1000;
  3432. if (to_skip<tk_dur) {
  3433. u64 media_time = (-tka->delay_ms)*gf_isom_get_media_timescale(file, track) / 1000;
  3434. gf_isom_append_edit_segment(file, track, tk_dur-to_skip, media_time, GF_ISOM_EDIT_NORMAL);
  3435. needSave = 1;
  3436. } else {
  3437. fprintf(stderr, "Warning: request negative delay longer than track duration - ignoring\n");
  3438. }
  3439. }
  3440. } else if (gf_isom_get_edit_segment_count(file, track)) {
  3441. gf_isom_remove_edit_segments(file, track);
  3442. needSave = 1;
  3443. }
  3444. break;
  3445. case 3:
  3446. for (i=0; i<gf_isom_get_track_count(file); i++) {
  3447. if (track && (track != i+1)) continue;
  3448. if (!gf_isom_is_media_encrypted(file, i+1, 1)) continue;
  3449. if (!gf_isom_is_ismacryp_media(file, i+1, 1)) continue;
  3450. e = gf_isom_change_ismacryp_protection(file, i+1, 1, NULL, (char *) tka->kms);
  3451. if (e) goto err_exit;
  3452. needSave = 1;
  3453. }
  3454. break;
  3455. case 4:
  3456. e = gf_media_change_par(file, track, tka->par_num, tka->par_den);
  3457. needSave = 1;
  3458. break;
  3459. case 5:
  3460. e = gf_isom_set_handler_name(file, track, tka->hdl_name);
  3461. needSave = 1;
  3462. break;
  3463. case 6:
  3464. if (!gf_isom_is_track_enabled(file, track)) {
  3465. e = gf_isom_set_track_enabled(file, track, 1);
  3466. needSave = 1;
  3467. }
  3468. break;
  3469. case 7:
  3470. if (gf_isom_is_track_enabled(file, track)) {
  3471. e = gf_isom_set_track_enabled(file, track, 0);
  3472. needSave = 1;
  3473. }
  3474. break;
  3475. case 8:
  3476. e = gf_isom_set_track_reference(file, track, GF_4CC(tka->lang[0], tka->lang[1], tka->lang[2], tka->lang[3]), (u32) tka->delay_ms);
  3477. needSave = 1;
  3478. break;
  3479. }
  3480. if (e) goto err_exit;
  3481. }
  3482. if (itunes_tags) {
  3483. char *tags = itunes_tags;
  3484. while (tags) {
  3485. char *val;
  3486. char *sep = strchr(tags, ':');
  3487. u32 tlen, itag = 0;
  3488. if (sep) {
  3489. while (sep) {
  3490. for (itag=0; itag<nb_itunes_tags;itag++) {
  3491. if (!strnicmp(sep+1, itags[itag].name, strlen(itags[itag].name))) break;
  3492. }
  3493. if (itag<nb_itunes_tags) {
  3494. break;
  3495. }
  3496. sep = strchr(sep+1, ':');
  3497. }
  3498. if (sep) sep[0] = 0;
  3499. }
  3500. for (itag=0; itag<nb_itunes_tags;itag++) {
  3501. if (!strnicmp(tags, itags[itag].name, strlen(itags[itag].name))) {
  3502. break;
  3503. }
  3504. }
  3505. if (itag==nb_itunes_tags) {
  3506. fprintf(stderr, "Invalid iTune tag format \"%s\" - ignoring\n", tags);
  3507. tags = NULL;
  3508. continue;
  3509. }
  3510. itag = itags[itag].code;
  3511. val = strchr(tags, '=');
  3512. if (!val) {
  3513. fprintf(stderr, "Invalid iTune tag format \"%s\" (expecting '=') - ignoring\n", tags);
  3514. tags = NULL;
  3515. continue;
  3516. }
  3517. if (val) {
  3518. val ++;
  3519. if ((val[0]==':') || !val[0] || !stricmp(val, "NULL") ) val = NULL;
  3520. }
  3521. tlen = val ? (u32) strlen(val) : 0;
  3522. switch (itag) {
  3523. case GF_ISOM_ITUNE_COVER_ART:
  3524. {
  3525. char *d, *ext;
  3526. FILE *t = gf_f64_open(val, "rb");
  3527. gf_f64_seek(t, 0, SEEK_END);
  3528. tlen = (u32) gf_f64_tell(t);
  3529. gf_f64_seek(t, 0, SEEK_SET);
  3530. d = gf_malloc(sizeof(char) * tlen);
  3531. tlen = (u32) fread(d, sizeof(char), tlen, t);
  3532. fclose(t);
  3533. ext = strrchr(split_file_name(val), '.');
  3534. if (!stricmp(ext, ".png")) tlen |= 0x80000000;
  3535. e = gf_isom_apple_set_tag(file, GF_ISOM_ITUNE_COVER_ART, d, tlen);
  3536. gf_free(d);
  3537. }
  3538. break;
  3539. case GF_ISOM_ITUNE_TEMPO:
  3540. gf_isom_apple_set_tag(file, itag, NULL, atoi(val) );
  3541. break;
  3542. case GF_ISOM_ITUNE_GENRE:
  3543. {
  3544. u8 _v = id3_get_genre_tag(val);
  3545. if (_v) {
  3546. gf_isom_apple_set_tag(file, itag, NULL, _v);
  3547. } else {
  3548. gf_isom_apple_set_tag(file, itag, val, (u32) strlen(val) );
  3549. }
  3550. }
  3551. break;
  3552. case GF_ISOM_ITUNE_DISK:
  3553. case GF_ISOM_ITUNE_TRACKNUMBER:
  3554. {
  3555. u32 n, t;
  3556. char _t[8];
  3557. n = t = 0;
  3558. memset(_t, 0, sizeof(char)*8);
  3559. tlen = (itag==GF_ISOM_ITUNE_DISK) ? 6 : 8;
  3560. if (sscanf(val, "%u/%u", &n, &t) == 2) { _t[3]=n; _t[2]=n>>8; _t[5]=t; _t[4]=t>>8; }
  3561. else if (sscanf(val, "%u", &n) == 1) { _t[3]=n; _t[2]=n>>8;}
  3562. else tlen = 0;
  3563. if (tlen) gf_isom_apple_set_tag(file, itag, _t, tlen);
  3564. }
  3565. break;
  3566. case GF_ISOM_ITUNE_GAPLESS:
  3567. case GF_ISOM_ITUNE_COMPILATION:
  3568. {
  3569. char _t[1];
  3570. if (!stricmp(val, "yes")) _t[0] = 1;
  3571. else _t[0] = 0;
  3572. gf_isom_apple_set_tag(file, itag, _t, 1);
  3573. }
  3574. break;
  3575. default:
  3576. gf_isom_apple_set_tag(file, itag, val, tlen);
  3577. break;
  3578. }
  3579. needSave = 1;
  3580. if (sep) {
  3581. sep[0] = ':';
  3582. tags = sep+1;
  3583. } else {
  3584. tags = NULL;
  3585. }
  3586. }
  3587. }
  3588. if (movie_time) {
  3589. gf_isom_set_creation_time(file, movie_time);
  3590. for (i=0; i<gf_isom_get_track_count(file); i++) {
  3591. gf_isom_set_track_creation_time(file, i+1, movie_time);
  3592. }
  3593. needSave = 1;
  3594. }
  3595. #ifndef GPAC_DISABLE_ISOM_FRAGMENTS
  3596. if (Frag) {
  3597. if (!interleaving_time) interleaving_time = 0.5;
  3598. if (HintIt) fprintf(stderr, "Warning: cannot hint and fragment - ignoring hint\n");
  3599. fprintf(stderr, "Fragmenting file (%.3f seconds fragments)\n", interleaving_time);
  3600. e = gf_media_fragment_file(file, outfile, interleaving_time);
  3601. if (e) fprintf(stderr, "Error while fragmenting file: %s\n", gf_error_to_string(e));
  3602. gf_isom_delete(file);
  3603. if (!e && !outName && !force_new) {
  3604. if (gf_delete_file(inName)) fprintf(stderr, "Error removing file %s\n", inName);
  3605. else if (gf_move_file(outfile, inName)) fprintf(stderr, "Error renaming file %s to %s\n", outfile, inName);
  3606. }
  3607. MP4BOX_EXIT_WITH_CODE( (e!=GF_OK) ? 1 : 0 );
  3608. }
  3609. #endif
  3610. #ifndef GPAC_DISABLE_ISOM_HINTING
  3611. if (HintIt) {
  3612. if (force_ocr) SetupClockReferences(file);
  3613. fprintf(stderr, "Hinting file with Path-MTU %d Bytes\n", MTUSize);
  3614. MTUSize -= 12;
  3615. e = HintFile(file, MTUSize, max_ptime, rtp_rate, hint_flags, HintCopy, HintInter, regular_iod, single_group);
  3616. if (e) goto err_exit;
  3617. needSave = 1;
  3618. if (print_sdp) DumpSDP(file, dump_std ? NULL : outfile);
  3619. }
  3620. #endif
  3621. /*full interleave (sample-based) if just hinted*/
  3622. if (FullInter) {
  3623. e = gf_isom_set_storage_mode(file, GF_ISOM_STORE_TIGHT);
  3624. } else if (!interleaving_time) {
  3625. e = gf_isom_set_storage_mode(file, GF_ISOM_STORE_STREAMABLE);
  3626. needSave = 1;
  3627. } else if (do_flat) {
  3628. e = gf_isom_set_storage_mode(file, GF_ISOM_STORE_FLAT);
  3629. needSave = 1;
  3630. } else {
  3631. e = gf_isom_make_interleave(file, interleaving_time);
  3632. if (!e && !old_interleave) e = gf_isom_set_storage_mode(file, GF_ISOM_STORE_DRIFT_INTERLEAVED);
  3633. }
  3634. if (e) goto err_exit;
  3635. #if !defined(GPAC_DISABLE_ISOM_HINTING) && !defined(GPAC_DISABLE_SENG)
  3636. for (i=0; i<nb_sdp_ex; i++) {
  3637. if (sdp_lines[i].trackID) {
  3638. u32 track = gf_isom_get_track_by_id(file, sdp_lines[i].trackID);
  3639. if (gf_isom_get_media_type(file, track)!=GF_ISOM_MEDIA_HINT) {
  3640. s32 ref_count;
  3641. u32 j, k, count = gf_isom_get_track_count(file);
  3642. for (j=0; j<count; j++) {
  3643. if (gf_isom_get_media_type(file, j+1)!=GF_ISOM_MEDIA_HINT) continue;
  3644. ref_count = gf_isom_get_reference_count(file, j+1, GF_ISOM_REF_HINT);
  3645. if (ref_count<0) continue;
  3646. for (k=0; k<(u32) ref_count; k++) {
  3647. u32 refTk;
  3648. if (gf_isom_get_reference(file, j+1, GF_ISOM_REF_HINT, k+1, &refTk)) continue;
  3649. if (refTk==track) {
  3650. track = j+1;
  3651. j=count;
  3652. break;
  3653. }
  3654. }
  3655. }
  3656. }
  3657. gf_isom_sdp_add_track_line(file, track, sdp_lines[i].line);
  3658. needSave = 1;
  3659. } else {
  3660. gf_isom_sdp_add_line(file, sdp_lines[i].line);
  3661. needSave = 1;
  3662. }
  3663. }
  3664. #endif /*!defined(GPAC_DISABLE_ISOM_HINTING) && !defined(GPAC_DISABLE_SENG)*/
  3665. if (cprt) {
  3666. e = gf_isom_set_copyright(file, "und", cprt);
  3667. needSave = 1;
  3668. if (e) goto err_exit;
  3669. }
  3670. if (chap_file) {
  3671. #ifndef GPAC_DISABLE_MEDIA_IMPORT
  3672. e = gf_media_import_chapters(file, chap_file, import_fps);
  3673. needSave = 1;
  3674. #else
  3675. fprintf(stderr, "Warning: GPAC compiled without Media Import, chapters can't be imported\n");
  3676. e = GF_NOT_SUPPORTED;
  3677. #endif
  3678. if (e) goto err_exit;
  3679. }
  3680. if (major_brand) {
  3681. gf_isom_set_brand_info(file, major_brand, minor_version);
  3682. needSave = 1;
  3683. }
  3684. for (i=0; i<nb_alt_brand_add; i++) {
  3685. gf_isom_modify_alternate_brand(file, brand_add[i], 1);
  3686. needSave = 1;
  3687. }
  3688. for (i=0; i<nb_alt_brand_rem; i++) {
  3689. gf_isom_modify_alternate_brand(file, brand_rem[i], 0);
  3690. needSave = 1;
  3691. }
  3692. if (!encode && !force_new) gf_isom_set_final_name(file, outfile);
  3693. if (needSave) {
  3694. if (outName) {
  3695. fprintf(stderr, "Saving to %s: ", outfile);
  3696. gf_isom_set_final_name(file, outfile);
  3697. } else if (encode || pack_file) {
  3698. fprintf(stderr, "Saving to %s: ", gf_isom_get_filename(file) );
  3699. } else {
  3700. fprintf(stderr, "Saving %s: ", inName);
  3701. }
  3702. if (HintIt && FullInter) fprintf(stderr, "Hinted file - Full Interleaving\n");
  3703. else if (FullInter) fprintf(stderr, "Full Interleaving\n");
  3704. else if (do_flat || !interleaving_time) fprintf(stderr, "Flat storage\n");
  3705. else fprintf(stderr, "%.3f secs Interleaving%s\n", interleaving_time, old_interleave ? " - no drift control" : "");
  3706. e = gf_isom_close(file);
  3707. if (!e && !outName && !encode && !force_new && !pack_file) {
  3708. if (gf_delete_file(inName)) fprintf(stderr, "Error removing file %s\n", inName);
  3709. else if (gf_move_file(outfile, inName)) fprintf(stderr, "Error renaming file %s to %s\n", outfile, inName);
  3710. }
  3711. } else {
  3712. gf_isom_delete(file);
  3713. }
  3714. if (e) fprintf(stderr, "Error: %s\n", gf_error_to_string(e));
  3715. MP4BOX_EXIT_WITH_CODE( (e!=GF_OK) ? 1 : 0 );
  3716. #else
  3717. /*close libgpac*/
  3718. gf_isom_delete(file);
  3719. fprintf(stderr, "Error: Read-only version of MP4Box.\n");
  3720. MP4BOX_EXIT_WITH_CODE(1);
  3721. #endif
  3722. err_exit:
  3723. /*close libgpac*/
  3724. if (file) gf_isom_delete(file);
  3725. fprintf(stderr, "\n\tError: %s\n", gf_error_to_string(e));
  3726. MP4BOX_EXIT_WITH_CODE(1);
  3727. }
  3728. int main( int argc, char** argv )
  3729. {
  3730. return mp4boxMain( argc, argv );
  3731. }
  3732. #endif /*GPAC_DISABLE_ISOM*/