#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INBUF_SIZE 4096
static
void
pgm_save
(
unsigned
char
*
buf
,
int
wrap
,
int
xsize,
int
ysize,
char
*filename)
FILE *f;
int
i;
f = fopen(filename,
"w"
);
fprintf(f,
"P5\n%d %d\n%d\n"
, xsize, ysize, 255);
for
(i = 0; i < ysize; i++)
fwrite(buf + i * wrap, 1, xsize, f);
fclose(f);
const
char
*filename)
int
ret;
if
(ret < 0) {
fprintf(stderr,
"Error sending a packet for decoding\n"
);
exit(1);
while
(ret >= 0) {
return
;
else
if
(ret < 0) {
fprintf(stderr,
"Error during decoding\n"
);
exit(1);
fflush(stdout);
int
main
(
int
argc,
char
**argv)
const
char
*filename, *outfilename;
FILE *f;
size_t
data_size;
int
ret;
if
(argc <= 2) {
fprintf(stderr,
"Usage: %s <input file> <output file>\n"
, argv[0]);
exit(0);
filename = argv[1];
outfilename = argv[2];
if
(!pkt)
exit(1);
if
(!codec) {
fprintf(stderr,
"Codec not found\n"
);
exit(1);
if
(!parser) {
fprintf(stderr,
"parser not found\n"
);
exit(1);
if
(!c) {
fprintf(stderr,
"Could not allocate video codec context\n"
);
exit(1);
fprintf(stderr,
"Could not open codec\n"
);
exit(1);
f = fopen(filename,
"rb"
);
if
(!f) {
fprintf(stderr,
"Could not open %s\n"
, filename);
exit(1);
if
(!frame) {
fprintf(stderr,
"Could not allocate video frame\n"
);
exit(1);
while
(!feof(f)) {
if
(!data_size)
break
;
data = inbuf;
while
(data_size > 0) {
if
(ret < 0) {
fprintf(stderr,
"Error while parsing\n"
);
exit(1);
data += ret;
data_size -= ret;
decode
(c, frame, pkt, outfilename);
fclose(f);
return
0;