コード例 #1
0
ファイル: external_seek_test.c プロジェクト: benob/ffmpeg-fas
int main (int argc, char **argv)
{
  fas_error_type video_error;
  fas_context_ref_type context;
  
  if (argc < 3) {
    fprintf (stderr, "usage: %s <video_file> <seek_table>\n", argv[0]);
    fail("arguments\n");
  }

  fprintf(stderr, "%s : ", argv[1]);

  seek_table_type table = read_table_file(argv[2]);
  if (table.num_entries == 0)
    fail("bad table\n");
  
  fas_initialize (FAS_FALSE, FAS_RGB24);
  
  video_error = fas_open_video (&context, argv[1]);
  if (video_error != FAS_SUCCESS)    fail("fail on open\n");
  
  video_error = fas_put_seek_table(context, table);
  if (video_error != FAS_SUCCESS)    fail("fail on put_seek_table\n");
    
  if (fas_get_frame_count(context) < 0)
    fail("n_frames = -1\n");

  if (fas_get_frame_count(context) < TEST_SET_SIZE)
      do_random_test(context, 0, fas_get_frame_count(context) - 1, N_ITERATIONS);
  else if (fas_get_frame_count(context) < TEST_SET_SIZE * 2)
    {
      do_random_test(context, 0, fas_get_frame_count(context) / 2 - 1, N_ITERATIONS / 2);
      do_random_test(context, fas_get_frame_count(context) / 2 + 1, fas_get_frame_count(context) - 1 , N_ITERATIONS / 2);   
    }
  else
    {
      do_random_test(context, 0, TEST_SET_SIZE, N_ITERATIONS / 2);
      do_random_test(context, fas_get_frame_count(context) - TEST_SET_SIZE, fas_get_frame_count(context) - 1 , N_ITERATIONS / 2);   
    }

  seek_release_table(&table);
  fas_close_video(context);
  
  success();
}
コード例 #2
0
ファイル: ffmpeg_fas.c プロジェクト: AMDmi3/ffmpeg-fas
/* fas_open_video */
fas_error_type fas_open_video (fas_context_ref_type *context_ptr, const char *file_path)
{
  int stream_idx;
  int numBytes;
  fas_context_ref_type fas_context;
  AVCodec *codec;

  if (NULL == context_ptr)
    return private_show_error("NULL context pointer provided", FAS_INVALID_ARGUMENT);

  *context_ptr = NULL; // set returned context to NULL in case of error

  fas_context = (fas_context_ref_type) malloc(sizeof(fas_context_type));
  memset(fas_context, 0, sizeof(fas_context_type));

  if (NULL == fas_context)
    return private_show_error("unable to allocate buffer", FAS_OUT_OF_MEMORY);

  fas_context->is_video_active        = FAS_TRUE;
  fas_context->is_frame_available     = FAS_TRUE;
  fas_context->current_frame_index    = FIRST_FRAME_INDEX - 1;
  fas_context->current_dts            = AV_NOPTS_VALUE;
  fas_context->previous_dts           = AV_NOPTS_VALUE;
  fas_context->keyframe_packet_dts    = AV_NOPTS_VALUE;
  fas_context->first_dts              = AV_NOPTS_VALUE;
  fas_context->seek_table = seek_init_table(-1); /* default starting size */

  if (av_open_input_file(&(fas_context->format_context), file_path, NULL, 0, NULL ) != 0)
  {
    fas_close_video(fas_context);
    return private_show_error("failure to open file", FAS_UNSUPPORTED_FORMAT);
  }

  if (av_find_stream_info (fas_context->format_context) < 0)
  {
    fas_close_video(fas_context);
    return private_show_error("could not extract stream information", FAS_UNSUPPORTED_FORMAT);
  }

  if (SHOW_WARNING_MESSAGES)
    av_dump_format(fas_context->format_context, 0, file_path, 0);

  for (stream_idx = 0; stream_idx < fas_context->format_context->nb_streams; stream_idx++)
  {
    if (fas_context->format_context->streams[stream_idx]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
    {
      fas_context->stream_idx = stream_idx;
      fas_context->codec_context  = fas_context->format_context->streams[stream_idx]->codec;
      break;
    }
  }

  if (fas_context->codec_context == 0)
  {
    fas_close_video(fas_context);
    return private_show_error("failure to find a video stream", FAS_UNSUPPORTED_FORMAT);
  }

  codec = avcodec_find_decoder(fas_context->codec_context->codec_id);

  if (!codec)
  {
    fas_context->codec_context = 0;
    fas_close_video(fas_context);
    return private_show_error("failed to find correct video codec", FAS_UNSUPPORTED_CODEC);
  }

  if (avcodec_open(fas_context->codec_context, codec) < 0)
  {
    fas_context->codec_context = 0;
    fas_close_video(fas_context);
    return private_show_error("failed to open codec", FAS_UNSUPPORTED_CODEC);
  }

  fas_context->frame_buffer = avcodec_alloc_frame();
  if (fas_context->frame_buffer == NULL)
  {
    fas_close_video(fas_context);
    return private_show_error("failed to allocate frame buffer", FAS_OUT_OF_MEMORY);
  }

  fas_context->rgb_frame_buffer = avcodec_alloc_frame();
  if (fas_context->rgb_frame_buffer == NULL)
  {
    fas_close_video(fas_context);
    return private_show_error("failed to allocate rgb frame buffer", FAS_OUT_OF_MEMORY);
  }
  numBytes = avpicture_get_size(PIX_FMT_RGB24, fas_context->codec_context->width, fas_context->codec_context->height);
  fas_context->rgb_buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
  avpicture_fill((AVPicture *)fas_context->rgb_frame_buffer, fas_context->rgb_buffer, PIX_FMT_RGB24, fas_context->codec_context->width, fas_context->codec_context->height);

  fas_context->gray8_frame_buffer = avcodec_alloc_frame();
  if (fas_context->gray8_frame_buffer == NULL)
  {
    fas_close_video(fas_context);
    return private_show_error("failed to allocate gray8 frame buffer", FAS_OUT_OF_MEMORY);
  }

  fas_context->rgb_buffer = 0;
  fas_context->gray8_buffer = 0;
  fas_context->rgb_already_converted = FAS_FALSE;
  fas_context->gray8_already_converted = FAS_FALSE;

  *context_ptr = fas_context;

  if (FAS_SUCCESS != fas_step_forward(*context_ptr))
    return private_show_error("failure decoding first frame", FAS_NO_MORE_FRAMES);

  if (!fas_frame_available(*context_ptr))
    return private_show_error("couldn't find a first frame (no valid frames in video stream)", FAS_NO_MORE_FRAMES);

  return FAS_SUCCESS;
}