MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / video_decode_example

Function video_decode_example

libavcodec/api-example.c:324–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324static void video_decode_example(const char *outfilename, const char *filename)
325{
326 AVCodec *codec;
327 AVCodecContext *c= NULL;
328 int frame, got_picture, len;
329 FILE *f;
330 AVFrame *picture;
331 uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
332 char buf[1024];
333 AVPacket avpkt;
334
335 av_init_packet(&avpkt);
336
337 /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
338 memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
339
340 printf("Video decoding\n");
341
342 /* find the mpeg1 video decoder */
343 codec = avcodec_find_decoder(CODEC_ID_MPEG1VIDEO);
344 if (!codec) {
345 fprintf(stderr, "codec not found\n");
346 exit(1);
347 }
348
349 c= avcodec_alloc_context();
350 picture= avcodec_alloc_frame();
351
352 if(codec->capabilities&CODEC_CAP_TRUNCATED)
353 c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
354
355 /* For some codecs, such as msmpeg4 and mpeg4, width and height
356 MUST be initialized there because this information is not
357 available in the bitstream. */
358
359 /* open it */
360 if (avcodec_open(c, codec) < 0) {
361 fprintf(stderr, "could not open codec\n");
362 exit(1);
363 }
364
365 /* the codec gives us the frame size, in samples */
366
367 f = fopen(filename, "rb");
368 if (!f) {
369 fprintf(stderr, "could not open %s\n", filename);
370 exit(1);
371 }
372
373 frame = 0;
374 for(;;) {
375 avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
376 if (avpkt.size == 0)
377 break;
378
379 /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
380 and this is the only method to use them because you cannot
381 know the compressed data size before analysing it.

Callers 1

mainFunction · 0.85

Calls 9

av_init_packetFunction · 0.85
avcodec_find_decoderFunction · 0.85
avcodec_alloc_contextFunction · 0.85
avcodec_alloc_frameFunction · 0.85
avcodec_openFunction · 0.85
avcodec_decode_video2Function · 0.85
pgm_saveFunction · 0.85
avcodec_closeFunction · 0.85
av_freeFunction · 0.85

Tested by

no test coverage detected