History

multi-res: restore v1.0.0 API

Move the notion of 0 bitrate implying skip deeper into the codec, rather than doing it at the multi-encoder API level. This preserves v1.0.0 ABI compatibility, rather than forcing a bump to v2.0.0 over a minor change. Also, this allows the case where the application can selectively enable and disable the larger resolution(s) without having to reinitialize the codec instace (for instance, if no target is receiving the full resolution stream). It's not clear how deep to push this check. It may be valuable to allow the framerate adaptation code to run, for example. Currently put the check as early as possible for simplicity, should reevaluate this as this feature gains real use.

John Koleszar committed 14 years ago

Commit d72c5361 parent c311b3b4 files · +36 −50Browse files

Unified · Split

4 files
  1. vp8/vp8_cx_iface.c +3 −0
  2. vp8_multi_resolution_encoder.c +29 −43
  3. vpx/src/vpx_encoder.c +2 −3
  4. vpx/vpx_encoder.h +2 −4
vp8/vp8_cx_iface.c+3−0
@@ -757,6 +757,9 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, · 756 unmodified lines
757757 {
758758 vpx_codec_err_t res = VPX_CODEC_OK;
759759
760+ if (!ctx->cfg.rc_target_bitrate)
761+ return res;
762+
760763 if (img)
761764 res = validate_img(ctx, img);
762765
vp8_multi_resolution_encoder.c+29−43
@@ -224,9 +224,6 @@ int main(int argc, char **argv) · 223 unmodified lines
224224 dsf[1] controls down sampling from level 1 to level 2;
225225 dsf[2] is not used. */
226226 vpx_rational_t dsf[NUM_ENCODERS] = {{2, 1}, {2, 1}, {1, 1}};
227− /* Encode starting from which resolution level. Normally it is 0 that
228− * means the original(highest) resolution. */
229− int s_lvl = 0;
230227
231228 if(argc!= (5+NUM_ENCODERS))
232229 die("Usage: %s <width> <height> <infile> <outfile(s)> <output psnr?>\n",
@@ -240,21 +237,6 @@ int main(int argc, char **argv) · 7 unmodified lines
240237 if(width < 16 || width%2 || height <16 || height%2)
241238 die("Invalid resolution: %ldx%ld", width, height);
242239
243− /* Check to see if we need to encode all resolution levels */
244− for (i=0; i<NUM_ENCODERS; i++)
245− {
246− if (target_bitrate[i])
247− break;
248− else
249− s_lvl += 1;
250− }
251−
252− if (s_lvl >= NUM_ENCODERS)
253− {
254− printf("No encoding: total number of encoders is 0!");
255− return 0;
256− }
257−
258240 /* Open input video file for encoding */
259241 if(!(infile = fopen(argv[3], "rb")))
260242 die("Failed to open %s for reading", argv[3]);
@@ -262,6 +244,12 @@ int main(int argc, char **argv) · 1 unmodified line
262244 /* Open output file for each encoder to output bitstreams */
263245 for (i=0; i< NUM_ENCODERS; i++)
264246 {
247+ if(!target_bitrate[i])
248+ {
249+ outfile[i] = NULL;
250+ continue;
251+ }
252+
265253 if(!(outfile[i] = fopen(argv[i+4], "wb")))
266254 die("Failed to open %s for writing", argv[i+4]);
267255 }
@@ -342,15 +330,18 @@ int main(int argc, char **argv) · 74 unmodified lines
342330 else
343331 read_frame_p = read_frame_by_row;
344332
333+ for (i=0; i< NUM_ENCODERS; i++)
334+ if(outfile[i])
335+ write_ivf_file_header(outfile[i], &cfg[i], 0);
336+
345337 /* Initialize multi-encoder */
346− if(vpx_codec_enc_init_multi(&codec[s_lvl], interface, &cfg[s_lvl], s_lvl,
347− NUM_ENCODERS,
348− (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[s_lvl]))
349− die_codec(&codec[s_lvl], "Failed to initialize encoder");
338+ if(vpx_codec_enc_init_multi(&codec[0], interface, &cfg[0], NUM_ENCODERS,
339+ (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[0]))
340+ die_codec(&codec[0], "Failed to initialize encoder");
350341
351342 /* The extra encoding configuration parameters can be set as follows. */
352343 /* Set encoding speed */
353− for ( i=s_lvl; i<NUM_ENCODERS; i++)
344+ for ( i=0; i<NUM_ENCODERS; i++)
354345 {
355346 int speed = -6;
356347 if(vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, speed))
@@ -360,25 +351,20 @@ int main(int argc, char **argv) · 3 unmodified lines
360351 * better performance. */
361352 {
362353 unsigned int static_thresh = 1000;
363− if(vpx_codec_control(&codec[s_lvl], VP8E_SET_STATIC_THRESHOLD,
364− static_thresh))
365− die_codec(&codec[s_lvl], "Failed to set static threshold");
354+ if(vpx_codec_control(&codec[0], VP8E_SET_STATIC_THRESHOLD, static_thresh))
355+ die_codec(&codec[0], "Failed to set static threshold");
366356 }
367357 /* Set static thresh = 0 for other encoders for better quality */
368− for ( i=s_lvl+1; i<NUM_ENCODERS; i++)
358+ for ( i=1; i<NUM_ENCODERS; i++)
369359 {
370360 unsigned int static_thresh = 0;
371− if(vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD,
372− static_thresh))
361+ if(vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, static_thresh))
373362 die_codec(&codec[i], "Failed to set static threshold");
374363 }
375364
376365 frame_avail = 1;
377366 got_data = 0;
378367
379− for (i=s_lvl ; i< NUM_ENCODERS; i++)
380− write_ivf_file_header(outfile[i], &cfg[i], 0);
381−
382368 while(frame_avail || got_data)
383369 {
384370 vpx_codec_iter_t iter[NUM_ENCODERS]={NULL};
@@ -405,11 +391,11 @@ int main(int argc, char **argv) · 20 unmodified lines
405391 }
406392
407393 /* Encode each frame at multi-levels */
408− if(vpx_codec_encode(&codec[s_lvl], frame_avail? &raw[s_lvl] : NULL,
394+ if(vpx_codec_encode(&codec[0], frame_avail? &raw[0] : NULL,
409395 frame_cnt, 1, flags, arg_deadline))
410− die_codec(&codec[s_lvl], "Failed to encode frame");
396+ die_codec(&codec[0], "Failed to encode frame");
411397
412− for (i=NUM_ENCODERS-1; i>=s_lvl ; i--)
398+ for (i=NUM_ENCODERS-1; i>=0 ; i--)
413399 {
414400 got_data = 0;
415401
@@ -452,10 +438,9 @@ int main(int argc, char **argv) · 36 unmodified lines
452438
453439 fclose(infile);
454440
455− for (i=s_lvl; i< NUM_ENCODERS; i++)
441+ printf("Processed %ld frames.\n",(long int)frame_cnt-1);
442+ for (i=0; i< NUM_ENCODERS; i++)
456443 {
457− printf("Processed %ld frames.\n",(long int)frame_cnt-1);
458−
459444 /* Calculate PSNR and print it out */
460445 if ( (show_psnr) && (psnr_count[i]>0) )
461446 {
@@ -475,16 +460,17 @@ int main(int argc, char **argv) · 13 unmodified lines
475460 if(vpx_codec_destroy(&codec[i]))
476461 die_codec(&codec[i], "Failed to destroy codec");
477462
463+ vpx_img_free(&raw[i]);
464+
465+ if(!outfile[i])
466+ continue;
467+
478468 /* Try to rewrite the file header with the actual frame count */
479469 if(!fseek(outfile[i], 0, SEEK_SET))
480470 write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1);
481− }
482−
483− for (i=0; i< NUM_ENCODERS; i++)
484− {
485471 fclose(outfile[i]);
486− vpx_img_free(&raw[i]);
487472 }
473+ printf("\n");
488474
489475 return EXIT_SUCCESS;
490476 }
vpx/src/vpx_encoder.c+2−3
@@ -69,7 +69,6 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, · 68 unmodified lines
6969 vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
7070 vpx_codec_iface_t *iface,
7171 vpx_codec_enc_cfg_t *cfg,
72− int s_lvl,
7372 int num_enc,
7473 vpx_codec_flags_t flags,
7574 vpx_rational_t *dsf,
@@ -100,7 +99,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, · 24 unmodified lines
10099
101100 if(!(res = iface->enc.mr_get_mem_loc(cfg, &mem_loc)))
102101 {
103− for (i = s_lvl; i < num_enc; i++)
102+ for (i = 0; i < num_enc; i++)
104103 {
105104 vpx_codec_priv_enc_mr_cfg_t mr_cfg;
106105
@@ -113,7 +112,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, · 6 unmodified lines
113112 }
114113
115114 mr_cfg.mr_low_res_mode_info = mem_loc;
116− mr_cfg.mr_total_resolutions = num_enc - s_lvl;
115+ mr_cfg.mr_total_resolutions = num_enc;
117116 mr_cfg.mr_encoder_id = num_enc-1-i;
118117 mr_cfg.mr_down_sampling_factor.num = dsf->num;
119118 mr_cfg.mr_down_sampling_factor.den = dsf->den;
vpx/vpx_encoder.h+2−4
@@ -688,7 +688,6 @@ extern "C" { · 687 unmodified lines
688688 * \param[in] ctx Pointer to this instance's context.
689689 * \param[in] iface Pointer to the algorithm interface to use.
690690 * \param[in] cfg Configuration to use, if known. May be NULL.
691− * \param[in] s_lvl Starting encoder id. Normally it is 0.
692691 * \param[in] num_enc Total number of encoders.
693692 * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
694693 * \param[in] dsf Pointer to down-sampling factors.
@@ -702,7 +701,6 @@ extern "C" { · 7 unmodified lines
702701 vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
703702 vpx_codec_iface_t *iface,
704703 vpx_codec_enc_cfg_t *cfg,
705− int s_lvl,
706704 int num_enc,
707705 vpx_codec_flags_t flags,
708706 vpx_rational_t *dsf,
@@ -713,8 +711,8 @@ extern "C" { · 4 unmodified lines
713711 *
714712 * Ensures the ABI version parameter is properly set.
715713 */
716−#define vpx_codec_enc_init_multi(ctx, iface, cfg, s_lvl, num_enc, flags, dsf) \
717− vpx_codec_enc_init_multi_ver(ctx, iface, cfg, s_lvl, num_enc, flags, dsf, \
714+#define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
715+ vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
718716 VPX_ENCODER_ABI_VERSION)
719717
720718

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