Ejemplo n.º 1
0
int fas_get_frame_count (fas_context_ref_type context)
{
  int current_frame;
  int fast;
  fas_error_type fas_error;

  fast = fas_get_frame_count_fast(context);
  if (fast >= 0)
    return fast;

  current_frame = fas_get_frame_index(context);


  fas_error = private_complete_seek_table(context);
  if (FAS_SUCCESS != fas_error)
  {
    private_show_error("failed in get_frame_count trying to complete the seek table", fas_error);
    return -1;
  }

  //  seek_show_raw_table(stderr, context->seek_table);

  fas_error = fas_seek_to_frame(context, current_frame);
  if (FAS_SUCCESS != fas_error)
  {
    private_show_error("failed in get_frame_count when trying to seek back to original location", fas_error);
    return -1;
  }

  fast = fas_get_frame_count_fast(context);
  if (fast < 0)
    private_show_warning("get_frame_count failed");

  return fast;
}
Ejemplo n.º 2
0
int main (int argc, char **argv)
{
  char * out_dir;
  char out_file[128];
  int i;
  seek_table_type table;
  fas_error_type video_error;
  fas_context_ref_type context, seek_context;

  cmdname = argv[0];

  if (argc < 3) {
    show_help();
    fail("arguments\n");
  }

  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");

  video_error = fas_open_video (&seek_context, argv[1]);
  if (video_error != FAS_SUCCESS)    fail("fail on open\n");


  if (argc >= 4) {
    out_dir = argv[3];
    create_dir(out_dir);
  } else {
    out_dir = ".";
  }

  for(i=0;i<table.num_entries;i++)
    {
      fas_raw_image_type image_buffer;
      //      int frame_index = table.array[table.num_entries - i - 1].display_index;
      int frame_index = table.array[i].display_index;
      if (FAS_SUCCESS != fas_seek_to_frame(context, frame_index))
	fail("failed on seek");

      if (FAS_SUCCESS != fas_get_frame (context, &image_buffer))
	fail("failed on rgb image\n");

      sprintf(out_file, "%s/frame_%04d.ppm", out_dir, frame_index);

      fprintf(stderr, "Writing %s (seek_table_value=%d frame_index=%d)\n", out_file, frame_index, fas_get_frame_index(context));
      ppm_save(&image_buffer, out_file);

      fas_free_frame (image_buffer);
    }

  success();
}
Ejemplo n.º 3
0
void do_random_test(fas_context_ref_type context, int start, int stop, int count)
{
  //  printf ("start: %d  stop: %d\n", start, stop );

  while (fas_get_frame_index(context) < start)
    if (FAS_SUCCESS != fas_step_forward(context))
      fail("failed on advancement\n");

  fas_raw_image_type *ref_frames = malloc( (stop - start + 1)* sizeof(fas_raw_image_type));
  
  int i;
  fas_error_type video_error;

  while (fas_get_frame_index(context) <= stop)
    {
      i = fas_get_frame_index(context) - start;

      video_error = fas_get_frame(context, &(ref_frames[i]));
      if (video_error != FAS_SUCCESS)    fail("fail on test(1)\n");

      video_error = fas_step_forward(context);
      if (video_error != FAS_SUCCESS)    fail("fail on test(2)\n");

    }

  int index = -1;
  int prev_index;

  for (i=0;i<count;i++)
    {
      int offset = random() % (stop - start + 1);
      prev_index = index;
      index = start + offset;

      video_error = fas_seek_to_frame(context, index);
      if (video_error != FAS_SUCCESS)    fail("fail on test(seek)\n");


      fas_raw_image_type test_frame;
      video_error = fas_get_frame(context, &test_frame);
      if (video_error != FAS_SUCCESS)    fail("fail on test(seek2)\n");

      //      printf("offset: %d / %d\n", offset, stop - start + 1);
      
      if (!compare_frames(test_frame, ref_frames[offset]))
	{	  
	  char buffer[70];
	  
	  sprintf(buffer, "fail-%d-test.ppm", index);
	  ppm_save(&test_frame, buffer);
	  sprintf(buffer, "fail-%d-ref.ppm", index);
	  ppm_save(&ref_frames[offset], buffer);
	  sprintf(buffer, "failed on compare after seeking (%d->%d)\n", prev_index, index);
	  
	  fail(buffer);
	}
      
      fas_free_frame(test_frame);
    }
  
  for (i=0;i<stop - start + 1;i++)
    free(ref_frames[i].data);
    
  free(ref_frames);
}