PageRenderTime 52ms CodeModel.GetById 13ms 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

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

  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 G

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