File: easympeg.c

package info (click to toggle)
libmpeg1 1.2.2-4
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 736 kB
  • ctags: 637
  • sloc: ansic: 8,415; sh: 1,328; makefile: 123
file content (92 lines) | stat: -rw-r--r-- 2,170 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * The World's Easiest MPEG Player -- a demonstration of the MPEG Library,
 * written for Silicon Graphics machines.  Demonstrates basic use of 
 * the MPEG Library, in either true-colour or colour-mapped dithering
 * modes.  Yes, it is possible to write an MPEG player in less than
 * 100 lines of code...
 *
 * Masochists may port to X (or whatever) if desired.
 *
 * By Greg Ward, 94/8/15
 *   modified for colour-mapped modes, March '95.
 */

#include <stdlib.h>
#include <errno.h>
#include <gl.h>
#define BOOLEAN_TYPE_EXISTS
#include "mpeg.h"


int main (int argc, char *argv[])
{
   FILE       *mpeg;
   ImageDesc   img;
   char       *pixels;
   Boolean     moreframes = TRUE;
   Boolean     full_color = TRUE;
   Boolean     loop = TRUE;
   
   if (argc != 2) 
   {
      fprintf (stderr, "Usage: %s mpegfile\n", argv[0]);
      exit (1);
   }

   mpeg = fopen (argv[1], "r");
   if (!mpeg)
   {
      perror (argv[1]);
      exit (1);
   }
      
   SetMPEGOption (MPEG_DITHER, 
		  (full_color) ? (int) FULL_COLOR_DITHER : 
		                 (int) ORDERED_DITHER);
   if (!OpenMPEG (mpeg, &img))
   {
      fprintf (stderr, "OpenMPEG on %s failed\n", argv[1]);
      exit (1);
   }

   pixels = (char *) malloc (img.Size * sizeof(char));
   printf ("Movie is %d x %d pixels\n", img.Width, img.Height);
   printf ("Required picture rate = %d, required bit rate = %d\n",
	   img.PictureRate, img.BitRate);

   foreground ();
   prefsize (img.Width, img.Height);
   winopen ("Easy MPEG");
   if (full_color) RGBmode ();
   pixmode (PM_SIZE, img.PixelSize);
   pixmode (PM_TTOB, 1);
   gconfig ();
   clear ();

   if (!full_color)
   {
      int  i;

      for (i = 0; i < img.ColormapSize; i++)
      {
	 mapcolor (i, 
		   img.Colormap[i].red, 
		   img.Colormap[i].green, 
		   img.Colormap[i].blue);
      }
      gflush ();
   }
   
   while (loop)			/* play the whole movie forever */
   {
      while (moreframes)	/* play frames until the movie ends */
      {
	 moreframes = GetMPEGFrame (pixels);
	 lrectwrite (0, 0, img.Width-1, img.Height-1,
		     (unsigned long *) pixels);
      }

      RewindMPEG (mpeg, &img);
      moreframes = TRUE;
   }
}