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
5454 int h = 288;
5555 int frame_rate_num = 30;
5656 int frame_rate_den = 1;
57− int target_bitrate = 200;
57+ int target_bitrate = 1000;
5858 int num_frames = 17;
5959 // TODO(angiebird): Figure out how to upload test video to our codebase
6060 FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
@@ -83,8 +83,11 @@ TEST(SimpleEncode, EncodeFrame) { · 22 unmodified lines
8383 EXPECT_LT(encode_frame_result.show_idx, num_frames);
8484 if (i == num_coding_frames - 1) {
8585 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";
8787 }
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";
8891 }
8992 EXPECT_EQ(num_alternate_refereces, ref_num_alternate_refereces);
9093 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
53745374 mismatch_move_frame_idx_w();
53755375 #endif
53765376 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
5377−
5378− vp9_twopass_postencode_update(cpi);
53795377 }
53805378 #endif // !CONFIG_REALTIME_ONLY
53815379
@@ -7091,12 +7089,29 @@ static void init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result) { · 1709 unmodified lines
70917089 encode_frame_result->show_idx = -1; // Actual encoding deosn't happen.
70927090 }
70937091
7092+#if !CONFIG_REALTIME_ONLY
70947093 static void update_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result,
70957094 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];
70977111 encode_frame_result->show_idx = show_idx;
70987112 encode_frame_result->update_type = update_type;
70997113 }
7114+#endif // !CONFIG_REALTIME_ONLY
71007115
71017116 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
71027117 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
73497364 bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);
73507365 #endif
73517366
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−
73587367 cpi->td.mb.fp_src_pred = 0;
73597368 #if CONFIG_REALTIME_ONLY
73607369 if (cpi->use_svc) {
@@ -7381,6 +7390,25 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 20 unmodified lines
73817390 vp9_first_pass(cpi, source);
73827391 } else if (oxcf->pass == 2 && !cpi->use_svc) {
73837392 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);
73847412 } else if (cpi->use_svc) {
73857413 SvcEncode(cpi, size, dest, frame_flags);
73867414 } else {
vp9/encoder/vp9_encoder.h+2−0
@@ -825,6 +825,8 @@ typedef struct VP9_COMP { · 824 unmodified lines
825825 typedef struct ENCODE_FRAME_RESULT {
826826 int show_idx;
827827 FRAME_UPDATE_TYPE update_type;
828+ double psnr;
829+ uint64_t sse;
828830 } ENCODE_FRAME_RESULT;
829831
830832 void vp9_initialize_enc(void);
vp9/simple_encode.cc+2−0
@@ -90,6 +90,8 @@ static void update_encode_frame_result( · 89 unmodified lines
9090 encode_frame_result->show_idx = encode_frame_info->show_idx;
9191 encode_frame_result->frame_type =
9292 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;
9395 }
9496
9597 SimpleEncode::SimpleEncode(int frame_width, int frame_height,
vp9/simple_encode.h+2−1
@@ -14,7 +14,8 @@ struct EncodeFrameResult { · 13 unmodified lines
1414 // The EncodeFrame will allocate a buffer, write the coding data into the
1515 // buffer and give the ownership of the buffer to coding_data
1616 std::unique_ptr<unsigned char[]> coding_data;
17− // TODO(angiebird): double psnr;
17+ double psnr;
18+ uint64_t sse;
1819 // TODO(angiebird): int quantize_index ;
1920 };
2021

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