36 #define INBUF_SIZE 4096
44 f = fopen(filename,
"w");
45 fprintf(f,
"P5\n%d %d\n%d\n", xsize, ysize, 255);
46 for (i = 0; i < ysize; i++)
47 fwrite(buf + i * wrap, 1, xsize, f);
59 fprintf(stderr,
"Error while decoding frame %d\n", *frame_count);
63 printf(
"Saving %sframe %3d\n", last ?
"last " :
"", *frame_count);
67 snprintf(buf,
sizeof(buf),
"%s-%d", outfilename, *frame_count);
79 int main(
int argc,
char **argv)
81 const char *filename, *outfilename;
91 fprintf(stderr,
"Usage: %s <input file> <output file>\n", argv[0]);
95 outfilename = argv[2];
107 fprintf(stderr,
"Codec not found\n");
113 fprintf(stderr,
"Could not allocate video codec context\n");
126 fprintf(stderr,
"Could not open codec\n");
130 f = fopen(filename,
"rb");
132 fprintf(stderr,
"Could not open %s\n", filename);
138 fprintf(stderr,
"Could not allocate video frame\n");
164 while (avpkt.
size > 0)
This structure describes decoded (raw) audio or video data.
static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename)
int main(int argc, char **argv)
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int width
width and height of the video frame
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int capabilities
Codec capabilities.
int flags
AV_CODEC_FLAG_*.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Libavcodec external API header.
attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
static int decode_write_frame(const char *outfilename, AVCodecContext *avctx, AVFrame *frame, int *frame_count, AVPacket *pkt, int last)
#define AV_CODEC_CAP_TRUNCATED
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
This structure stores compressed data.