| OLD | NEW |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 void usage_exit() { | 63 void usage_exit() { |
| 64 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", | 64 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", |
| 65 exec_name); | 65 exec_name); |
| 66 exit(EXIT_FAILURE); | 66 exit(EXIT_FAILURE); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static void get_frame_stats(vpx_codec_ctx_t *ctx, | 69 static void get_frame_stats(vpx_codec_ctx_t *ctx, |
| 70 const vpx_image_t *img, | 70 const vpx_image_t *img, |
| 71 vpx_codec_pts_t pts, | 71 vpx_codec_pts_t pts, |
| 72 uint64_t duration, | 72 unsigned int duration, |
| 73 vpx_enc_frame_flags_t flags, | 73 vpx_enc_frame_flags_t flags, |
| 74 uint64_t deadline, | 74 unsigned int deadline, |
| 75 vpx_fixed_buf_t *stats) { | 75 vpx_fixed_buf_t *stats) { |
| 76 vpx_codec_iter_t iter = NULL; | 76 vpx_codec_iter_t iter = NULL; |
| 77 const vpx_codec_cx_pkt_t *pkt = NULL; | 77 const vpx_codec_cx_pkt_t *pkt = NULL; |
| 78 const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags, | 78 const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags, |
| 79 deadline); | 79 deadline); |
| 80 if (res != VPX_CODEC_OK) | 80 if (res != VPX_CODEC_OK) |
| 81 die_codec(ctx, "Failed to get frame stats."); | 81 die_codec(ctx, "Failed to get frame stats."); |
| 82 | 82 |
| 83 while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) { | 83 while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) { |
| 84 if (pkt->kind == VPX_CODEC_STATS_PKT) { | 84 if (pkt->kind == VPX_CODEC_STATS_PKT) { |
| 85 const uint8_t *const pkt_buf = pkt->data.twopass_stats.buf; | 85 const uint8_t *const pkt_buf = pkt->data.twopass_stats.buf; |
| 86 const size_t pkt_size = pkt->data.twopass_stats.sz; | 86 const size_t pkt_size = pkt->data.twopass_stats.sz; |
| 87 stats->buf = realloc(stats->buf, stats->sz + pkt_size); | 87 stats->buf = realloc(stats->buf, stats->sz + pkt_size); |
| 88 memcpy((uint8_t *)stats->buf + stats->sz, pkt_buf, pkt_size); | 88 memcpy((uint8_t *)stats->buf + stats->sz, pkt_buf, pkt_size); |
| 89 stats->sz += pkt_size; | 89 stats->sz += pkt_size; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 static void encode_frame(vpx_codec_ctx_t *ctx, | 94 static void encode_frame(vpx_codec_ctx_t *ctx, |
| 95 const vpx_image_t *img, | 95 const vpx_image_t *img, |
| 96 vpx_codec_pts_t pts, | 96 vpx_codec_pts_t pts, |
| 97 uint64_t duration, | 97 unsigned int duration, |
| 98 vpx_enc_frame_flags_t flags, | 98 vpx_enc_frame_flags_t flags, |
| 99 uint64_t deadline, | 99 unsigned int deadline, |
| 100 VpxVideoWriter *writer) { | 100 VpxVideoWriter *writer) { |
| 101 vpx_codec_iter_t iter = NULL; | 101 vpx_codec_iter_t iter = NULL; |
| 102 const vpx_codec_cx_pkt_t *pkt = NULL; | 102 const vpx_codec_cx_pkt_t *pkt = NULL; |
| 103 const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags, | 103 const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags, |
| 104 deadline); | 104 deadline); |
| 105 if (res != VPX_CODEC_OK) | 105 if (res != VPX_CODEC_OK) |
| 106 die_codec(ctx, "Failed to encode frame."); | 106 die_codec(ctx, "Failed to encode frame."); |
| 107 | 107 |
| 108 while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) { | 108 while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) { |
| 109 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { | 109 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 die_codec(&codec, "Failed to destroy codec."); | 221 die_codec(&codec, "Failed to destroy codec."); |
| 222 } | 222 } |
| 223 | 223 |
| 224 vpx_img_free(&raw); | 224 vpx_img_free(&raw); |
| 225 free(stats.buf); | 225 free(stats.buf); |
| 226 | 226 |
| 227 vpx_video_writer_close(writer); | 227 vpx_video_writer_close(writer); |
| 228 | 228 |
| 229 return EXIT_SUCCESS; | 229 return EXIT_SUCCESS; |
| 230 } | 230 } |
| OLD | NEW |