diff options
author | Mikhail Fludkov <misha@pexip.com> | 2015-11-26 19:52:29 +0300 |
---|---|---|
committer | GStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2020-06-04 23:14:03 +0300 |
commit | 7b390a8bbd0da33199e3c083f13bf5cd1a825a96 (patch) | |
tree | be8b12de1173bdd4888638c71208dd6d02062607 /tests | |
parent | b90dd2d755880d8dc0a956e47d7c3793cf563233 (diff) |
vpxenc: Add new bit-per-pixel property to select a better "default" bitrate
As part of this also change the default bitrate value to 0. The default
value was 256000 previously. In reality, if the property was not set the
bitrate value would be scaled according to the resolution which is not
very intuitive behavior. It is better to use 0 for this purpose. Now
together with newly introduced property "bits-per-pixel" 0 means to
assign the bitrate according to resolution/framerate.
The default bitrates are now
- 1.2Mbps for VP8 720p@30fps
- 0.8Mbps for VP9 720p@30fps
and scaled accordingly for different resolutions/framerates.
Previously the default bitrate was also not scaled according to the
framerate but only took the resolution into account.
This also fixes the side effect of setting bitrate to 0. Previously
encoder would not produce any data at all.
Addition from Sebastian Dröge <sebastian@centricular.com> to assume
30fps if no framerate is given in the caps instead of not calculating
any bitrate at all.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/611>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check/elements/vp8enc.c | 106 | ||||
-rw-r--r-- | tests/check/elements/vp9enc.c | 46 |
2 files changed, 151 insertions, 1 deletions
diff --git a/tests/check/elements/vp8enc.c b/tests/check/elements/vp8enc.c index 86b1d929d..e9d8c071f 100644 --- a/tests/check/elements/vp8enc.c +++ b/tests/check/elements/vp8enc.c @@ -17,8 +17,9 @@ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - +#include <gst/check/gstharness.h> #include <gst/check/gstcheck.h> +#include <gst/video/video.h> static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, @@ -90,6 +91,7 @@ cleanup_vp8enc (GstElement * vp8enc) gst_check_teardown_element (vp8enc); } + GST_START_TEST (test_encode_simple) { GstElement *vp8enc; @@ -152,6 +154,106 @@ GST_START_TEST (test_encode_simple) GST_END_TEST; +#define gst_caps_new_i420(w, h) gst_caps_new_i420_full (w, h, 30, 1, 1, 1) +static GstCaps * +gst_caps_new_i420_full (gint width, gint height, gint fps_n, gint fps_d, + gint par_n, gint par_d) +{ + GstVideoInfo info; + gst_video_info_init (&info); + gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, width, height); + GST_VIDEO_INFO_FPS_N (&info) = fps_n; + GST_VIDEO_INFO_FPS_D (&info) = fps_d; + GST_VIDEO_INFO_PAR_N (&info) = par_n; + GST_VIDEO_INFO_PAR_D (&info) = par_d; + return gst_video_info_to_caps (&info); +} + +static GstBuffer * +gst_harness_create_video_buffer_from_info (GstHarness * h, gint value, + GstVideoInfo * info, GstClockTime timestamp, GstClockTime duration) +{ + GstBuffer *buf; + gsize size; + + size = GST_VIDEO_INFO_SIZE (info); + + buf = gst_harness_create_buffer (h, size); + gst_buffer_memset (buf, 0, value, size); + g_assert (buf != NULL); + + gst_buffer_add_video_meta_full (buf, + GST_VIDEO_FRAME_FLAG_NONE, + GST_VIDEO_INFO_FORMAT (info), + GST_VIDEO_INFO_WIDTH (info), + GST_VIDEO_INFO_HEIGHT (info), + GST_VIDEO_INFO_N_PLANES (info), info->offset, info->stride); + + GST_BUFFER_PTS (buf) = timestamp; + GST_BUFFER_DURATION (buf) = duration; + + return buf; +} + +static GstBuffer * +gst_harness_create_video_buffer_full (GstHarness * h, gint value, + guint width, guint height, GstClockTime timestamp, GstClockTime duration) +{ + GstVideoInfo info; + + gst_video_info_init (&info); + gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, width, height); + + return gst_harness_create_video_buffer_from_info (h, value, &info, + timestamp, duration); +} + +GST_START_TEST (test_encode_simple_when_bitrate_set_to_zero) +{ + GstHarness *h = gst_harness_new_parse ("vp8enc target-bitrate=0"); + GstBuffer *buf; + + gst_harness_set_src_caps (h, gst_caps_new_i420 (320, 240)); + + buf = gst_harness_create_video_buffer_full (h, 0x42, + 320, 240, 0, gst_util_uint64_scale (GST_SECOND, 1, 30)); + gst_harness_push (h, buf); + gst_buffer_unref (gst_harness_pull (h)); + gst_harness_teardown (h); +} + +GST_END_TEST; + +GST_START_TEST (test_autobitrate_changes_with_caps) +{ + gint bitrate = 0; + GstHarness *h = gst_harness_new ("vp8enc"); + gst_harness_set_src_caps (h, gst_caps_new_i420_full (1280, 720, 30, 1, 1, 1)); + + /* Default settings for 720p @ 30fps ~1.2Mbps */ + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 1199000); + + /* Change bits-per-pixel 0.036 to give us ~1Mbps */ + g_object_set (h->element, "bits-per-pixel", 0.037, NULL); + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 1022000); + + /* Halving the framerate should halve the auto bitrate */ + gst_harness_set_src_caps (h, gst_caps_new_i420_full (1280, 720, 15, 1, 1, 1)); + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 511000); + + /* Halving the resolution should quarter the auto bitrate */ + gst_harness_set_src_caps (h, gst_caps_new_i420_full (640, 360, 15, 1, 1, 1)); + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 127000); + + gst_harness_teardown (h); +} + +GST_END_TEST; + static Suite * vp8enc_suite (void) { @@ -161,6 +263,8 @@ vp8enc_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_encode_simple); + tcase_add_test (tc_chain, test_encode_simple_when_bitrate_set_to_zero); + tcase_add_test (tc_chain, test_autobitrate_changes_with_caps); return s; } diff --git a/tests/check/elements/vp9enc.c b/tests/check/elements/vp9enc.c index f7be0e0fb..b7ae12fd9 100644 --- a/tests/check/elements/vp9enc.c +++ b/tests/check/elements/vp9enc.c @@ -21,6 +21,21 @@ #include <gst/check/gstcheck.h> #include <gst/video/video.h> +#define gst_caps_new_i420(w, h) gst_caps_new_i420_full (w, h, 30, 1, 1, 1) +static GstCaps * +gst_caps_new_i420_full (gint width, gint height, gint fps_n, gint fps_d, + gint par_n, gint par_d) +{ + GstVideoInfo info; + gst_video_info_init (&info); + gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, width, height); + GST_VIDEO_INFO_FPS_N (&info) = fps_n; + GST_VIDEO_INFO_FPS_D (&info) = fps_d; + GST_VIDEO_INFO_PAR_N (&info) = par_n; + GST_VIDEO_INFO_PAR_D (&info) = par_d; + return gst_video_info_to_caps (&info); +} + GST_START_TEST (test_encode_lag_in_frames) { GstHarness *h = gst_harness_new_parse ("vp9enc lag-in-frames=5 cpu-used=8 " @@ -62,6 +77,36 @@ GST_START_TEST (test_encode_lag_in_frames) GST_END_TEST; +GST_START_TEST (test_autobitrate_changes_with_caps) +{ + gint bitrate = 0; + GstHarness *h = gst_harness_new ("vp9enc"); + gst_harness_set_src_caps (h, gst_caps_new_i420_full (1280, 720, 30, 1, 1, 1)); + + /* Default settings for 720p @ 30fps ~0.8Mbps */ + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 799000); + + /* Change bits-per-pixel 0.036 to give us ~1Mbps */ + g_object_set (h->element, "bits-per-pixel", 0.037, NULL); + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 1022000); + + /* Halving the framerate should halve the auto bitrate */ + gst_harness_set_src_caps (h, gst_caps_new_i420_full (1280, 720, 15, 1, 1, 1)); + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 511000); + + /* Halving the resolution should quarter the auto bitrate */ + gst_harness_set_src_caps (h, gst_caps_new_i420_full (640, 360, 15, 1, 1, 1)); + g_object_get (h->element, "target-bitrate", &bitrate, NULL); + fail_unless_equals_int (bitrate, 127000); + + gst_harness_teardown (h); +} + +GST_END_TEST; + static Suite * vp9enc_suite (void) { @@ -71,6 +116,7 @@ vp9enc_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_encode_lag_in_frames); + tcase_add_test (tc_chain, test_autobitrate_changes_with_caps); return s; } |