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
3131
3232 #include <math.h>
3333
34−#include <libavutil/imgutils.h>
3534 #include <libavutil/opt.h>
3635 #include <libavcodec/avcodec.h>
3736 #include <libavutil/audioconvert.h>
37+#include <libavutil/imgutils.h>
3838 #include <libavutil/mathematics.h>
3939 #include <libavutil/samplefmt.h>
4040
@@ -315,11 +315,11 @@ static void video_encode_example(const char *filename, int codec_id) · 274 unmodified lines
315315 {
316316 AVCodec *codec;
317317 AVCodecContext *c= NULL;
318− int i, out_size, x, y, outbuf_size;
318+ int i, ret, x, y, got_output;
319319 FILE *f;
320320 AVFrame *picture;
321− uint8_t *outbuf;
322− int had_output=0;
321+ AVPacket pkt;
322+ uint8_t endcode[] = { 0, 0, 1, 0xb7 };
323323
324324 printf("Encode video file %s\n", filename);
325325
@@ -359,17 +359,25 @@ static void video_encode_example(const char *filename, int codec_id) · 33 unmodified lines
359359 exit(1);
360360 }
361361
362− /* alloc image and output buffer */
363− outbuf_size = 100000 + 12*c->width*c->height;
364− outbuf = malloc(outbuf_size);
365−
366362 /* the image can be allocated by any means and av_image_alloc() is
367363 * just the most convenient way if av_malloc() is to be used */
368− av_image_alloc(picture->data, picture->linesize,
369− c->width, c->height, c->pix_fmt, 1);
364+ ret = av_image_alloc(picture->data, picture->linesize, c->width, c->height,
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;
370374
371375 /* encode 1 second of video */
372376 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+
373381 fflush(stdout);
374382 /* prepare a dummy image */
375383 /* Y */
@@ -387,35 +395,46 @@ static void video_encode_example(const char *filename, int codec_id) · 11 unmodified lines
387395 }
388396 }
389397
398+ picture->pts = i;
399+
390400 /* encode the image */
391− out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
392− had_output |= out_size;
393− printf("encoding frame %3d (size=%5d)\n", i, out_size);
394− fwrite(outbuf, 1, out_size, f);
401+ ret = avcodec_encode_video2(c, &pkt, picture, &got_output);
402+ if (ret < 0) {
403+ fprintf(stderr, "error encoding frame\n");
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+ }
395412 }
396413
397414 /* get the delayed frames */
398− for(; out_size || !had_output; i++) {
415+ for (got_output = 1; got_output; i++) {
399416 fflush(stdout);
400417
401− out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
402− had_output |= out_size;
403− printf("write frame %3d (size=%5d)\n", i, out_size);
404− fwrite(outbuf, 1, out_size, f);
418+ ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
419+ if (ret < 0) {
420+ fprintf(stderr, "error encoding frame\n");
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+ }
405429 }
406430
407431 /* add sequence end code to have a real mpeg file */
408− outbuf[0] = 0x00;
409− outbuf[1] = 0x00;
410− outbuf[2] = 0x01;
411− outbuf[3] = 0xb7;
412− fwrite(outbuf, 1, 4, f);
432+ fwrite(endcode, 1, sizeof(endcode), f);
413433 fclose(f);
414− free(outbuf);
415434
416435 avcodec_close(c);
417436 av_free(c);
418− av_free(picture->data[0]);
437+ av_freep(&picture->data[0]);
419438 av_free(picture);
420439 printf("\n");
421440 }

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