1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010-2015 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
34 #define eprintf( ... ) fprintf( stderr, __VA_ARGS__ )
36 static void display_version( void )
39 "L-SMASH isom/mov structual analyzer rev%s %s\n"
41 "Copyright (C) 2010-2015 L-SMASH project\n",
42 LSMASH_REV
, LSMASH_GIT_HASH
, __DATE__
, __TIME__
);
45 static void display_help( void )
49 "Usage: boxdumper [option] input\n"
51 " --help Display help\n"
52 " --version Display version information\n"
53 " --box Dump box structure\n"
54 " --chapter Extract chapter list\n"
55 " --timestamp Dump media timestamps\n" );
58 static int boxdumper_error
61 lsmash_file_parameters_t
*file_param
,
65 lsmash_close_file( file_param
);
66 lsmash_destroy_root( root
);
67 eprintf( "%s", message
);
71 #define BOXDUMPER_ERR( message ) boxdumper_error( root, &file_param, message )
74 int main( int argc
, char *argv
[] )
81 else if( !strcasecmp( argv
[1], "-h" ) || !strcasecmp( argv
[1], "--help" ) )
86 else if( !strcasecmp( argv
[1], "-v" ) || !strcasecmp( argv
[1], "--version" ) )
94 lsmash_get_mainargs( &argc
, &argv
);
97 if( !strcasecmp( argv
[1], "--box" ) )
99 else if( !strcasecmp( argv
[1], "--chapter" ) )
101 else if( !strcasecmp( argv
[1], "--timestamp" ) )
114 /* Open the input file. */
115 lsmash_root_t
*root
= lsmash_create_root();
118 fprintf( stderr
, "Failed to create a ROOT.\n" );
121 lsmash_file_parameters_t file_param
= { 0 };
122 if( lsmash_open_file( filename
, 1, &file_param
) < 0 )
123 return BOXDUMPER_ERR( "Failed to open an input file.\n" );
125 file_param
.mode
|= LSMASH_FILE_MODE_DUMP
;
126 lsmash_file_t
*file
= lsmash_set_file( root
, &file_param
);
128 return BOXDUMPER_ERR( "Failed to add a file into a ROOT.\n" );
129 if( lsmash_read_file( file
, &file_param
) < 0 )
130 return BOXDUMPER_ERR( "Failed to read a file\n" );
131 /* Dump the input file. */
134 if( lsmash_print_chapter_list( root
) )
135 return BOXDUMPER_ERR( "Failed to extract chapter.\n" );
139 if( lsmash_print_movie( root
, "-" ) )
140 return BOXDUMPER_ERR( "Failed to dump box structure.\n" );
144 lsmash_movie_parameters_t movie_param
;
145 lsmash_initialize_movie_parameters( &movie_param
);
146 lsmash_get_movie_parameters( root
, &movie_param
);
147 uint32_t num_tracks
= movie_param
.number_of_tracks
;
148 for( uint32_t track_number
= 1; track_number
<= num_tracks
; track_number
++ )
150 uint32_t track_ID
= lsmash_get_track_ID( root
, track_number
);
152 return BOXDUMPER_ERR( "Failed to get track_ID.\n" );
153 lsmash_media_parameters_t media_param
;
154 lsmash_initialize_media_parameters( &media_param
);
155 if( lsmash_get_media_parameters( root
, track_ID
, &media_param
) )
156 return BOXDUMPER_ERR( "Failed to get media parameters.\n" );
157 if( lsmash_construct_timeline( root
, track_ID
) )
158 return BOXDUMPER_ERR( "Failed to construct timeline.\n" );
159 uint32_t timeline_shift
;
160 if( lsmash_get_composition_to_decode_shift_from_media_timeline( root
, track_ID
, &timeline_shift
) )
161 return BOXDUMPER_ERR( "Failed to get timestamps.\n" );
162 lsmash_media_ts_list_t ts_list
;
163 if( lsmash_get_media_timestamps( root
, track_ID
, &ts_list
) )
164 return BOXDUMPER_ERR( "Failed to get timestamps.\n" );
165 fprintf( stdout
, "track_ID: %"PRIu32
"\n", track_ID
);
166 fprintf( stdout
, "Media timescale: %"PRIu32
"\n", media_param
.timescale
);
167 lsmash_media_ts_t
*ts_array
= ts_list
.timestamp
;
170 fprintf( stdout
, "\n" );
173 for( uint32_t i
= 0; i
< ts_list
.sample_count
; i
++ )
174 fprintf( stdout
, "DTS = %"PRIu64
", CTS = %"PRIu64
"\n", ts_array
[i
].dts
, ts_array
[i
].cts
+ timeline_shift
);
175 lsmash_free( ts_array
);
176 fprintf( stdout
, "\n" );
179 lsmash_destroy_root( root
);