summaryrefslogtreecommitdiff
path: root/ffmpeg-fas/test/dump_frames.c
blob: ee9406ba7363ed3dacca99c2fca7cf0ecb3e32d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*****************************************************************************
 * Copyright 2008. Pittsburgh Pattern Recognition, Inc.
 * 
 * This file is part of the Frame Accurate Seeking extension library to 
 * ffmpeg (ffmpeg-fas).
 * 
 * ffmpeg-fas is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or (at your 
 * option) any later version.
 *
 * The ffmpeg-fas library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with the ffmpeg-fas library.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/

#include "ffmpeg_fas.h"
#include "test_support.h"
#include <stdio.h>

int main (int argc, char **argv)
{
  char filename_buffer [255];
  
  fas_error_type video_error;
  fas_context_ref_type context;
  fas_raw_image_type image_buffer;
  
  if (argc < 2) {
    fprintf (stderr, "usage: %s <video_file>\n", argv[0]);
    return -1;
  }

  fas_initialize (FAS_FALSE, FAS_RGB24);
  
  fprintf(stderr, "%s : ",argv[1]);
  video_error = fas_open_video (&context, argv[1]);
  if (video_error != FAS_SUCCESS)
    fail("failed to open\n");
    
  int counter = 0;
  while (fas_frame_available (context))
    {
            
      if (FAS_SUCCESS != fas_get_frame (context, &image_buffer))
	fail("failed on rgb image\n");  

      char filename[50];
      sprintf(filename, "frame_%04d.ppm", counter);
      
      fprintf(stderr, "Writing %s (counter=%d frame_index=%d)\n", filename, counter, fas_get_frame_index(context));
      ppm_save(&image_buffer, filename);
      
      fas_free_frame (image_buffer);

      video_error = fas_step_forward (context);
      counter++;
    }

  success();

}