static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) { *p_handle = NULL; int b_regular = strcmp( psz_filename, "-" ); b_regular = b_regular && x264_is_regular_file_path( psz_filename ); if( b_regular ) { FILE *fh = x264_fopen( psz_filename, "wb" ); MP4_FAIL_IF_ERR( !fh, "cannot open output file `%s'.\n", psz_filename ); b_regular = x264_is_regular_file( fh ); fclose( fh ); } mp4_hnd_t *p_mp4 = calloc( 1, sizeof(mp4_hnd_t) ); MP4_FAIL_IF_ERR( !p_mp4, "failed to allocate memory for muxer information.\n" ); p_mp4->b_dts_compress = opt->use_dts_compress; p_mp4->b_use_recovery = 0; // we don't really support recovery p_mp4->b_fragments = !b_regular; p_mp4->b_stdout = !strcmp( psz_filename, "-" ); p_mp4->p_root = lsmash_open_movie( psz_filename, p_mp4->b_fragments ? LSMASH_FILE_MODE_WRITE_FRAGMENTED : LSMASH_FILE_MODE_WRITE ); MP4_FAIL_IF_ERR_EX( !p_mp4->p_root, "failed to create root.\n" ); p_mp4->summary = (lsmash_video_summary_t *)lsmash_create_summary( LSMASH_SUMMARY_TYPE_VIDEO ); MP4_FAIL_IF_ERR_EX( !p_mp4->summary, "failed to allocate memory for summary information of video.\n" ); p_mp4->summary->sample_type = ISOM_CODEC_TYPE_AVC1_VIDEO; *p_handle = p_mp4; return 0; }
static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) { mp4_hnd_t *p_mp4; *p_handle = NULL; int b_regular = strcmp( psz_filename, "-" ); b_regular = b_regular && x264_is_regular_file_path( psz_filename ); if( b_regular ) { FILE *fh = x264_fopen( psz_filename, "wb" ); MP4_FAIL_IF_ERR( !fh, "cannot open output file `%s'.\n", psz_filename ); b_regular = x264_is_regular_file( fh ); fclose( fh ); } p_mp4 = malloc( sizeof(mp4_hnd_t) ); MP4_FAIL_IF_ERR( !p_mp4, "failed to allocate memory for muxer information.\n" ); memset( p_mp4, 0, sizeof(mp4_hnd_t) ); p_mp4->b_dts_compress = opt->use_dts_compress; p_mp4->b_use_recovery = 0; p_mp4->b_no_pasp = 0; p_mp4->scale_method = ISOM_SCALE_METHOD_MEET; p_mp4->b_fragments = !b_regular; p_mp4->b_stdout = !strcmp( psz_filename, "-" ); char* ext = get_filename_extension( psz_filename ); if( !strcmp( ext, "mov" ) || !strcmp( ext, "qt" ) ) { p_mp4->major_brand = ISOM_BRAND_TYPE_QT; p_mp4->b_brand_qt = 1; } else if( !strcmp( ext, "3gp" ) ) { p_mp4->major_brand = ISOM_BRAND_TYPE_3GP6; p_mp4->i_brand_3gpp = 1; } else if( !strcmp( ext, "3g2" ) ) { p_mp4->major_brand = ISOM_BRAND_TYPE_3G2A; p_mp4->i_brand_3gpp = 2; } else p_mp4->major_brand = ISOM_BRAND_TYPE_MP42; p_mp4->p_root = lsmash_open_movie( psz_filename, p_mp4->b_fragments ? LSMASH_FILE_MODE_WRITE_FRAGMENTED : LSMASH_FILE_MODE_WRITE ); MP4_FAIL_IF_ERR_EX( !p_mp4->p_root, "failed to create root.\n" ); p_mp4->summary = (lsmash_video_summary_t *)lsmash_create_summary( LSMASH_SUMMARY_TYPE_VIDEO ); MP4_FAIL_IF_ERR_EX( !p_mp4->summary, "failed to allocate memory for summary information of video.\n" ); p_mp4->summary->sample_type = ISOM_CODEC_TYPE_AVC1_VIDEO; *p_handle = p_mp4; return 0; }
uint32_t LSMASHVideoSource::open_file( const char *source, IScriptEnvironment *env ) { /* L-SMASH */ vdh.root = lsmash_open_movie( source, LSMASH_FILE_MODE_READ ); if( !vdh.root ) env->ThrowError( "LSMASHVideoSource: failed to lsmash_open_movie." ); lsmash_movie_parameters_t movie_param; lsmash_initialize_movie_parameters( &movie_param ); lsmash_get_movie_parameters( vdh.root, &movie_param ); if( movie_param.number_of_tracks == 0 ) env->ThrowError( "LSMASHVideoSource: the number of tracks equals 0." ); /* libavformat */ av_register_all(); avcodec_register_all(); if( avformat_open_input( &format_ctx, source, NULL, NULL ) ) env->ThrowError( "LSMASHVideoSource: failed to avformat_open_input." ); if( avformat_find_stream_info( format_ctx, NULL ) < 0 ) env->ThrowError( "LSMASHVideoSource: failed to avformat_find_stream_info." ); /* */ lw_log_handler_t *lhp = &vdh.config.lh; lhp->level = LW_LOG_FATAL; lhp->show_log = throw_error; return movie_param.number_of_tracks; }
int main( int argc, char *argv[] ) { if( argc < 2 ) return print_help( -1 ); int dump_box = 1; int chapter = 0; char *filename; if( argc > 2 ) { if( !strcasecmp( argv[1], "--box" ) ) DO_NOTHING; else if( !strcasecmp( argv[1], "--chapter" ) ) chapter = 1; else if( !strcasecmp( argv[1], "--timestamp" ) ) dump_box = 0; else return print_help( -1 ); filename = argv[2]; } else { if( !strcasecmp( argv[1], "-h" ) || !strcasecmp( argv[1], "--help" ) ) return print_help( 0 ); filename = argv[1]; } #ifdef _WIN32 _setmode( _fileno(stdin), _O_BINARY ); #endif lsmash_file_mode mode = LSMASH_FILE_MODE_READ; if( dump_box ) mode |= LSMASH_FILE_MODE_DUMP; lsmash_root_t *root = lsmash_open_movie( filename, mode ); if( !root ) { fprintf( stderr, "Failed to open input file.\n" ); return -1; } if( chapter ) { if( lsmash_print_chapter_list( root ) ) return BOXDUMPER_ERR( "Failed to extract chapter.\n" ); } else if( dump_box ) { if( lsmash_print_movie( root, "-" ) ) return BOXDUMPER_ERR( "Failed to dump box structure.\n" ); } else { lsmash_movie_parameters_t movie_param; lsmash_initialize_movie_parameters( &movie_param ); lsmash_get_movie_parameters( root, &movie_param ); uint32_t num_tracks = movie_param.number_of_tracks; for( uint32_t track_number = 1; track_number <= num_tracks; track_number++ ) { uint32_t track_ID = lsmash_get_track_ID( root, track_number ); if( !track_ID ) return BOXDUMPER_ERR( "Failed to get track_ID.\n" ); lsmash_media_parameters_t media_param; lsmash_initialize_media_parameters( &media_param ); if( lsmash_get_media_parameters( root, track_ID, &media_param ) ) return BOXDUMPER_ERR( "Failed to get media parameters.\n" ); if( lsmash_construct_timeline( root, track_ID ) ) return BOXDUMPER_ERR( "Failed to construct timeline.\n" ); uint32_t timeline_shift; if( lsmash_get_composition_to_decode_shift_from_media_timeline( root, track_ID, &timeline_shift ) ) return BOXDUMPER_ERR( "Failed to get timestamps.\n" ); lsmash_media_ts_list_t ts_list; if( lsmash_get_media_timestamps( root, track_ID, &ts_list ) ) return BOXDUMPER_ERR( "Failed to get timestamps.\n" ); fprintf( stdout, "track_ID: %"PRIu32"\n", track_ID ); fprintf( stdout, "Media timescale: %"PRIu32"\n", media_param.timescale ); lsmash_media_ts_t *ts_array = ts_list.timestamp; if( !ts_array ) { fprintf( stdout, "\n" ); continue; } for( uint32_t i = 0; i < ts_list.sample_count; i++ ) fprintf( stdout, "DTS = %"PRIu64", CTS = %"PRIu64"\n", ts_array[i].dts, ts_array[i].cts + timeline_shift ); free( ts_array ); fprintf( stdout, "\n" ); } } lsmash_destroy_root( root ); return 0; }