History

Add psnr and sse to EncodeFrameResult

angiebird committed 7 years ago

Commit 56735c31 parent 6956e395 files · +48 −12Browse files

Unified · Split

5 files
  1. test/simple_encode_test.cc +5 −2
  2. vp9/encoder/vp9_encoder.c +37 −9
  3. vp9/encoder/vp9_encoder.h +2 −0
  4. vp9/simple_encode.cc +2 −0
  5. vp9/simple_encode.h +2 −1
test/simple_encode_test.cc+5−2
@@ -54,7 +54,7 @@ TEST(SimpleEncode, EncodeFrame) { · 53 unmodified lines
54 int h = 288;54 int h = 288;
55 int frame_rate_num = 30;55 int frame_rate_num = 30;
56 int frame_rate_den = 1;56 int frame_rate_den = 1;
57 int target_bitrate = 200;57 int target_bitrate = 1000;
58 int num_frames = 17;58 int num_frames = 17;
59 // TODO(angiebird): Figure out how to upload test video to our codebase59 // TODO(angiebird): Figure out how to upload test video to our codebase
60 FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");60 FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
@@ -83,8 +83,11 @@ TEST(SimpleEncode, EncodeFrame) { · 22 unmodified lines
83 EXPECT_LT(encode_frame_result.show_idx, num_frames);83 EXPECT_LT(encode_frame_result.show_idx, num_frames);
84 if (i == num_coding_frames - 1) {84 if (i == num_coding_frames - 1) {
85 EXPECT_EQ(encode_frame_result.show_idx, num_frames - 1)85 EXPECT_EQ(encode_frame_result.show_idx, num_frames - 1)
86 << "The last coding frame should should be the last display order";86 << "The last coding frame should be the last display order";
87 }87 }
88 EXPECT_GE(encode_frame_result.psnr, 34)
89 << "The psnr is supposed to be greater than 34 given the "
90 "target_bitrate 1000 kbps";
88 }91 }
89 EXPECT_EQ(num_alternate_refereces, ref_num_alternate_refereces);92 EXPECT_EQ(num_alternate_refereces, ref_num_alternate_refereces);
90 simple_encode.EndEncode();93 simple_encode.EndEncode();
vp9/encoder/vp9_encoder.c+37−9
@@ -5374,8 +5374,6 @@ static void Pass2Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, · 5373 unmodified lines
5374 mismatch_move_frame_idx_w();5374 mismatch_move_frame_idx_w();
5375#endif5375#endif
5376 encode_frame_to_data_rate(cpi, size, dest, frame_flags);5376 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
5377
5378 vp9_twopass_postencode_update(cpi);
5379}5377}
5380#endif // !CONFIG_REALTIME_ONLY5378#endif // !CONFIG_REALTIME_ONLY
5381 5379
@@ -7091,12 +7089,29 @@ static void init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result) { · 1709 unmodified lines
7091 encode_frame_result->show_idx = -1; // Actual encoding deosn't happen.7089 encode_frame_result->show_idx = -1; // Actual encoding deosn't happen.
7092}7090}
7093 7091
7092#if !CONFIG_REALTIME_ONLY
7094static void update_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result,7093static void update_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result,
7095 int show_idx,7094 int show_idx,
7096 FRAME_UPDATE_TYPE update_type) {7095 FRAME_UPDATE_TYPE update_type,
7096 const YV12_BUFFER_CONFIG *source_frame,
7097 const YV12_BUFFER_CONFIG *coded_frame,
7098 uint32_t bit_depth,
7099 uint32_t input_bit_depth) {
7100 PSNR_STATS psnr;
7101#if CONFIG_VP9_HIGHBITDEPTH
7102 vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr, bit_depth,
7103 input_bit_depth);
7104#else
7105 (void)bit_depth;
7106 (void)input_bit_depth;
7107 vpx_calc_psnr(source_frame, coded_frame, &psnr);
7108#endif
7109 encode_frame_result->psnr = psnr.psnr[0];
7110 encode_frame_result->sse = psnr.sse[0];
7097 encode_frame_result->show_idx = show_idx;7111 encode_frame_result->show_idx = show_idx;
7098 encode_frame_result->update_type = update_type;7112 encode_frame_result->update_type = update_type;
7099}7113}
7114#endif // !CONFIG_REALTIME_ONLY
7100 7115
7101int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,7116int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
7102 size_t *size, uint8_t *dest, int64_t *time_stamp,7117 size_t *size, uint8_t *dest, int64_t *time_stamp,
@@ -7349,12 +7364,6 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 246 unmodified lines
7349 bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);7364 bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);
7350#endif7365#endif
7351 7366
7352 if (oxcf->pass != 1) {
7353 update_encode_frame_result(
7354 encode_frame_result, source->show_idx,
7355 cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index]);
7356 }
7357
7358 cpi->td.mb.fp_src_pred = 0;7367 cpi->td.mb.fp_src_pred = 0;
7359#if CONFIG_REALTIME_ONLY7368#if CONFIG_REALTIME_ONLY
7360 if (cpi->use_svc) {7369 if (cpi->use_svc) {
@@ -7381,6 +7390,25 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 20 unmodified lines
7381 vp9_first_pass(cpi, source);7390 vp9_first_pass(cpi, source);
7382 } else if (oxcf->pass == 2 && !cpi->use_svc) {7391 } else if (oxcf->pass == 2 && !cpi->use_svc) {
7383 Pass2Encode(cpi, size, dest, frame_flags);7392 Pass2Encode(cpi, size, dest, frame_flags);
7393 // update_encode_frame_result() depends on twopass.gf_group.index and
7394 // cm->new_fb_idx and cpi->Source are updated for current properly and have
7395 // not been updated for the next frame yet.
7396 // The update locations are as follows.
7397 // 1) twopass.gf_group.index is initialized at define_gf_group by vp9_zero()
7398 // for the first frame in the gf_group and is updated for the next frame at
7399 // vp9_twopass_postencode_update().
7400 // 2) cpi->Source is updated at the beginging of this function, i.e.
7401 // vp9_get_compressed_data()
7402 // 3) cm->new_fb_idx is updated at the beginging of this function by
7403 // get_free_fb(cm)
7404 // TODO(angiebird): Improve the codebase to make the update of frame
7405 // dependent variables more robust.
7406 update_encode_frame_result(
7407 encode_frame_result, source->show_idx,
7408 cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index],
7409 cpi->Source, get_frame_new_buffer(cm), cpi->oxcf.input_bit_depth,
7410 cm->bit_depth);
7411 vp9_twopass_postencode_update(cpi);
7384 } else if (cpi->use_svc) {7412 } else if (cpi->use_svc) {
7385 SvcEncode(cpi, size, dest, frame_flags);7413 SvcEncode(cpi, size, dest, frame_flags);
7386 } else {7414 } else {
vp9/encoder/vp9_encoder.h+2−0
@@ -825,6 +825,8 @@ typedef struct VP9_COMP { · 824 unmodified lines
825typedef struct ENCODE_FRAME_RESULT {825typedef struct ENCODE_FRAME_RESULT {
826 int show_idx;826 int show_idx;
827 FRAME_UPDATE_TYPE update_type;827 FRAME_UPDATE_TYPE update_type;
828 double psnr;
829 uint64_t sse;
828} ENCODE_FRAME_RESULT;830} ENCODE_FRAME_RESULT;
829 831
830void vp9_initialize_enc(void);832void vp9_initialize_enc(void);
vp9/simple_encode.cc+2−0
@@ -90,6 +90,8 @@ static void update_encode_frame_result( · 89 unmodified lines
90 encode_frame_result->show_idx = encode_frame_info->show_idx;90 encode_frame_result->show_idx = encode_frame_info->show_idx;
91 encode_frame_result->frame_type =91 encode_frame_result->frame_type =
92 get_frame_type_from_update_type(encode_frame_info->update_type);92 get_frame_type_from_update_type(encode_frame_info->update_type);
93 encode_frame_result->psnr = encode_frame_info->psnr;
94 encode_frame_result->sse = encode_frame_info->sse;
93}95}
94 96
95SimpleEncode::SimpleEncode(int frame_width, int frame_height,97SimpleEncode::SimpleEncode(int frame_width, int frame_height,
vp9/simple_encode.h+2−1
@@ -14,7 +14,8 @@ struct EncodeFrameResult { · 13 unmodified lines
14 // The EncodeFrame will allocate a buffer, write the coding data into the14 // The EncodeFrame will allocate a buffer, write the coding data into the
15 // buffer and give the ownership of the buffer to coding_data15 // buffer and give the ownership of the buffer to coding_data
16 std::unique_ptr<unsigned char[]> coding_data;16 std::unique_ptr<unsigned char[]> coding_data;
17 // TODO(angiebird): double psnr;17 double psnr;
18 uint64_t sse;
18 // TODO(angiebird): int quantize_index ;19 // TODO(angiebird): int quantize_index ;
19};20};
20 21

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