History

Merge remote-tracking branch 'qatar/master'

* qatar/master: rtmp: Add support for SWFVerification api-example: use new video encoding API. x86: avcodec: Appropriately name files containing only init functions mpegvideo_mmx_template: drop some commented-out cruft libavresample: add mix level normalization option w32pthreads: Add missing #includes to make header compile standalone rtmp: Gracefully ignore _checkbw errors by tracking them rtmp: Do not send _checkbw calls as notifications prores: interlaced ProRes encoding Conflicts: doc/examples/decoding_encoding.c libavcodec/proresenc_kostya.c libavcodec/w32pthreads.h libavcodec/x86/Makefile libavformat/version.h

Michael Niedermayer committed 14 years ago

Commit 9e89bc32 parents aee7b88 635ac8e16 files · +177 −74Browse files

Showing the changes to doc/examples/decoding_encoding.c (1 of 16 files). Show all

Unified · Split

doc/examples/decoding_encoding.c+45−26
@@ -31,10 +31,10 @@ · 30 unmodified lines
31 31
32#include <math.h>32#include <math.h>
33 33
34#include <libavutil/imgutils.h>
35#include <libavutil/opt.h>34#include <libavutil/opt.h>
36#include <libavcodec/avcodec.h>35#include <libavcodec/avcodec.h>
37#include <libavutil/audioconvert.h>36#include <libavutil/audioconvert.h>
37#include <libavutil/imgutils.h>
38#include <libavutil/mathematics.h>38#include <libavutil/mathematics.h>
39#include <libavutil/samplefmt.h>39#include <libavutil/samplefmt.h>
40 40
@@ -315,11 +315,11 @@ static void video_encode_example(const char *filename, int codec_id) · 274 unmodified lines
315{315{
316 AVCodec *codec;316 AVCodec *codec;
317 AVCodecContext *c= NULL;317 AVCodecContext *c= NULL;
318 int i, out_size, x, y, outbuf_size;318 int i, ret, x, y, got_output;
319 FILE *f;319 FILE *f;
320 AVFrame *picture;320 AVFrame *picture;
321 uint8_t *outbuf;321 AVPacket pkt;
322 int had_output=0;322 uint8_t endcode[] = { 0, 0, 1, 0xb7 };
323 323
324 printf("Encode video file %s\n", filename);324 printf("Encode video file %s\n", filename);
325 325
@@ -359,17 +359,25 @@ static void video_encode_example(const char *filename, int codec_id) · 33 unmodified lines
359 exit(1);359 exit(1);
360 }360 }
361 361
362 /* alloc image and output buffer */
363 outbuf_size = 100000 + 12*c->width*c->height;
364 outbuf = malloc(outbuf_size);
365
366 /* the image can be allocated by any means and av_image_alloc() is362 /* the image can be allocated by any means and av_image_alloc() is
367 * just the most convenient way if av_malloc() is to be used */363 * just the most convenient way if av_malloc() is to be used */
368 av_image_alloc(picture->data, picture->linesize,364 ret = av_image_alloc(picture->data, picture->linesize, c->width, c->height,
369 c->width, c->height, c->pix_fmt, 1);365 c->pix_fmt, 32);
366 if (ret < 0) {
367 fprintf(stderr, "could not alloc raw picture buffer\n");
368 exit(1);
369 }
370
371 picture->format = c->pix_fmt;
372 picture->width = c->width;
373 picture->height = c->height;
370 374
371 /* encode 1 second of video */375 /* encode 1 second of video */
372 for(i=0;i<25;i++) {376 for(i=0;i<25;i++) {
377 av_init_packet(&pkt);
378 pkt.data = NULL; // packet data will be allocated by the encoder
379 pkt.size = 0;
380
373 fflush(stdout);381 fflush(stdout);
374 /* prepare a dummy image */382 /* prepare a dummy image */
375 /* Y */383 /* Y */
@@ -387,35 +395,46 @@ static void video_encode_example(const char *filename, int codec_id) · 11 unmodified lines
387 }395 }
388 }396 }
389 397
398 picture->pts = i;
399
390 /* encode the image */400 /* encode the image */
391 out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);401 ret = avcodec_encode_video2(c, &pkt, picture, &got_output);
392 had_output |= out_size;402 if (ret < 0) {
393 printf("encoding frame %3d (size=%5d)\n", i, out_size);403 fprintf(stderr, "error encoding frame\n");
394 fwrite(outbuf, 1, out_size, f);404 exit(1);
405 }
406
407 if (got_output) {
408 printf("encoding frame %3d (size=%5d)\n", i, pkt.size);
409 fwrite(pkt.data, 1, pkt.size, f);
410 av_free_packet(&pkt);
411 }
395 }412 }
396 413
397 /* get the delayed frames */414 /* get the delayed frames */
398 for(; out_size || !had_output; i++) {415 for (got_output = 1; got_output; i++) {
399 fflush(stdout);416 fflush(stdout);
400 417
401 out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);418 ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
402 had_output |= out_size;419 if (ret < 0) {
403 printf("write frame %3d (size=%5d)\n", i, out_size);420 fprintf(stderr, "error encoding frame\n");
404 fwrite(outbuf, 1, out_size, f);421 exit(1);
422 }
423
424 if (got_output) {
425 printf("write frame %3d (size=%5d)\n", i, pkt.size);
426 fwrite(pkt.data, 1, pkt.size, f);
427 av_free_packet(&pkt);
428 }
405 }429 }
406 430
407 /* add sequence end code to have a real mpeg file */431 /* add sequence end code to have a real mpeg file */
408 outbuf[0] = 0x00;432 fwrite(endcode, 1, sizeof(endcode), f);
409 outbuf[1] = 0x00;
410 outbuf[2] = 0x01;
411 outbuf[3] = 0xb7;
412 fwrite(outbuf, 1, 4, f);
413 fclose(f);433 fclose(f);
414 free(outbuf);
415 434
416 avcodec_close(c);435 avcodec_close(c);
417 av_free(c);436 av_free(c);
418 av_free(picture->data[0]);437 av_freep(&picture->data[0]);
419 av_free(picture);438 av_free(picture);
420 printf("\n");439 printf("\n");
421}440}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t