Exemple #1
0
static int read_frame( cli_pic_t *pic, hnd_t handle, int i_frame )
{
    raw_hnd_t *h = handle;

    if( h->use_mmap )
    {
        pic->img.plane[0] = x264_cli_mmap( &h->mmap, i_frame * h->frame_size, h->frame_size );
        if( !pic->img.plane[0] )
            return -1;
    }
    else if( i_frame > h->next_frame )
    {
        if( x264_is_regular_file( h->fh ) )
            fseek( h->fh, i_frame * h->frame_size, SEEK_SET );
        else
            while( i_frame > h->next_frame )
            {
                if( read_frame_internal( pic, h, 0 ) )
                    return -1;
                h->next_frame++;
            }
    }

    if( read_frame_internal( pic, h, h->bit_depth & 7 ) )
        return -1;

    h->next_frame = i_frame+1;
    return 0;
}
Exemple #2
0
gavl_source_status_t
gavl_audio_source_read_frame(void * sp, gavl_audio_frame_t ** frame)
  {
  gavl_audio_source_t * s = sp;
  if(!(s->flags & FLAG_DST_SET))
    gavl_audio_source_set_dst(s, 0, NULL);
  return read_frame_internal(s, frame, s->dst_format.samples_per_frame);
  }
Exemple #3
0
int gavl_audio_source_read_samples(void * sp, gavl_audio_frame_t * frame,
                                   int num_samples)
  {
  gavl_audio_source_t * s = sp;
  if(!(s->flags & FLAG_DST_SET))
    gavl_audio_source_set_dst(s, 0, NULL);
  
  s->flags &= ~FLAG_PASSTHROUGH;
  if(read_frame_internal(s, &frame, num_samples) != GAVL_SOURCE_OK)
    return 0;
  return frame->valid_samples;
  }
Exemple #4
0
static int read_frame( cli_pic_t *pic, hnd_t handle, int i_frame )
{
    y4m_hnd_t *h = handle;

    if( i_frame > h->next_frame )
    {
        if( x264_is_regular_file( h->fh ) )
            fseek( h->fh, h->frame_size * i_frame + h->seq_header_len, SEEK_SET );
        else
            while( i_frame > h->next_frame )
            {
                if( read_frame_internal( pic, h ) )
                    return -1;
                h->next_frame++;
            }
    }

    if( read_frame_internal( pic, h ) )
        return -1;

    h->next_frame = i_frame+1;
    return 0;
}
Exemple #5
0
static int read_frame( cli_pic_t *pic, hnd_t handle, int i_frame )
{
    raw_hnd_t *h = (raw_hnd_t*)handle;

    if( i_frame > h->next_frame )
    {
        if( x264_is_regular_file( h->fh ) )
            fseek( h->fh, i_frame * h->frame_size, SEEK_SET );
        else
            while( i_frame > h->next_frame )
            {
                if( read_frame_internal( pic, h ) )
                    return -1;
                h->next_frame++;
            }
    }

    if( read_frame_internal( pic, h ) )
        return -1;

    h->next_frame = i_frame+1;
    return 0;
}
Exemple #6
0
static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame )
{
    yuv_hnd_t *h = handle;

    if( i_frame > h->next_frame )
    {
        if( x264_is_regular_file( h->fh ) )
            fseek( h->fh, (uint64_t)i_frame * h->width * h->height * 3 / 2, SEEK_SET );
        else
            while( i_frame > h->next_frame )
            {
                if( read_frame_internal( p_pic, h ) )
                    return -1;
                h->next_frame++;
            }
    }

    if( read_frame_internal( p_pic, h ) )
        return -1;

    h->next_frame = i_frame+1;
    return 0;
}
Exemple #7
0
static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame )
{
    return read_frame_internal( p_pic, handle, i_frame, NULL );
}
Exemple #8
0
static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
{
    lavf_hnd_t *h = malloc( sizeof(lavf_hnd_t) );
    if( !h )
        return -1;
    av_register_all();
    h->scaler = NULL;
    if( !strcmp( psz_filename, "-" ) )
        psz_filename = "pipe:";

    if( av_open_input_file( &h->lavf, psz_filename, NULL, 0, NULL ) )
    {
        fprintf( stderr, "lavf [error]: could not open input file\n" );
        return -1;
    }

    if( av_find_stream_info( h->lavf ) < 0 )
    {
        fprintf( stderr, "lavf [error]: could not find input stream info\n" );
        return -1;
    }

    int i = 0;
    while( i < h->lavf->nb_streams && h->lavf->streams[i]->codec->codec_type != CODEC_TYPE_VIDEO )
        i++;
    if( i == h->lavf->nb_streams )
    {
        fprintf( stderr, "lavf [error]: could not find video stream\n" );
        return -1;
    }
    h->stream_id       = i;
    h->next_frame      = 0;
    h->pts_offset_flag = 0;
    h->pts_offset      = 0;
    AVCodecContext *c  = h->lavf->streams[i]->codec;
    h->init_width      = h->cur_width  = info->width  = c->width;
    h->init_height     = h->cur_height = info->height = c->height;
    h->cur_pix_fmt     = c->pix_fmt;
    info->fps_num      = h->lavf->streams[i]->r_frame_rate.num;
    info->fps_den      = h->lavf->streams[i]->r_frame_rate.den;
    info->timebase_num = h->lavf->streams[i]->time_base.num;
    info->timebase_den = h->lavf->streams[i]->time_base.den;
    h->vfr_input       = info->vfr;
    h->vertical_flip   = 0;

    /* avisynth stores rgb data vertically flipped. */
    if( !strcasecmp( get_filename_extension( psz_filename ), "avs" ) &&
        (h->cur_pix_fmt == PIX_FMT_BGRA || h->cur_pix_fmt == PIX_FMT_BGR24) )
        info->csp |= X264_CSP_VFLIP;

    if( h->cur_pix_fmt != PIX_FMT_YUV420P )
        fprintf( stderr, "lavf [warning]: converting from %s to YV12\n",
                 avcodec_get_pix_fmt_name( h->cur_pix_fmt ) );

    if( avcodec_open( c, avcodec_find_decoder( c->codec_id ) ) )
    {
        fprintf( stderr, "lavf [error]: could not find decoder for video stream\n" );
        return -1;
    }

    /* prefetch the first frame and set/confirm flags */
    h->first_pic = malloc( sizeof(x264_picture_t) );
    if( !h->first_pic || lavf_input.picture_alloc( h->first_pic, info->csp, info->width, info->height ) )
    {
        fprintf( stderr, "lavf [error]: malloc failed\n" );
        return -1;
    }
    else if( read_frame_internal( h->first_pic, h, 0, info ) )
        return -1;

    info->sar_height = c->sample_aspect_ratio.den;
    info->sar_width  = c->sample_aspect_ratio.num;
    *p_handle = h;

    return 0;
}