Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: source/libvpx/vpxenc.c

Issue 341293003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vpxdec.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 748
749 if (input->detect.buf_read == 4 749 if (input->detect.buf_read == 4
750 && file_is_y4m(input->detect.buf)) { 750 && file_is_y4m(input->detect.buf)) {
751 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, 751 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4,
752 input->only_i420) >= 0) { 752 input->only_i420) >= 0) {
753 input->file_type = FILE_TYPE_Y4M; 753 input->file_type = FILE_TYPE_Y4M;
754 input->width = input->y4m.pic_w; 754 input->width = input->y4m.pic_w;
755 input->height = input->y4m.pic_h; 755 input->height = input->y4m.pic_h;
756 input->framerate.numerator = input->y4m.fps_n; 756 input->framerate.numerator = input->y4m.fps_n;
757 input->framerate.denominator = input->y4m.fps_d; 757 input->framerate.denominator = input->y4m.fps_d;
758 input->use_i420 = 0; 758 input->fmt = input->y4m.vpx_fmt;
759 } else 759 } else
760 fatal("Unsupported Y4M stream."); 760 fatal("Unsupported Y4M stream.");
761 } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) { 761 } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
762 fatal("IVF is not supported as input."); 762 fatal("IVF is not supported as input.");
763 } else { 763 } else {
764 input->file_type = FILE_TYPE_RAW; 764 input->file_type = FILE_TYPE_RAW;
765 } 765 }
766 } 766 }
767 767
768 768
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 /* Use a max keyframe interval of 5 seconds, if none was 1052 /* Use a max keyframe interval of 5 seconds, if none was
1053 * specified on the command line. 1053 * specified on the command line.
1054 */ 1054 */
1055 if (!stream->config.have_kf_max_dist) { 1055 if (!stream->config.have_kf_max_dist) {
1056 double framerate = (double)global->framerate.num / global->framerate.den; 1056 double framerate = (double)global->framerate.num / global->framerate.den;
1057 if (framerate > 0.0) 1057 if (framerate > 0.0)
1058 stream->config.cfg.kf_max_dist = (unsigned int)(5.0 * framerate); 1058 stream->config.cfg.kf_max_dist = (unsigned int)(5.0 * framerate);
1059 } 1059 }
1060 } 1060 }
1061 1061
1062 static const char* file_type_to_string(enum VideoFileType t) {
1063 switch (t) {
1064 case FILE_TYPE_RAW: return "RAW";
1065 case FILE_TYPE_Y4M: return "Y4M";
1066 default: return "Other";
1067 }
1068 }
1069
1070 static const char* image_format_to_string(vpx_img_fmt_t f) {
1071 switch (f) {
1072 case VPX_IMG_FMT_I420: return "I420";
1073 case VPX_IMG_FMT_I422: return "I422";
1074 case VPX_IMG_FMT_I444: return "I444";
1075 case VPX_IMG_FMT_YV12: return "YV12";
1076 default: return "Other";
1077 }
1078 }
1062 1079
1063 static void show_stream_config(struct stream_state *stream, 1080 static void show_stream_config(struct stream_state *stream,
1064 struct VpxEncoderConfig *global, 1081 struct VpxEncoderConfig *global,
1065 struct VpxInputContext *input) { 1082 struct VpxInputContext *input) {
1066 1083
1067 #define SHOW(field) \ 1084 #define SHOW(field) \
1068 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field) 1085 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1069 1086
1070 if (stream->index == 0) { 1087 if (stream->index == 0) {
1071 fprintf(stderr, "Codec: %s\n", 1088 fprintf(stderr, "Codec: %s\n",
1072 vpx_codec_iface_name(global->codec->interface())); 1089 vpx_codec_iface_name(global->codec->interface()));
1073 fprintf(stderr, "Source file: %s Format: %s\n", input->filename, 1090 fprintf(stderr, "Source file: %s File Type: %s Format: %s\n",
1074 input->use_i420 ? "I420" : "YV12"); 1091 input->filename,
1092 file_type_to_string(input->file_type),
1093 image_format_to_string(input->fmt));
1075 } 1094 }
1076 if (stream->next || stream->index) 1095 if (stream->next || stream->index)
1077 fprintf(stderr, "\nStream Index: %d\n", stream->index); 1096 fprintf(stderr, "\nStream Index: %d\n", stream->index);
1078 fprintf(stderr, "Destination file: %s\n", stream->config.out_fn); 1097 fprintf(stderr, "Destination file: %s\n", stream->config.out_fn);
1079 fprintf(stderr, "Encoder parameters:\n"); 1098 fprintf(stderr, "Encoder parameters:\n");
1080 1099
1081 SHOW(g_usage); 1100 SHOW(g_usage);
1082 SHOW(g_threads); 1101 SHOW(g_threads);
1083 SHOW(g_profile); 1102 SHOW(g_profile);
1084 SHOW(g_w); 1103 SHOW(g_w);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 1257
1239 frame_start = (cfg->g_timebase.den * (int64_t)(frames_in - 1) 1258 frame_start = (cfg->g_timebase.den * (int64_t)(frames_in - 1)
1240 * global->framerate.den) 1259 * global->framerate.den)
1241 / cfg->g_timebase.num / global->framerate.num; 1260 / cfg->g_timebase.num / global->framerate.num;
1242 next_frame_start = (cfg->g_timebase.den * (int64_t)(frames_in) 1261 next_frame_start = (cfg->g_timebase.den * (int64_t)(frames_in)
1243 * global->framerate.den) 1262 * global->framerate.den)
1244 / cfg->g_timebase.num / global->framerate.num; 1263 / cfg->g_timebase.num / global->framerate.num;
1245 1264
1246 /* Scale if necessary */ 1265 /* Scale if necessary */
1247 if (img && (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) { 1266 if (img && (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) {
1267 if (img->fmt != VPX_IMG_FMT_I420 && img->fmt != VPX_IMG_FMT_YV12) {
1268 fprintf(stderr, "%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1269 exit(EXIT_FAILURE);
1270 }
1271 #if CONFIG_LIBYUV
1248 if (!stream->img) 1272 if (!stream->img)
1249 stream->img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 1273 stream->img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420,
1250 cfg->g_w, cfg->g_h, 16); 1274 cfg->g_w, cfg->g_h, 16);
1251 I420Scale(img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], 1275 I420Scale(img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y],
1252 img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], 1276 img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U],
1253 img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], 1277 img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V],
1254 img->d_w, img->d_h, 1278 img->d_w, img->d_h,
1255 stream->img->planes[VPX_PLANE_Y], 1279 stream->img->planes[VPX_PLANE_Y],
1256 stream->img->stride[VPX_PLANE_Y], 1280 stream->img->stride[VPX_PLANE_Y],
1257 stream->img->planes[VPX_PLANE_U], 1281 stream->img->planes[VPX_PLANE_U],
1258 stream->img->stride[VPX_PLANE_U], 1282 stream->img->stride[VPX_PLANE_U],
1259 stream->img->planes[VPX_PLANE_V], 1283 stream->img->planes[VPX_PLANE_V],
1260 stream->img->stride[VPX_PLANE_V], 1284 stream->img->stride[VPX_PLANE_V],
1261 stream->img->d_w, stream->img->d_h, 1285 stream->img->d_w, stream->img->d_h,
1262 kFilterBox); 1286 kFilterBox);
1263
1264 img = stream->img; 1287 img = stream->img;
1288 #else
1289 stream->encoder.err = 1;
1290 ctx_exit_on_error(&stream->encoder,
1291 "Stream %d: Failed to encode frame.\n"
1292 "Scaling disabled in this configuration. \n"
1293 "To enable, configure with --enable-libyuv\n",
1294 stream->index);
1295 #endif
1265 } 1296 }
1266 1297
1267 vpx_usec_timer_start(&timer); 1298 vpx_usec_timer_start(&timer);
1268 vpx_codec_encode(&stream->encoder, img, frame_start, 1299 vpx_codec_encode(&stream->encoder, img, frame_start,
1269 (unsigned long)(next_frame_start - frame_start), 1300 (unsigned long)(next_frame_start - frame_start),
1270 0, global->deadline); 1301 0, global->deadline);
1271 vpx_usec_timer_mark(&timer); 1302 vpx_usec_timer_mark(&timer);
1272 stream->cx_time += vpx_usec_timer_elapsed(&timer); 1303 stream->cx_time += vpx_usec_timer_elapsed(&timer);
1273 ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame", 1304 ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame",
1274 stream->index); 1305 stream->index);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 int res = 0; 1525 int res = 0;
1495 1526
1496 exec_name = argv_[0]; 1527 exec_name = argv_[0];
1497 1528
1498 if (argc < 3) 1529 if (argc < 3)
1499 usage_exit(); 1530 usage_exit();
1500 1531
1501 /* Setup default input stream settings */ 1532 /* Setup default input stream settings */
1502 input.framerate.numerator = 30; 1533 input.framerate.numerator = 30;
1503 input.framerate.denominator = 1; 1534 input.framerate.denominator = 1;
1504 input.use_i420 = 1;
1505 input.only_i420 = 1; 1535 input.only_i420 = 1;
1506 1536
1507 /* First parse the global configuration values, because we want to apply 1537 /* First parse the global configuration values, because we want to apply
1508 * other parameters on top of the default configuration provided by the 1538 * other parameters on top of the default configuration provided by the
1509 * codec. 1539 * codec.
1510 */ 1540 */
1511 argv = argv_dup(argc - 1, argv_ + 1); 1541 argv = argv_dup(argc - 1, argv_ + 1);
1512 parse_global_config(&global, argv); 1542 parse_global_config(&global, argv);
1513 1543
1544 input.fmt = global.use_i420 ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_YV12;
1514 1545
1515 { 1546 {
1516 /* Now parse each stream's parameters. Using a local scope here 1547 /* Now parse each stream's parameters. Using a local scope here
1517 * due to the use of 'stream' as loop variable in FOREACH_STREAM 1548 * due to the use of 'stream' as loop variable in FOREACH_STREAM
1518 * loops 1549 * loops
1519 */ 1550 */
1520 struct stream_state *stream = NULL; 1551 struct stream_state *stream = NULL;
1521 1552
1522 do { 1553 do {
1523 stream = new_stream(&global, stream); 1554 stream = new_stream(&global, stream);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 if (global.verbose && pass == 0) 1635 if (global.verbose && pass == 0)
1605 FOREACH_STREAM(show_stream_config(stream, &global, &input)); 1636 FOREACH_STREAM(show_stream_config(stream, &global, &input));
1606 1637
1607 if (pass == (global.pass ? global.pass - 1 : 0)) { 1638 if (pass == (global.pass ? global.pass - 1 : 0)) {
1608 if (input.file_type == FILE_TYPE_Y4M) 1639 if (input.file_type == FILE_TYPE_Y4M)
1609 /*The Y4M reader does its own allocation. 1640 /*The Y4M reader does its own allocation.
1610 Just initialize this here to avoid problems if we never read any 1641 Just initialize this here to avoid problems if we never read any
1611 frames.*/ 1642 frames.*/
1612 memset(&raw, 0, sizeof(raw)); 1643 memset(&raw, 0, sizeof(raw));
1613 else 1644 else
1614 vpx_img_alloc(&raw, 1645 vpx_img_alloc(&raw, input.fmt, input.width, input.height, 32);
1615 input.use_i420 ? VPX_IMG_FMT_I420
1616 : VPX_IMG_FMT_YV12,
1617 input.width, input.height, 32);
1618 1646
1619 FOREACH_STREAM(stream->rate_hist = 1647 FOREACH_STREAM(stream->rate_hist =
1620 init_rate_histogram(&stream->config.cfg, 1648 init_rate_histogram(&stream->config.cfg,
1621 &global.framerate)); 1649 &global.framerate));
1622 } 1650 }
1623 1651
1624 FOREACH_STREAM(setup_pass(stream, &global, pass)); 1652 FOREACH_STREAM(setup_pass(stream, &global, pass));
1625 FOREACH_STREAM(open_output_file(stream, &global)); 1653 FOREACH_STREAM(open_output_file(stream, &global));
1626 FOREACH_STREAM(initialize_encoder(stream, &global)); 1654 FOREACH_STREAM(initialize_encoder(stream, &global));
1627 1655
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 } 1803 }
1776 fclose(f); 1804 fclose(f);
1777 }); 1805 });
1778 #endif 1806 #endif
1779 1807
1780 vpx_img_free(&raw); 1808 vpx_img_free(&raw);
1781 free(argv); 1809 free(argv);
1782 free(streams); 1810 free(streams);
1783 return res ? EXIT_FAILURE : EXIT_SUCCESS; 1811 return res ? EXIT_FAILURE : EXIT_SUCCESS;
1784 } 1812 }
OLDNEW
« no previous file with comments | « source/libvpx/vpxdec.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698