Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(422961)

Side by Side Diff: examples/encoder_example.c

Issue 547: Added filter prior to encoding giving BDR gains on certain sequences like KristenAndSara.
Patch Set: Added filter prior to encoding giving BDR gains on certain sequences like KristenAndSara. Created 4 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Makefile.am ('k') | examples/prefilter.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*Daala video codec 2 /*Daala video codec
3 Copyright (c) 2006-2010 Daala project contributors. All rights reserved. 3 Copyright (c) 2006-2010 Daala project contributors. All rights reserved.
4 4
5 Redistribution and use in source and binary forms, with or without 5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met: 6 modification, are permitted provided that the following conditions are met:
7 7
8 - Redistributions of source code must retain the above copyright notice, this 8 - Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer. 9 list of conditions and the following disclaimer.
10 10
(...skipping 17 matching lines...) Expand all
28 #endif 28 #endif
29 29
30 #include <stdio.h> 30 #include <stdio.h>
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include <math.h> 32 #include <math.h>
33 #include <string.h> 33 #include <string.h>
34 #include <time.h> 34 #include <time.h>
35 #include <getopt.h> 35 #include <getopt.h>
36 #include "../src/logging.h" 36 #include "../src/logging.h"
37 #include "daala/daalaenc.h" 37 #include "daala/daalaenc.h"
38 #include "prefilter.h"
38 #if defined(_WIN32) 39 #if defined(_WIN32)
39 # include <fcntl.h> 40 # include <fcntl.h>
40 # include <io.h> 41 # include <io.h>
41 #else 42 #else
42 # include <unistd.h> 43 # include <unistd.h>
43 #endif 44 #endif
44 #if defined(_MSC_VER) 45 #if defined(_MSC_VER)
45 static double rint(double x) { 46 static double rint(double x) {
46 return (int)(x < 0 ? x - 0.5 : x + 0.5); 47 return (int)(x < 0 ? x - 0.5 : x + 0.5);
47 } 48 }
48 #endif 49 #endif
49 50
50 typedef struct av_input av_input; 51 typedef struct av_input av_input;
51 52
52 struct av_input{ 53 struct av_input{
53 int has_video; 54 int has_video;
54 FILE *video_infile; 55 FILE *video_infile;
55 int video_pic_w; 56 int video_pic_w;
56 int video_pic_h; 57 int video_pic_h;
57 int video_fps_n; 58 int video_fps_n;
58 int video_fps_d; 59 int video_fps_d;
59 int video_par_n; 60 int video_par_n;
60 int video_par_d; 61 int video_par_d;
61 int video_interlacing; 62 int video_interlacing;
62 char video_chroma_type[16]; 63 char video_chroma_type[16];
63 int video_nplanes; 64 int video_nplanes;
64 daala_plane_info video_plane_info[OD_NPLANES_MAX]; 65 daala_plane_info video_plane_info[OD_NPLANES_MAX];
65 od_img video_img; 66 od_img video_buf1;
67 od_img video_buf2;
68 od_img video_filt;
69 od_img *video_img;
70 od_img *video_img_prev;
66 int video_cur_img; 71 int video_cur_img;
67 }; 72 };
68 73
69 static int y4m_parse_tags(av_input *avin, char *tags) { 74 static int y4m_parse_tags(av_input *avin, char *tags) {
70 int got_w; 75 int got_w;
71 int got_h; 76 int got_h;
72 int got_fps; 77 int got_fps;
73 int got_interlacing; 78 int got_interlacing;
74 int got_par; 79 int got_par;
75 int got_chroma; 80 int got_chroma;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 avin->video_plane_info[2].ydec = 1; 237 avin->video_plane_info[2].ydec = 1;
233 } 238 }
234 else if (strcmp(avin->video_chroma_type, "mono") == 0) { 239 else if (strcmp(avin->video_chroma_type, "mono") == 0) {
235 avin->video_nplanes = 1; 240 avin->video_nplanes = 1;
236 } 241 }
237 else { 242 else {
238 fprintf(stderr, "Unknown chroma sampling type: '%s'.\n", 243 fprintf(stderr, "Unknown chroma sampling type: '%s'.\n",
239 avin->video_chroma_type); 244 avin->video_chroma_type);
240 exit(1); 245 exit(1);
241 } 246 }
242 img = &avin->video_img; 247 img = avin->video_img;
243 img->nplanes = avin->video_nplanes; 248 img->nplanes = avin->video_nplanes;
244 img->width = avin->video_pic_w; 249 img->width = avin->video_pic_w;
245 img->height = avin->video_pic_h; 250 img->height = avin->video_pic_h;
246 for (pli = 0; pli < img->nplanes; pli++) { 251 for (pli = 0; pli < img->nplanes; pli++) {
247 od_img_plane *iplane; 252 od_img_plane *iplane;
253 int size;
248 iplane = img->planes + pli; 254 iplane = img->planes + pli;
249 iplane->xdec = avin->video_plane_info[pli].xdec; 255 iplane->xdec = avin->video_plane_info[pli].xdec;
250 iplane->ydec = avin->video_plane_info[pli].ydec; 256 iplane->ydec = avin->video_plane_info[pli].ydec;
251 iplane->xstride = 1; 257 iplane->xstride = 1;
252 iplane->ystride = (avin->video_pic_w 258 iplane->ystride = (avin->video_pic_w
253 + (1 << iplane->xdec) - 1) >> iplane->xdec; 259 + (1 << iplane->xdec) - 1) >> iplane->xdec;
254 iplane->data = (unsigned char *)_ogg_malloc(iplane->ystride* 260 size = iplane->ystride*((avin->video_pic_h + (1 << iplane->ydec) - 1)
255 ((avin->video_pic_h + (1 << iplane->ydec) - 1) >> iplane->ydec)); 261 >> iplane->ydec);
262 iplane->data = (unsigned char *)_ogg_malloc(size);
263 memset(iplane->data, pli ? 128 : 0, size);
256 } 264 }
257 } 265 }
258 266
259 static void id_file(av_input *avin, const char *file) { 267 static void id_file(av_input *avin, const char *file) {
260 unsigned char buf[4]; 268 unsigned char buf[4];
261 FILE *test; 269 FILE *test;
262 int ret; 270 int ret;
263 if (!strcmp(file, "-")) test = stdin; 271 if (!strcmp(file, "-")) test = stdin;
264 else { 272 else {
265 test = fopen(file, "rb"); 273 test = fopen(file, "rb");
(...skipping 18 matching lines...) Expand all
284 fprintf(stderr, "Error parsing YUV4MPEG2 file.\n"); 292 fprintf(stderr, "Error parsing YUV4MPEG2 file.\n");
285 exit(1); 293 exit(1);
286 } 294 }
287 } 295 }
288 else { 296 else {
289 fprintf(stderr, 297 fprintf(stderr,
290 "Input file '%s' is not a YUV4MPEG2 file.\n", file); 298 "Input file '%s' is not a YUV4MPEG2 file.\n", file);
291 } 299 }
292 } 300 }
293 301
302 static od_img *get_next_video_img(av_input *avin) {
303 od_img *r = avin->video_img;
304 r = avin->video_img == &avin->video_buf1
305 ? &avin->video_buf2 : &avin->video_buf1;
306 avin->video_img_prev = r;
307 return avin->video_img;
308 }
309
294 int fetch_and_process_video(av_input *avin, ogg_page *page, 310 int fetch_and_process_video(av_input *avin, ogg_page *page,
295 ogg_stream_state *vo, daala_enc_ctx *dd, int video_ready, 311 ogg_stream_state *vo, daala_enc_ctx *dd, int video_ready,
296 int *limit, int *skip) { 312 int *limit, int skip, int prefilter, int input_q) {
297 ogg_packet op; 313 ogg_packet op;
298 while (!video_ready) { 314 while (!video_ready) {
299 size_t ret; 315 size_t ret;
300 char frame[6]; 316 char frame[6];
301 char c; 317 char c;
302 int last; 318 int last;
303 if (ogg_stream_pageout(vo, page) > 0) return 1; 319 if (ogg_stream_pageout(vo, page) > 0) return 1;
304 else if (ogg_stream_eos(vo) || (limit && (*limit) < 0)) return 0; 320 else if (ogg_stream_eos(vo) || (limit && (*limit) < 0)) return 0;
305 ret = fread(frame, 1, 6, avin->video_infile); 321 ret = fread(frame, 1, 6, avin->video_infile);
306 if (ret == 6) { 322 if (ret == 6) {
307 od_img *img; 323 od_img *img;
308 int pli; 324 int pli;
309 if (memcmp(frame, "FRAME", 5) != 0) { 325 if (memcmp(frame, "FRAME", 5) != 0) {
310 fprintf(stderr, "Loss of framing in YUV input data.\n"); 326 fprintf(stderr, "Loss of framing in YUV input data.\n");
311 exit(1); 327 exit(1);
312 } 328 }
313 if (frame[5] != '\n') { 329 if (frame[5] != '\n') {
314 int bi; 330 int bi;
315 for (bi = 0; bi < 121; bi++) { 331 for (bi = 0; bi < 121; bi++) {
316 if (fread(&c, 1, 1, avin->video_infile) == 1 && c == '\n') break; 332 if (fread(&c, 1, 1, avin->video_infile) == 1 && c == '\n') break;
317 } 333 }
318 if (bi >= 121) { 334 if (bi >= 121) {
319 fprintf(stderr, "Error parsing YUV frame header.\n"); 335 fprintf(stderr, "Error parsing YUV frame header.\n");
320 exit(1); 336 exit(1);
321 } 337 }
322 } 338 }
323 /*Read the frame data.*/ 339 /*Read the frame data.*/
324 img = &avin->video_img; 340 img = get_next_video_img(avin);
325 for (pli = 0; pli < img->nplanes; pli++) { 341 for (pli = 0; pli < img->nplanes; pli++) {
326 od_img_plane *iplane; 342 od_img_plane *iplane;
327 size_t plane_sz; 343 size_t plane_sz;
328 iplane = img->planes + pli; 344 iplane = img->planes + pli;
329 plane_sz = ((avin->video_pic_w + (1 << iplane->xdec) - 1) 345 plane_sz = ((avin->video_pic_w + (1 << iplane->xdec) - 1)
330 >> iplane->xdec)*((avin->video_pic_h + (1 << iplane->ydec) 346 >> iplane->xdec)*((avin->video_pic_h + (1 << iplane->ydec)
331 - 1) >> iplane->ydec); 347 - 1) >> iplane->ydec);
332 ret = fread(iplane->data/* + (avin->video_pic_y >> iplane->ydec) 348 ret = fread(iplane->data/* + (avin->video_pic_y >> iplane->ydec)
333 *iplane->ystride + (avin->video_picx >> iplane->xdec)*/, 1, plane_sz, 349 *iplane->ystride + (avin->video_picx >> iplane->xdec)*/, 1, plane_sz,
334 avin->video_infile); 350 avin->video_infile);
335 if (ret != plane_sz) { 351 if (ret != plane_sz) {
336 fprintf(stderr, "Error reading YUV frame data.\n"); 352 fprintf(stderr, "Error reading YUV frame data.\n");
337 exit(1); 353 exit(1);
338 } 354 }
339 } 355 }
340 if (skip && (*skip) > 0) { 356 if (skip && (*skip) > 0) {
341 (*skip)--; 357 (*skip)--;
342 continue; 358 continue;
343 } 359 }
360
361 if (prefilter) {
362 pre_filter(avin->video_filt.planes[0].data,
363 avin->video_filt.planes[1].data,
364 avin->video_filt.planes[2].data,
365 avin->video_img->planes[0].data,
366 avin->video_img->planes[1].data,
367 avin->video_img->planes[2].data,
368 avin->video_img_prev->planes[0].data,
369 avin->video_img_prev->planes[1].data,
370 avin->video_img_prev->planes[2].data,
371 avin->video_pic_w, avin->video_pic_h, input_q);
372 }
373
344 if (limit) { 374 if (limit) {
345 last = (*limit) == 0; 375 last = (*limit) == 0;
346 (*limit)--; 376 (*limit)--;
347 } 377 }
348 else last = 0; 378 else last = 0;
349 } 379 }
350 else last = 1; 380 else last = 1;
351 /*Pull the packets from the previous frame, now that we know whether or not 381 /*Pull the packets from the previous frame, now that we know whether or not
352 we can read the current one. 382 we can read the current one.
353 This is used to set the e_o_s bit on the final packet.*/ 383 This is used to set the e_o_s bit on the final packet.*/
354 while (daala_encode_packet_out(dd, last, &op)) { 384 while (daala_encode_packet_out(dd, last, &op)) {
355 ogg_stream_packetin(vo, &op); 385 ogg_stream_packetin(vo, &op);
356 } 386 }
357 /*Submit the current frame for encoding.*/ 387 /*Submit the current frame for encoding.*/
358 if (!last) daala_encode_img_in(dd, &avin->video_img, 0); 388 if (!last) daala_encode_img_in(dd, avin->video_img, 0);
359 } 389 }
360 return video_ready; 390 return video_ready;
361 } 391 }
362 392
363 static const char *OPTSTRING = "ho:k:v:V:s:S:l:z:"; 393 static const char *OPTSTRING = "ho:k:v:V:s:S:l:z:f:";
364 394
365 static const struct option OPTIONS[] = { 395 static const struct option OPTIONS[] = {
366 { "help", no_argument, NULL, 'h' }, 396 { "help", no_argument, NULL, 'h' },
367 { "output", required_argument, NULL, 'o' }, 397 { "output", required_argument, NULL, 'o' },
368 { "keyframe-rate", required_argument, NULL, 'k' }, 398 { "keyframe-rate", required_argument, NULL, 'k' },
369 { "video-quality", required_argument, NULL, 'v' }, 399 { "video-quality", required_argument, NULL, 'v' },
370 { "video-rate-target", required_argument, NULL, 'V' }, 400 { "video-rate-target", required_argument, NULL, 'V' },
371 { "serial", required_argument, NULL, 's' }, 401 { "serial", required_argument, NULL, 's' },
372 { "skip", required_argument, NULL, 'S' }, 402 { "skip", required_argument, NULL, 'S' },
373 { "limit", required_argument, NULL, 'l' }, 403 { "limit", required_argument, NULL, 'l' },
374 { "complexity", required_argument, NULL, 'z' }, 404 { "complexity", required_argument, NULL, 'z' },
375 { "mc-use-chroma", no_argument, NULL, 0 }, 405 { "mc-use-chroma", no_argument, NULL, 0 },
376 { "no-mc-use-chroma", no_argument, NULL, 0 }, 406 { "no-mc-use-chroma", no_argument, NULL, 0 },
377 { "activity-masking", no_argument, NULL, 0 }, 407 { "activity-masking", no_argument, NULL, 0 },
378 { "no-activity-masking", no_argument, NULL, 0 }, 408 { "no-activity-masking", no_argument, NULL, 0 },
379 { "qm", required_argument, NULL, 0 }, 409 { "qm", required_argument, NULL, 0 },
380 { "mv-res-min", required_argument, NULL, 0 }, 410 { "mv-res-min", required_argument, NULL, 0 },
381 { "mv-level-min", required_argument, NULL, 0 }, 411 { "mv-level-min", required_argument, NULL, 0 },
382 { "mv-level-max", required_argument, NULL, 0 }, 412 { "mv-level-max", required_argument, NULL, 0 },
383 { "version", no_argument, NULL, 0}, 413 { "version", no_argument, NULL, 0},
414 { "filter", no_argument, NULL, 'f' },
384 { NULL, 0, NULL, 0 } 415 { NULL, 0, NULL, 0 }
385 }; 416 };
386 417
387 static void usage(void) { 418 static void usage(void) {
388 fprintf(stderr, 419 fprintf(stderr,
389 "Usage: encoder_example [options] video_file\n\n" 420 "Usage: encoder_example [options] video_file\n\n"
390 "Options:\n\n" 421 "Options:\n\n"
391 " -h --help Display this help and exit.\n" 422 " -h --help Display this help and exit.\n"
392 " -o --output <filename.ogg> file name for encoded output;\n" 423 " -o --output <filename.ogg> file name for encoded output;\n"
393 " If this option is not given, the\n" 424 " If this option is not given, the\n"
(...skipping 23 matching lines...) Expand all
417 " motion compensation search.\n" 448 " motion compensation search.\n"
418 " 0 => 1/8 pel (default), 1 => 1/4 pel,\n" 449 " 0 => 1/8 pel (default), 1 => 1/4 pel,\n"
419 " 2 => 1/2 pel\n" 450 " 2 => 1/2 pel\n"
420 " --qm <n> Select quantization matrix\n" 451 " --qm <n> Select quantization matrix\n"
421 " 0 => flat, 1 => hvs (default)\n" 452 " 0 => flat, 1 => hvs (default)\n"
422 " --mv-level-min <n> Minimum motion vectors level between\n" 453 " --mv-level-min <n> Minimum motion vectors level between\n"
423 " 0 (default) and 6.\n" 454 " 0 (default) and 6.\n"
424 " --mv-level-max <n> Maximum motion vectors level between\n" 455 " --mv-level-max <n> Maximum motion vectors level between\n"
425 " 0 and 6 (default).\n" 456 " 0 and 6 (default).\n"
426 " --version Displays version information." 457 " --version Displays version information."
458 " 0 and 4 (default).\n"
459 " -f --filter Enable pre encode filter.\n"
427 " encoder_example accepts only uncompressed YUV4MPEG2 video.\n\n"); 460 " encoder_example accepts only uncompressed YUV4MPEG2 video.\n\n");
428 exit(1); 461 exit(1);
429 } 462 }
430 463
431 static void version(void) { 464 static void version(void) {
432 fprintf(stderr, "%s\n", PACKAGE_STRING); 465 fprintf(stderr, "%s\n", PACKAGE_STRING);
433 exit(0); 466 exit(0);
434 } 467 }
435 468
436 int main(int argc, char **argv) { 469 int main(int argc, char **argv) {
437 FILE *outfile; 470 FILE *outfile;
438 av_input avin; 471 av_input avin;
439 ogg_stream_state vo; 472 ogg_stream_state vo;
440 ogg_page og; 473 ogg_page og;
441 ogg_packet op; 474 ogg_packet op;
442 daala_enc_ctx *dd; 475 daala_enc_ctx *dd;
443 daala_info di; 476 daala_info di;
444 daala_comment dc; 477 daala_comment dc;
445 ogg_int64_t video_bytesout; 478 ogg_int64_t video_bytesout;
446 double time_base; 479 double time_base;
447 int c; 480 int c;
448 int loi; 481 int loi;
449 int ret; 482 int ret;
450 int video_kbps; 483 int video_kbps;
451 int video_q; 484 int video_q;
452 int video_r; 485 int video_r;
453 int video_keyframe_rate; 486 int video_keyframe_rate;
454 int video_ready; 487 int video_ready;
455 int pli; 488 int pli;
489 int prefilter;
456 int fixedserial; 490 int fixedserial;
457 unsigned int serial; 491 unsigned int serial;
458 int skip; 492 int skip;
459 int limit; 493 int limit;
460 int complexity; 494 int complexity;
461 int interactive; 495 int interactive;
462 int mc_use_chroma; 496 int mc_use_chroma;
463 int use_activity_masking; 497 int use_activity_masking;
464 int qm; 498 int qm;
465 int mv_res_min; 499 int mv_res_min;
(...skipping 10 matching lines...) Expand all
476 outfile = stdout; 510 outfile = stdout;
477 memset(&avin, 0, sizeof(avin)); 511 memset(&avin, 0, sizeof(avin));
478 avin.video_fps_n = -1; 512 avin.video_fps_n = -1;
479 avin.video_fps_d = -1; 513 avin.video_fps_d = -1;
480 avin.video_par_n = -1; 514 avin.video_par_n = -1;
481 avin.video_par_d = -1; 515 avin.video_par_d = -1;
482 video_q = 10; 516 video_q = 10;
483 video_keyframe_rate = 256; 517 video_keyframe_rate = 256;
484 video_r = -1; 518 video_r = -1;
485 video_bytesout = 0; 519 video_bytesout = 0;
520 prefilter = 0;
486 fixedserial = 0; 521 fixedserial = 0;
487 skip = 0; 522 skip = 0;
488 limit = -1; 523 limit = -1;
489 complexity = 7; 524 complexity = 7;
490 mc_use_chroma = 1; 525 mc_use_chroma = 1;
491 use_activity_masking = 1; 526 use_activity_masking = 1;
492 qm = 1; 527 qm = 1;
493 mv_res_min = 0; 528 mv_res_min = 0;
494 mv_level_min = 0; 529 mv_level_min = 0;
495 mv_level_max = 6; 530 mv_level_max = 6;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 575 }
541 break; 576 break;
542 } 577 }
543 case 'S': { 578 case 'S': {
544 skip = atoi(optarg); 579 skip = atoi(optarg);
545 if (skip < 0) { 580 if (skip < 0) {
546 fprintf(stderr, 581 fprintf(stderr,
547 "Illegal number of frames to skip (must be non-negative)\n"); 582 "Illegal number of frames to skip (must be non-negative)\n");
548 exit(1); 583 exit(1);
549 } 584 }
585 case 'f': {
586 prefilter = 1;
550 break; 587 break;
551 } 588 }
552 case 'l': { 589 case 'l': {
553 limit = atoi(optarg); 590 limit = atoi(optarg);
554 if (limit < 1) { 591 if (limit < 1) {
555 fprintf(stderr, 592 fprintf(stderr,
556 "Illegal maximum frame limit (must be greater than 0)\n"); 593 "Illegal maximum frame limit (must be greater than 0)\n");
557 exit(1); 594 exit(1);
558 } 595 }
559 break; 596 break;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 657 }
621 else if (strcmp(OPTIONS[loi].name, "version") == 0) { 658 else if (strcmp(OPTIONS[loi].name, "version") == 0) {
622 version(); 659 version();
623 } 660 }
624 break; 661 break;
625 } 662 }
626 case 'h': 663 case 'h':
627 default: usage(); break; 664 default: usage(); break;
628 } 665 }
629 } 666 }
667 avin.video_img = &avin.video_buf1;
668
630 /*Assume anything following the options must be a file name.*/ 669 /*Assume anything following the options must be a file name.*/
631 for (; optind < argc; optind++) id_file(&avin, argv[optind]); 670 for (; optind < argc; optind++) id_file(&avin, argv[optind]);
632 if (!avin.has_video) { 671 if (!avin.has_video) {
633 fprintf(stderr, "No video files submitted for compression.\n"); 672 fprintf(stderr, "No video files submitted for compression.\n");
634 exit(1); 673 exit(1);
635 } 674 }
675
676 /* Alloc space for storing the previous frame */
677 avin.video_buf2 = avin.video_buf1;
678 for(pli=0;pli<avin.video_buf2.nplanes;pli++){
679 od_img_plane *iplane;
680 int size;
681 iplane=avin.video_buf2.planes+pli;
682 size=iplane->ystride*((avin.video_pic_h+(1<<iplane->ydec)-1)>>iplane->ydec);
683 iplane->data=_ogg_malloc(size);
684 memset(iplane->data, pli ? 128 : 0, size);
685 }
686
687 /* Alloc space for storing a temporally filtered frame */
688 avin.video_filt = avin.video_buf1;
689 for(pli=0;pli<avin.video_filt.nplanes;pli++){
690 od_img_plane *iplane;
691 int size;
692 iplane=avin.video_filt.planes+pli;
693 size=iplane->ystride*((avin.video_pic_h+(1<<iplane->ydec)-1)>>iplane->ydec);
694 iplane->data=_ogg_malloc(size);
695 memset(iplane->data, pli ? 128 : 0, size);
696 }
697
636 if (!fixedserial) { 698 if (!fixedserial) {
637 srand(time(NULL)); 699 srand(time(NULL));
638 serial = rand(); 700 serial = rand();
639 } 701 }
640 ogg_stream_init(&vo, serial); 702 ogg_stream_init(&vo, serial);
641 daala_info_init(&di); 703 daala_info_init(&di);
642 di.pic_width = avin.video_pic_w; 704 di.pic_width = avin.video_pic_w;
643 di.pic_height = avin.video_pic_h; 705 di.pic_height = avin.video_pic_h;
644 di.timebase_numerator = avin.video_fps_n; 706 di.timebase_numerator = avin.video_fps_n;
645 di.timebase_denominator = avin.video_fps_d; 707 di.timebase_denominator = avin.video_fps_d;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 /*Setup complete. 775 /*Setup complete.
714 Main compression loop.*/ 776 Main compression loop.*/
715 fprintf(stderr, "Compressing...\n"); 777 fprintf(stderr, "Compressing...\n");
716 video_ready = 0; 778 video_ready = 0;
717 for (;;) { 779 for (;;) {
718 ogg_page video_page; 780 ogg_page video_page;
719 double video_time; 781 double video_time;
720 size_t bytes_written; 782 size_t bytes_written;
721 video_ready = fetch_and_process_video(&avin, &video_page, &vo, 783 video_ready = fetch_and_process_video(&avin, &video_page, &vo,
722 dd, video_ready, limit >= 0 ? &limit : NULL, skip > 0 ? &skip : NULL); 784 dd, video_ready, limit >= 0 ? &limit : NULL, skip > 0 ? &skip : NULL);
785 video_ready = fetch_and_process_video(&avin, &video_page,
786 &vo, dd, video_ready, limit >= 0 ? &limit : NULL,
787 skip > 0 ? &skip : NULL, prefilter, input_q);
723 /*TODO: Fetch the next video page.*/ 788 /*TODO: Fetch the next video page.*/
724 /*If no more pages are available, we've hit the end of the stream.*/ 789 /*If no more pages are available, we've hit the end of the stream.*/
725 if (!video_ready) break; 790 if (!video_ready) break;
726 video_time = daala_granule_time(dd, ogg_page_granulepos(&video_page)); 791 video_time = daala_granule_time(dd, ogg_page_granulepos(&video_page));
727 bytes_written = 792 bytes_written =
728 fwrite(video_page.header, 1, video_page.header_len, outfile); 793 fwrite(video_page.header, 1, video_page.header_len, outfile);
729 if (bytes_written < (size_t)video_page.header_len) { 794 if (bytes_written < (size_t)video_page.header_len) {
730 fprintf(stderr, "Could not write page header to file.\n"); 795 fprintf(stderr, "Could not write page header to file.\n");
731 exit(1); 796 exit(1);
732 } 797 }
(...skipping 15 matching lines...) Expand all
748 fprintf(stderr, "\n"); 813 fprintf(stderr, "\n");
749 } 814 }
750 fprintf(stderr, 815 fprintf(stderr,
751 " %i:%02i:%02i.%02i video: %ikbps ", 816 " %i:%02i:%02i.%02i video: %ikbps ",
752 (int)time_base/3600, ((int)time_base/60)%60, (int)time_base % 60, 817 (int)time_base/3600, ((int)time_base/60)%60, (int)time_base % 60,
753 (int)(time_base*100 - (long)time_base*100), video_kbps); 818 (int)(time_base*100 - (long)time_base*100), video_kbps);
754 } 819 }
755 ogg_stream_clear(&vo); 820 ogg_stream_clear(&vo);
756 daala_encode_free(dd); 821 daala_encode_free(dd);
757 daala_comment_clear(&dc); 822 daala_comment_clear(&dc);
758 for (pli = 0; pli < avin.video_img.nplanes; pli++) { 823 for(pli = 0; pli < avin.video_buf1.nplanes; pli++) {
759 _ogg_free(avin.video_img.planes[pli].data); 824 _ogg_free(avin.video_buf1.planes[pli].data);
825 _ogg_free(avin.video_buf2.planes[pli].data);
760 } 826 }
761 if (outfile != NULL && outfile != stdout) fclose(outfile); 827 if (outfile != NULL && outfile != stdout) fclose(outfile);
762 fprintf(stderr, "\r \ndone.\n\r"); 828 fprintf(stderr, "\r \ndone.\n\r");
763 if (avin.video_infile != NULL && avin.video_infile != stdin) { 829 if (avin.video_infile != NULL && avin.video_infile != stdin) {
764 fclose(avin.video_infile); 830 fclose(avin.video_infile);
765 } 831 }
766 return 0; 832 return 0;
767 } 833 }
OLDNEW
« no previous file with comments | « Makefile.am ('k') | examples/prefilter.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld