1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010 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 int print_help( int ret
)
38 eprintf( "Usage: boxdumper [option] input\n"
40 " --box Dump box structure\n"
41 " --timestamp Dump media timestamps\n" );
45 static int boxdumper_error( lsmash_root_t
*root
, char* message
)
47 lsmash_destroy_root( root
);
52 #define BOXDUMPER_ERR( message ) boxdumper_error( root, message )
55 int main( int argc
, char *argv
[] )
57 if( argc
< 2 || argc
> 3 )
58 return print_help( -1 );
63 if( !strcasecmp( argv
[1], "--box" ) )
65 else if( !strcasecmp( argv
[1], "--timestamp" ) )
68 return print_help( -1 );
73 if( !strcasecmp( argv
[1], "-h" ) || !strcasecmp( argv
[1], "--help" ) )
74 return print_help( 0 );
78 _setmode( _fileno(stdin
), _O_BINARY
);
80 lsmash_file_mode mode
= dump_box
? (LSMASH_FILE_MODE_READ
| LSMASH_FILE_MODE_DUMP
) : LSMASH_FILE_MODE_READ
;
81 lsmash_root_t
*root
= lsmash_open_movie( filename
, mode
);
84 fprintf( stderr
, "Failed to open input file.\n" );
89 if( lsmash_print_movie( root
) )
90 return BOXDUMPER_ERR( "Failed to dump box structure.\n" );
94 lsmash_movie_parameters_t movie_param
;
95 lsmash_initialize_movie_parameters( &movie_param
);
96 lsmash_get_movie_parameters( root
, &movie_param
);
97 uint32_t num_tracks
= movie_param
.number_of_tracks
;
98 for( uint32_t track_number
= 1; track_number
<= num_tracks
; track_number
++ )
100 uint32_t track_ID
= lsmash_get_track_ID( root
, track_number
);
102 return BOXDUMPER_ERR( "Failed to get track_ID.\n" );
103 lsmash_media_parameters_t media_param
;
104 lsmash_initialize_media_parameters( &media_param
);
105 if( lsmash_get_media_parameters( root
, track_ID
, &media_param
) )
106 return BOXDUMPER_ERR( "Failed to get media parameters.\n" );
107 if( lsmash_construct_timeline( root
, track_ID
) )
108 return BOXDUMPER_ERR( "Failed to construct timeline.\n" );
109 int32_t timeline_shift
;
110 if( lsmash_get_media_timeline_shift( root
, track_ID
, &timeline_shift
) )
111 return BOXDUMPER_ERR( "Failed to get timestamps.\n" );
112 lsmash_media_ts_list_t ts_list
;
113 if( lsmash_get_media_timestamps( root
, track_ID
, &ts_list
) )
114 return BOXDUMPER_ERR( "Failed to get timestamps.\n" );
115 fprintf( stdout
, "track_ID: %"PRIu32
"\n", track_ID
);
116 fprintf( stdout
, "Media timescale: %"PRIu32
"\n", media_param
.timescale
);
117 lsmash_media_ts_t
*ts_array
= ts_list
.timestamp
;
120 fprintf( stdout
, "\n" );
123 for( uint32_t i
= 0; i
< ts_list
.sample_count
; i
++ )
124 fprintf( stdout
, "DTS = %"PRIu64
", CTS = %"PRIu64
"\n", ts_array
[i
].dts
, ts_array
[i
].cts
+ timeline_shift
);
126 fprintf( stdout
, "\n" );
129 lsmash_destroy_root( root
);