static int get_first_video_track( lsmash_handler_t *h, video_option_t *opt ) { if( h->audio_pcm_sample_count == 0 || h->audio_format.Format.nSamplesPerSec == 0 ) return -1; /* Only available if audio stream is present. */ if( opt->dummy.framerate_den == 0 ) return -1; h->framerate_num = opt->dummy.framerate_num; h->framerate_den = opt->dummy.framerate_den; h->video_sample_count = ((uint64_t)h->framerate_num * h->audio_pcm_sample_count - 1) / ((uint64_t)h->framerate_den * h->audio_format.Format.nSamplesPerSec) + 1; static const struct { int pixel_size; output_colorspace_tag compression; } colorspace_table[3] = { { YUY2_SIZE, OUTPUT_TAG_YUY2 }, { RGB24_SIZE, OUTPUT_TAG_RGB }, { YC48_SIZE, OUTPUT_TAG_YC48 } }; int linesize = MAKE_AVIUTL_PITCH( opt->dummy.width * (colorspace_table[ opt->dummy.colorspace ].pixel_size << 3) ); dummy_handler_t *hp = (dummy_handler_t *)h->video_private; hp->dummy_size = linesize * opt->dummy.height; if( hp->dummy_size <= 0 ) return -1; hp->dummy_data = lw_malloc_zero( hp->dummy_size ); if( !hp->dummy_data ) return -1; uint8_t *pic = hp->dummy_data; switch( colorspace_table[ opt->dummy.colorspace ].compression ) { case OUTPUT_TAG_YC48 : case OUTPUT_TAG_RGB : break; case OUTPUT_TAG_YUY2 : for( int i = 0; i < opt->dummy.height; i++ ) { for( int j = 0; j < linesize; j += 2 ) { pic[j ] = 0; pic[j + 1] = 128; } pic += linesize; } break; default : lw_freep( &hp->dummy_data ); return -1; } /* BITMAPINFOHEADER */ h->video_format.biSize = sizeof( BITMAPINFOHEADER ); h->video_format.biWidth = opt->dummy.width; h->video_format.biHeight = opt->dummy.height; h->video_format.biBitCount = colorspace_table[ opt->dummy.colorspace ].pixel_size << 3; h->video_format.biCompression = colorspace_table[ opt->dummy.colorspace ].compression; return 0; }
static int read_video( lsmash_handler_t *h, int sample_number, void *buf ) { avs_handler_t *hp = (avs_handler_t *)h->video_private; int buf_linesize = MAKE_AVIUTL_PITCH( hp->vi->width * avs_bits_per_pixel( hp->vi ) ); AVS_VideoFrame *frame = hp->func.avs_get_frame( hp->clip, sample_number ); if( hp->func.avs_clip_get_error( hp->clip ) ) return 0; hp->func.avs_bit_blt( hp->env, buf, buf_linesize, avs_get_read_ptr( frame ), avs_get_pitch( frame ), avs_get_row_size( frame ), hp->vi->height ); hp->func.avs_release_video_frame( frame ); return avs_bmp_size( hp->vi ); }