*Read from an MPEG1 video file, decode frames, and generate PGM images as output.
/*
* Copyright (c) 2001 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file libavcodec video decoding API usage example
* @example decode_video.c *
*
* Read from an MPEG1 video file, decode frames, and generate PGM images as
* output.
*/
#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)
{
f = fopen(filename,
"wb");
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);
}
const char *filename)
{
char buf[1024];
fprintf(stderr, "Error sending a packet for decoding\n");
exit(1);
}
return;
fprintf(stderr, "Error during decoding\n");
exit(1);
}
fflush(stdout);
/* the picture is allocated by the decoder. no need to
free it */
}
}
int main(
int argc,
char **argv)
{
const char *filename, *outfilename;
size_t data_size;
int eof;
if (argc <= 2) {
fprintf(stderr, "Usage: %s <input file> <output file>\n"
"And check your input file is encoded by mpeg1video please.\n", argv[0]);
exit(0);
}
filename = argv[1];
outfilename = argv[2];
exit(1);
/* set end of buffer to 0 (this ensures that no overreading happens for damaged MPEG streams) */
/* find the MPEG-1 video decoder */
if (!codec) {
fprintf(stderr, "Codec not found\n");
exit(1);
}
if (!parser) {
fprintf(stderr, "parser not found\n");
exit(1);
}
fprintf(stderr, "Could not allocate video codec context\n");
exit(1);
}
/* For some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because this information is not
available in the bitstream. */
/* open it */
fprintf(stderr, "Could not open codec\n");
exit(1);
}
f = fopen(filename,
"rb");
fprintf(stderr, "Could not open %s\n", filename);
exit(1);
}
fprintf(stderr, "Could not allocate video frame\n");
exit(1);
}
do {
/* read raw data from the input file */
break;
eof = !data_size;
/* use the parser to split the data into frames */
while (data_size > 0 || eof) {
fprintf(stderr, "Error while parsing\n");
exit(1);
}
else if (eof)
break;
}
} while (!eof);
/* flush the decoder */
return 0;
}