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

Delta Between Two Patch Sets: examples/encoder_example.c

Issue 547: Added filter prior to encoding giving BDR gains on certain sequences like KristenAndSara.
Left Patch Set: Created 4 years, 11 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Makefile.am ('k') | examples/prefilter.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 30 matching lines...) Expand all
41 # include <io.h> 41 # include <io.h>
42 #else 42 #else
43 # include <unistd.h> 43 # include <unistd.h>
44 #endif 44 #endif
45 #if defined(_MSC_VER) 45 #if defined(_MSC_VER)
46 static double rint(double x) { 46 static double rint(double x) {
47 return (int)(x < 0 ? x - 0.5 : x + 0.5); 47 return (int)(x < 0 ? x - 0.5 : x + 0.5);
48 } 48 }
49 #endif 49 #endif
50 50
51
52
53 typedef struct av_input av_input; 51 typedef struct av_input av_input;
54
55
56 52
57 struct av_input{ 53 struct av_input{
58 int has_video; 54 int has_video;
59 FILE *video_infile; 55 FILE *video_infile;
60 int video_pic_w; 56 int video_pic_w;
61 int video_pic_h; 57 int video_pic_h;
62 int video_fps_n; 58 int video_fps_n;
63 int video_fps_d; 59 int video_fps_d;
64 int video_par_n; 60 int video_par_n;
65 int video_par_d; 61 int video_par_d;
66 int video_interlacing; 62 int video_interlacing;
67 char video_chroma_type[16]; 63 char video_chroma_type[16];
68 int video_nplanes; 64 int video_nplanes;
69 daala_plane_info video_plane_info[OD_NPLANES_MAX]; 65 daala_plane_info video_plane_info[OD_NPLANES_MAX];
70 od_img video_buf1; 66 od_img video_buf1;
71 od_img video_buf2; 67 od_img video_buf2;
72 od_img video_filt; 68 od_img video_filt;
73 od_img *video_img; 69 od_img *video_img;
74 od_img *video_img_prev; 70 od_img *video_img_prev;
75 int video_cur_img; 71 int video_cur_img;
76 }; 72 };
77
78
79 73
80 static int y4m_parse_tags(av_input *avin, char *tags) { 74 static int y4m_parse_tags(av_input *avin, char *tags) {
81 int got_w; 75 int got_w;
82 int got_h; 76 int got_h;
83 int got_fps; 77 int got_fps;
84 int got_interlacing; 78 int got_interlacing;
85 int got_par; 79 int got_par;
86 int got_chroma; 80 int got_chroma;
87 int tmp_video_fps_n; 81 int tmp_video_fps_n;
88 int tmp_video_fps_d; 82 int tmp_video_fps_d;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 static od_img *get_next_video_img(av_input *avin) { 302 static od_img *get_next_video_img(av_input *avin) {
309 od_img *r = avin->video_img; 303 od_img *r = avin->video_img;
310 r = avin->video_img == &avin->video_buf1 304 r = avin->video_img == &avin->video_buf1
311 ? &avin->video_buf2 : &avin->video_buf1; 305 ? &avin->video_buf2 : &avin->video_buf1;
312 avin->video_img_prev = r; 306 avin->video_img_prev = r;
313 return avin->video_img; 307 return avin->video_img;
314 } 308 }
315 309
316 int fetch_and_process_video(av_input *avin, ogg_page *page, 310 int fetch_and_process_video(av_input *avin, ogg_page *page,
317 ogg_stream_state *vo, daala_enc_ctx *dd, int video_ready, 311 ogg_stream_state *vo, daala_enc_ctx *dd, int video_ready,
318 int *limit, int prefilter, int input_q) { 312 int *limit, int skip, int prefilter, int input_q) {
319 ogg_packet op; 313 ogg_packet op;
320 while (!video_ready) { 314 while (!video_ready) {
321 size_t ret; 315 size_t ret;
322 char frame[6]; 316 char frame[6];
323 char c; 317 char c;
324 int last; 318 int last;
325 if (ogg_stream_pageout(vo, page) > 0) return 1; 319 if (ogg_stream_pageout(vo, page) > 0) return 1;
326 else if (ogg_stream_eos(vo) || (limit && (*limit) < 0)) return 0; 320 else if (ogg_stream_eos(vo) || (limit && (*limit) < 0)) return 0;
327 ret = fread(frame, 1, 6, avin->video_infile); 321 ret = fread(frame, 1, 6, avin->video_infile);
328 if (ret == 6) { 322 if (ret == 6) {
(...skipping 23 matching lines...) Expand all
352 >> iplane->xdec)*((avin->video_pic_h + (1 << iplane->ydec) 346 >> iplane->xdec)*((avin->video_pic_h + (1 << iplane->ydec)
353 - 1) >> iplane->ydec); 347 - 1) >> iplane->ydec);
354 ret = fread(iplane->data/* + (avin->video_pic_y >> iplane->ydec) 348 ret = fread(iplane->data/* + (avin->video_pic_y >> iplane->ydec)
355 *iplane->ystride + (avin->video_picx >> iplane->xdec)*/, 1, plane_sz, 349 *iplane->ystride + (avin->video_picx >> iplane->xdec)*/, 1, plane_sz,
356 avin->video_infile); 350 avin->video_infile);
357 if (ret != plane_sz) { 351 if (ret != plane_sz) {
358 fprintf(stderr, "Error reading YUV frame data.\n"); 352 fprintf(stderr, "Error reading YUV frame data.\n");
359 exit(1); 353 exit(1);
360 } 354 }
361 } 355 }
356 if (skip && (*skip) > 0) {
357 (*skip)--;
358 continue;
359 }
362 360
363 if (prefilter) { 361 if (prefilter) {
364 pre_filter(avin->video_filt.planes[0].data, 362 pre_filter(avin->video_filt.planes[0].data,
365 avin->video_filt.planes[1].data, 363 avin->video_filt.planes[1].data,
366 avin->video_filt.planes[2].data, 364 avin->video_filt.planes[2].data,
367 avin->video_img->planes[0].data, 365 avin->video_img->planes[0].data,
368 avin->video_img->planes[1].data, 366 avin->video_img->planes[1].data,
369 avin->video_img->planes[2].data, 367 avin->video_img->planes[2].data,
370 avin->video_img_prev->planes[0].data, 368 avin->video_img_prev->planes[0].data,
371 avin->video_img_prev->planes[1].data, 369 avin->video_img_prev->planes[1].data,
(...skipping 13 matching lines...) Expand all
385 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.*/
386 while (daala_encode_packet_out(dd, last, &op)) { 384 while (daala_encode_packet_out(dd, last, &op)) {
387 ogg_stream_packetin(vo, &op); 385 ogg_stream_packetin(vo, &op);
388 } 386 }
389 /*Submit the current frame for encoding.*/ 387 /*Submit the current frame for encoding.*/
390 if (!last) daala_encode_img_in(dd, avin->video_img, 0); 388 if (!last) daala_encode_img_in(dd, avin->video_img, 0);
391 } 389 }
392 return video_ready; 390 return video_ready;
393 } 391 }
394 392
395 static const char *OPTSTRING = "ho:k:v:V:s:l:f"; 393 static const char *OPTSTRING = "ho:k:v:V:s:S:l:z:f:";
396 394
397 static const struct option OPTIONS[] = { 395 static const struct option OPTIONS[] = {
398 { "help", no_argument, NULL, 'h' }, 396 { "help", no_argument, NULL, 'h' },
399 { "output", required_argument, NULL, 'o' }, 397 { "output", required_argument, NULL, 'o' },
400 { "keyframe-rate", required_argument, NULL, 'k' }, 398 { "keyframe-rate", required_argument, NULL, 'k' },
401 { "video-quality", required_argument, NULL, 'v' }, 399 { "video-quality", required_argument, NULL, 'v' },
402 { "video-rate-target", required_argument, NULL, 'V' }, 400 { "video-rate-target", required_argument, NULL, 'V' },
403 { "serial", required_argument, NULL, 's' }, 401 { "serial", required_argument, NULL, 's' },
402 { "skip", required_argument, NULL, 'S' },
404 { "limit", required_argument, NULL, 'l' }, 403 { "limit", required_argument, NULL, 'l' },
404 { "complexity", required_argument, NULL, 'z' },
405 { "mc-use-chroma", no_argument, NULL, 0 }, 405 { "mc-use-chroma", no_argument, NULL, 0 },
406 { "no-mc-use-chroma", no_argument, NULL, 0 }, 406 { "no-mc-use-chroma", no_argument, NULL, 0 },
407 { "activity-masking", no_argument, NULL, 0 },
408 { "no-activity-masking", no_argument, NULL, 0 },
409 { "qm", required_argument, NULL, 0 },
407 { "mv-res-min", required_argument, NULL, 0 }, 410 { "mv-res-min", required_argument, NULL, 0 },
408 { "mv-level-min", required_argument, NULL, 0 }, 411 { "mv-level-min", required_argument, NULL, 0 },
409 { "mv-level-max", required_argument, NULL, 0 }, 412 { "mv-level-max", required_argument, NULL, 0 },
413 { "version", no_argument, NULL, 0},
410 { "filter", no_argument, NULL, 'f' }, 414 { "filter", no_argument, NULL, 'f' },
411 { NULL, 0, NULL, 0 } 415 { NULL, 0, NULL, 0 }
412 }; 416 };
413 417
414 static void usage(void) { 418 static void usage(void) {
415 fprintf(stderr, 419 fprintf(stderr,
416 "Usage: encoder_example [options] video_file\n\n" 420 "Usage: encoder_example [options] video_file\n\n"
417 "Options:\n\n" 421 "Options:\n\n"
418 " -h --help Display this help and exit.\n" 422 " -h --help Display this help and exit.\n"
419 " -o --output <filename.ogg> file name for encoded output;\n" 423 " -o --output <filename.ogg> file name for encoded output;\n"
420 " If this option is not given, the\n" 424 " If this option is not given, the\n"
421 " compressed data is sent to stdout.\n\n" 425 " compressed data is sent to stdout.\n\n"
422 " -k --keyframe-rate <n> Frequency of keyframes in output.\n\n" 426 " -k --keyframe-rate <n> Frequency of keyframes in output.\n\n"
423 " -v --video-quality <n> Daala quality selector from 0 to 511.\n" 427 " -v --video-quality <n> Daala quality selector from 0 to 511.\n"
424 " 511 yields the smallest files, but\n" 428 " 511 yields the smallest files, but\n"
425 " lowest video quality; 1 yields the\n" 429 " lowest video quality; 1 yields the\n"
426 " highest quality, but large files;\n" 430 " highest quality, but large files;\n"
427 " 0 is lossless.\n\n" 431 " 0 is lossless.\n\n"
428 " -V --video-rate-target <n> bitrate target for Daala video;\n" 432 " -V --video-rate-target <n> bitrate target for Daala video;\n"
429 " use -v and not -V if at all possible,\n" 433 " use -v and not -V if at all possible,\n"
430 " as -v gives higher quality for a given\n" 434 " as -v gives higher quality for a given\n"
431 " bitrate.\n\n" 435 " bitrate.\n\n"
432 " -s --serial <n> Specify a serial number for the stream.\n" 436 " -s --serial <n> Specify a serial number for the stream.\n"
437 " -S --skip <n> Number of input frames to skip before encod ing.\n"
433 " -l --limit <n> Maximum number of frames to encode.\n" 438 " -l --limit <n> Maximum number of frames to encode.\n"
439 " -z --complexity <n> Computational complexity: 0...10\n"
440 " Fastest: 0, slowest: 10, default: 7\n"
434 " --[no-]mc-use-chroma Control whether the chroma planes should\n" 441 " --[no-]mc-use-chroma Control whether the chroma planes should\n"
435 " be used in the motion compensation search.\ n" 442 " be used in the motion compensation search.\ n"
436 " --mc-use-chroma is implied by default.\n" 443 " --mc-use-chroma is implied by default.\n"
444 " --[no-]activity-masking Control whether activity masking should\n"
445 " be used in quantization.\n"
446 " --activity-masking is implied by default.\n "
437 " --mv-res-min <n> Minimum motion vectors resolution for the\n " 447 " --mv-res-min <n> Minimum motion vectors resolution for the\n "
438 " motion compensation search.\n" 448 " motion compensation search.\n"
439 " 0 => 1/8 pel (default), 1 => 1/4 pel,\n" 449 " 0 => 1/8 pel (default), 1 => 1/4 pel,\n"
440 " 2 => 1/2 pel\n" 450 " 2 => 1/2 pel\n"
451 " --qm <n> Select quantization matrix\n"
452 " 0 => flat, 1 => hvs (default)\n"
441 " --mv-level-min <n> Minimum motion vectors level between\n" 453 " --mv-level-min <n> Minimum motion vectors level between\n"
442 " 0 (default) and 4.\n" 454 " 0 (default) and 6.\n"
443 " --mv-level-max <n> Maximum motion vectors level between\n" 455 " --mv-level-max <n> Maximum motion vectors level between\n"
456 " 0 and 6 (default).\n"
457 " --version Displays version information."
444 " 0 and 4 (default).\n" 458 " 0 and 4 (default).\n"
445 " -f --filter Enable pre encode filter.\n" 459 " -f --filter Enable pre encode filter.\n"
446 " encoder_example accepts only uncompressed YUV4MPEG2 video.\n\n"); 460 " encoder_example accepts only uncompressed YUV4MPEG2 video.\n\n");
447 exit(1); 461 exit(1);
462 }
463
464 static void version(void) {
465 fprintf(stderr, "%s\n", PACKAGE_STRING);
466 exit(0);
448 } 467 }
449 468
450 int main(int argc, char **argv) { 469 int main(int argc, char **argv) {
451 FILE *outfile; 470 FILE *outfile;
452 av_input avin; 471 av_input avin;
453 ogg_stream_state vo; 472 ogg_stream_state vo;
454 ogg_page og; 473 ogg_page og;
455 ogg_packet op; 474 ogg_packet op;
456 daala_enc_ctx *dd; 475 daala_enc_ctx *dd;
457 daala_info di; 476 daala_info di;
458 daala_comment dc; 477 daala_comment dc;
459 ogg_int64_t video_bytesout; 478 ogg_int64_t video_bytesout;
460 double time_base; 479 double time_base;
461 int c; 480 int c;
462 int loi; 481 int loi;
463 int ret; 482 int ret;
464 int video_kbps; 483 int video_kbps;
465 int video_q; 484 int video_q;
466 int video_r; 485 int video_r;
467 int video_keyframe_rate; 486 int video_keyframe_rate;
468 int video_ready; 487 int video_ready;
469 int pli; 488 int pli;
470 int prefilter; 489 int prefilter;
471 int fixedserial; 490 int fixedserial;
472 unsigned int serial; 491 unsigned int serial;
492 int skip;
473 int limit; 493 int limit;
494 int complexity;
474 int interactive; 495 int interactive;
475 int mc_use_chroma; 496 int mc_use_chroma;
497 int use_activity_masking;
498 int qm;
476 int mv_res_min; 499 int mv_res_min;
477 int mv_level_min; 500 int mv_level_min;
478 int mv_level_max; 501 int mv_level_max;
479 daala_log_init(); 502 daala_log_init();
480 #if defined(_WIN32) 503 #if defined(_WIN32)
481 _setmode(_fileno(stdin), _O_BINARY); 504 _setmode(_fileno(stdin), _O_BINARY);
482 _setmode(_fileno(stdout), _O_BINARY); 505 _setmode(_fileno(stdout), _O_BINARY);
483 interactive = _isatty(_fileno(stderr)); 506 interactive = _isatty(_fileno(stderr));
484 #else 507 #else
485 interactive = isatty(fileno(stderr)); 508 interactive = isatty(fileno(stderr));
486 #endif 509 #endif
487 outfile = stdout; 510 outfile = stdout;
488 memset(&avin, 0, sizeof(avin)); 511 memset(&avin, 0, sizeof(avin));
489 avin.video_fps_n = -1; 512 avin.video_fps_n = -1;
490 avin.video_fps_d = -1; 513 avin.video_fps_d = -1;
491 avin.video_par_n = -1; 514 avin.video_par_n = -1;
492 avin.video_par_d = -1; 515 avin.video_par_d = -1;
493 video_q = 10; 516 video_q = 10;
494 video_keyframe_rate = 256; 517 video_keyframe_rate = 256;
495 video_r = -1; 518 video_r = -1;
496 video_bytesout = 0; 519 video_bytesout = 0;
497 prefilter = 0; 520 prefilter = 0;
498 fixedserial = 0; 521 fixedserial = 0;
522 skip = 0;
499 limit = -1; 523 limit = -1;
524 complexity = 7;
500 mc_use_chroma = 1; 525 mc_use_chroma = 1;
526 use_activity_masking = 1;
527 qm = 1;
501 mv_res_min = 0; 528 mv_res_min = 0;
502 mv_level_min = 0; 529 mv_level_min = 0;
503 mv_level_max = 4; 530 mv_level_max = 6;
504 while ((c = getopt_long(argc, argv, OPTSTRING, OPTIONS, &loi)) != EOF) { 531 while ((c = getopt_long(argc, argv, OPTSTRING, OPTIONS, &loi)) != EOF) {
505 switch (c) { 532 switch (c) {
506 case 'o': { 533 case 'o': {
507 outfile = fopen(optarg, "wb"); 534 outfile = fopen(optarg, "wb");
508 if (outfile == NULL) { 535 if (outfile == NULL) {
509 fprintf(stderr, "Unable to open output file '%s'\n", optarg); 536 fprintf(stderr, "Unable to open output file '%s'\n", optarg);
510 exit(1); 537 exit(1);
511 } 538 }
512 break; 539 break;
513 } 540 }
(...skipping 27 matching lines...) Expand all
541 } 568 }
542 case 's': { 569 case 's': {
543 if (sscanf(optarg, "%u", &serial) != 1) { 570 if (sscanf(optarg, "%u", &serial) != 1) {
544 serial = 0; 571 serial = 0;
545 } 572 }
546 else { 573 else {
547 fixedserial = 1; 574 fixedserial = 1;
548 } 575 }
549 break; 576 break;
550 } 577 }
578 case 'S': {
579 skip = atoi(optarg);
580 if (skip < 0) {
581 fprintf(stderr,
582 "Illegal number of frames to skip (must be non-negative)\n");
583 exit(1);
584 }
551 case 'f': { 585 case 'f': {
552 prefilter = 1; 586 prefilter = 1;
553 break; 587 break;
554 } 588 }
555 case 'l': { 589 case 'l': {
556 limit = atoi(optarg); 590 limit = atoi(optarg);
557 if (limit < 1) { 591 if (limit < 1) {
558 fprintf(stderr, 592 fprintf(stderr,
559 "Illegal maximum frame limit (must be greater than 0)\n"); 593 "Illegal maximum frame limit (must be greater than 0)\n");
560 exit(1); 594 exit(1);
561 } 595 }
562 break; 596 break;
563 } 597 }
598 case 'z': {
599 complexity = atoi(optarg);
600 if (complexity < 0 || complexity > 10) {
601 fprintf(stderr,
602 "Illegal complexity setting (must be 0...10, inclusive)\n");
603 exit(1);
604 }
605 break;
606 }
564 case 0: { 607 case 0: {
565 if (strcmp(OPTIONS[loi].name, "mc-use-chroma") == 0) { 608 if (strcmp(OPTIONS[loi].name, "mc-use-chroma") == 0) {
566 mc_use_chroma = 1; 609 mc_use_chroma = 1;
567 } 610 }
568 else if (strcmp(OPTIONS[loi].name, "no-mc-use-chroma") == 0) { 611 else if (strcmp(OPTIONS[loi].name, "no-mc-use-chroma") == 0) {
569 mc_use_chroma = 0; 612 mc_use_chroma = 0;
613 }
614 else if (strcmp(OPTIONS[loi].name, "activity-masking") == 0) {
615 use_activity_masking = 1;
616 }
617 else if (strcmp(OPTIONS[loi].name, "no-activity-masking") == 0) {
618 use_activity_masking = 0;
570 } 619 }
571 else if (strcmp(OPTIONS[loi].name, "mv-res-min") == 0) { 620 else if (strcmp(OPTIONS[loi].name, "mv-res-min") == 0) {
572 mv_res_min = atoi(optarg); 621 mv_res_min = atoi(optarg);
573 if (mv_res_min < 0 || mv_res_min > 2) { 622 if (mv_res_min < 0 || mv_res_min > 2) {
574 fprintf(stderr, "Illegal value for --mv-res-min\n"); 623 fprintf(stderr, "Illegal value for --mv-res-min\n");
575 exit(1); 624 exit(1);
576 } 625 }
577 } 626 }
627 else if (strcmp(OPTIONS[loi].name, "qm") == 0) {
628 qm = atoi(optarg);
629 if (qm < 0 || qm > 1) {
630 fprintf(stderr, "Illegal value for --qm\n");
631 exit(1);
632 }
633 }
578 else if (strcmp(OPTIONS[loi].name, "mv-level-min") == 0) { 634 else if (strcmp(OPTIONS[loi].name, "mv-level-min") == 0) {
579 mv_level_min = atoi(optarg); 635 mv_level_min = atoi(optarg);
580 if (mv_level_min < 0 || mv_level_min > 4) { 636 if (mv_level_min < 0 || mv_level_min > 6) {
581 fprintf(stderr, "Illegal value for --mv-level-min\n"); 637 fprintf(stderr, "Illegal value for --mv-level-min\n");
582 exit(1); 638 exit(1);
583 } 639 }
584 if (mv_level_min > mv_level_max) { 640 if (mv_level_min > mv_level_max) {
585 fprintf(stderr, 641 fprintf(stderr,
586 "--mv-level-min must be less than or equal to --mv-level-max\n"); 642 "--mv-level-min must be less than or equal to --mv-level-max\n");
587 exit(1); 643 exit(1);
588 } 644 }
589 } 645 }
590 else if (strcmp(OPTIONS[loi].name, "mv-level-max") == 0) { 646 else if (strcmp(OPTIONS[loi].name, "mv-level-max") == 0) {
591 mv_level_max = atoi(optarg); 647 mv_level_max = atoi(optarg);
592 if (mv_level_max < 0 || mv_level_max > 4) { 648 if (mv_level_max < 0 || mv_level_max > 6) {
593 fprintf(stderr, "Illegal value for --mv-level-max\n"); 649 fprintf(stderr, "Illegal value for --mv-level-max\n");
594 exit(1); 650 exit(1);
595 } 651 }
596 if (mv_level_min > mv_level_max) { 652 if (mv_level_min > mv_level_max) {
597 fprintf(stderr, 653 fprintf(stderr,
598 "--mv-level-max must be greater than or equal to --mv-level-min\n") ; 654 "--mv-level-max must be greater than or equal to --mv-level-min\n") ;
599 exit(1); 655 exit(1);
600 } 656 }
657 }
658 else if (strcmp(OPTIONS[loi].name, "version") == 0) {
659 version();
601 } 660 }
602 break; 661 break;
603 } 662 }
604 case 'h': 663 case 'h':
605 default: usage(); break; 664 default: usage(); break;
606 } 665 }
607 } 666 }
608 avin.video_img = &avin.video_buf1; 667 avin.video_img = &avin.video_buf1;
609 668
610 /*Assume anything following the options must be a file name.*/ 669 /*Assume anything following the options must be a file name.*/
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 di.pixel_aspect_numerator = avin.video_par_n; 709 di.pixel_aspect_numerator = avin.video_par_n;
651 di.pixel_aspect_denominator = avin.video_par_d; 710 di.pixel_aspect_denominator = avin.video_par_d;
652 di.nplanes = avin.video_nplanes; 711 di.nplanes = avin.video_nplanes;
653 memcpy(di.plane_info, avin.video_plane_info, 712 memcpy(di.plane_info, avin.video_plane_info,
654 di.nplanes*sizeof(*di.plane_info)); 713 di.nplanes*sizeof(*di.plane_info));
655 di.keyframe_rate = video_keyframe_rate; 714 di.keyframe_rate = video_keyframe_rate;
656 /*TODO: Other crap.*/ 715 /*TODO: Other crap.*/
657 dd = daala_encode_create(&di); 716 dd = daala_encode_create(&di);
658 daala_comment_init(&dc); 717 daala_comment_init(&dc);
659 /*Set up encoder.*/ 718 /*Set up encoder.*/
660 daala_encode_ctl(dd, OD_SET_QUANT, &video_q, sizeof(int)); 719 daala_encode_ctl(dd, OD_SET_QUANT, &video_q, sizeof(video_q));
661 daala_encode_ctl(dd, OD_SET_MC_USE_CHROMA, &mc_use_chroma, sizeof(int)); 720 daala_encode_ctl(dd, OD_SET_COMPLEXITY, &complexity, sizeof(complexity));
662 daala_encode_ctl(dd, OD_SET_MV_RES_MIN, &mv_res_min, sizeof(int)); 721 daala_encode_ctl(dd, OD_SET_MC_USE_CHROMA, &mc_use_chroma,
663 daala_encode_ctl(dd, OD_SET_MV_LEVEL_MIN, &mv_level_min, sizeof(int)); 722 sizeof(mc_use_chroma));
664 daala_encode_ctl(dd, OD_SET_MV_LEVEL_MAX, &mv_level_max, sizeof(int)); 723 daala_encode_ctl(dd, OD_SET_USE_ACTIVITY_MASKING, &use_activity_masking,
724 sizeof(use_activity_masking));
725 daala_encode_ctl(dd, OD_SET_MV_RES_MIN, &mv_res_min, sizeof(mv_res_min));
726 daala_encode_ctl(dd, OD_SET_QM, &qm, sizeof(qm));
727 daala_encode_ctl(dd, OD_SET_MV_LEVEL_MIN, &mv_level_min, sizeof(mv_level_min)) ;
728 daala_encode_ctl(dd, OD_SET_MV_LEVEL_MAX, &mv_level_max, sizeof(mv_level_max)) ;
665 /*Write the bitstream header packets with proper page interleave.*/ 729 /*Write the bitstream header packets with proper page interleave.*/
666 /*The first packet for each logical stream will get its own page 730 /*The first packet for each logical stream will get its own page
667 automatically.*/ 731 automatically.*/
668 if (daala_encode_flush_header(dd, &dc, &op) <= 0) { 732 if (daala_encode_flush_header(dd, &dc, &op) <= 0) {
669 fprintf(stderr, "Internal Daala library error.\n"); 733 fprintf(stderr, "Internal Daala library error.\n");
670 exit(1); 734 exit(1);
671 } 735 }
672 ogg_stream_packetin(&vo, &op); 736 ogg_stream_packetin(&vo, &op);
673 if (ogg_stream_pageout(&vo, &og) != 1) { 737 if (ogg_stream_pageout(&vo, &og) != 1) {
674 fprintf(stderr, "Internal Ogg library error.\n"); 738 fprintf(stderr, "Internal Ogg library error.\n");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } 773 }
710 } 774 }
711 /*Setup complete. 775 /*Setup complete.
712 Main compression loop.*/ 776 Main compression loop.*/
713 fprintf(stderr, "Compressing...\n"); 777 fprintf(stderr, "Compressing...\n");
714 video_ready = 0; 778 video_ready = 0;
715 for (;;) { 779 for (;;) {
716 ogg_page video_page; 780 ogg_page video_page;
717 double video_time; 781 double video_time;
718 size_t bytes_written; 782 size_t bytes_written;
783 video_ready = fetch_and_process_video(&avin, &video_page, &vo,
784 dd, video_ready, limit >= 0 ? &limit : NULL, skip > 0 ? &skip : NULL);
719 video_ready = fetch_and_process_video(&avin, &video_page, 785 video_ready = fetch_and_process_video(&avin, &video_page,
720 &vo, dd, video_ready, limit >= 0 ? &limit : NULL, 786 &vo, dd, video_ready, limit >= 0 ? &limit : NULL,
721 prefilter, input_q); 787 skip > 0 ? &skip : NULL, prefilter, input_q);
722 /*TODO: Fetch the next video page.*/ 788 /*TODO: Fetch the next video page.*/
723 /*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.*/
724 if (!video_ready) break; 790 if (!video_ready) break;
725 video_time = daala_granule_time(dd, ogg_page_granulepos(&video_page)); 791 video_time = daala_granule_time(dd, ogg_page_granulepos(&video_page));
726 bytes_written = 792 bytes_written =
727 fwrite(video_page.header, 1, video_page.header_len, outfile); 793 fwrite(video_page.header, 1, video_page.header_len, outfile);
728 if (bytes_written < (size_t)video_page.header_len) { 794 if (bytes_written < (size_t)video_page.header_len) {
729 fprintf(stderr, "Could not write page header to file.\n"); 795 fprintf(stderr, "Could not write page header to file.\n");
730 exit(1); 796 exit(1);
731 } 797 }
(...skipping 26 matching lines...) Expand all
758 _ogg_free(avin.video_buf1.planes[pli].data); 824 _ogg_free(avin.video_buf1.planes[pli].data);
759 _ogg_free(avin.video_buf2.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 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld