Commit c5d6e879 authored by Michel Lespinasse's avatar Michel Lespinasse

adding sample1.c example file

parent ec013d50
SUBDIRS = autotools include doc libmpeg2 libvo src vc++ test
SUBDIRS = autotools include libmpeg2 libvo doc src vc++ test
EXTRA_DIST = bootstrap
EXTRA_DIST = libvo.txt
CFLAGS = @MPEG2DEC_CFLAGS@
noinst_PROGRAMS = sample1
sample1_SOURCES = sample1.c
sample1_LDADD = $(top_builddir)/libmpeg2/libmpeg2.la
EXTRA_DIST = libmpeg2.txt libvo.txt
I - simplest example
explanation of sequence_t, picture_t fields
II - w/ color conversion
III - pts
IV - app that preallocates buffers
V - app that does its own buffer management
/*
* sample1.c
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
* See http://libmpeg2.sourceforge.net/ for updates.
*
* mpeg2dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* mpeg2dec 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "mpeg2.h"
static void save_pgm (int width, int height, uint8_t * const * buf, int num)
{
char filename[100];
FILE * pgmfile;
int i;
sprintf (filename, "%d.pgm", num);
pgmfile = fopen (filename, "wb");
if (!pgmfile)
return;
fprintf (pgmfile, "P5\n\n%d %d\n255\n", width, height * 3 / 2);
fwrite (buf[0], width, height, pgmfile);
width >>= 1; height >>= 1;
for (i = 0; i < height; i++) {
fwrite (buf[1] + i * width, width, 1, pgmfile);
fwrite (buf[2] + i * width, width, 1, pgmfile);
}
fclose (pgmfile);
}
static void sample1 (FILE * file)
{
uint32_t accel;
#define BUFFER_SIZE 4096
uint8_t buffer[BUFFER_SIZE];
mpeg2dec_t * mpeg2dec;
const mpeg2_info_t * info;
uint8_t * current;
uint8_t * end;
int state;
int done;
int framenum = 0;
accel = 0;
mpeg2dec = mpeg2_init (accel);
if (mpeg2dec == NULL)
exit (1);
info = mpeg2_info (mpeg2dec);
current = buffer;
end = buffer + fread (buffer, 1, BUFFER_SIZE, file);
done = 0;
do {
state = mpeg2_buffer (mpeg2dec, &current, end);
switch (state) {
case -1:
current = buffer;
end = buffer + fread (buffer, 1, BUFFER_SIZE, file);
done = (end <= buffer);
break;
case STATE_SEQUENCE:
mpeg2_set_buf_alloc_XXX (mpeg2dec);
mpeg2_set_buf_alloc_XXX (mpeg2dec);
mpeg2_set_buf_alloc_XXX (mpeg2dec);
break;
case STATE_SLICE:
case STATE_END:
if (info->display_fbuf)
save_pgm (info->sequence->width, info->sequence->height,
info->display_fbuf->buf, framenum++);
break;
}
} while (!done);
mpeg2_close (mpeg2dec);
}
int main (int argc, char ** argv)
{
FILE * file;
if (argc > 1) {
file = fopen (argv[1], "rb");
if (!file) {
fprintf (stderr, "Could not open file %s\n", argv[1]);
exit (1);
}
} else
file = stdin;
sample1 (file);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment