Skip to content

Commit 349c409

Browse files
committed
add command line argument for fps and bitrate. Move m4 installation to before flex
1 parent c4bf729 commit 349c409

File tree

2 files changed

+82
-47
lines changed

2 files changed

+82
-47
lines changed

kinesis-video-gst-demo/kinesis_video_gstreamer_sample_app.cpp

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static GstFlowReturn on_new_sample(GstElement *sink, CustomData *data) {
189189
} else {
190190
kinesis_video_flags = FRAME_FLAG_NONE;
191191
}
192+
192193
if (false == put_frame(data->kinesis_video_stream, frame_data, buffer_size, std::chrono::nanoseconds(buffer->pts),
193194
std::chrono::nanoseconds(buffer->dts), kinesis_video_flags)) {
194195
g_printerr("Dropped frame!\n");
@@ -200,20 +201,20 @@ static GstFlowReturn on_new_sample(GstElement *sink, CustomData *data) {
200201
return GST_FLOW_OK;
201202
}
202203

203-
static bool format_supported_by_source(GstCaps *src_caps, bool h264_stream, int width, int height) {
204+
static bool format_supported_by_source(GstCaps *src_caps, bool h264_stream, int width, int height, int framerate) {
204205
GstCaps *query_caps;
205206
query_caps = gst_caps_new_simple(h264_stream ? "video/x-h264" : "video/x-raw",
206207
"width", G_TYPE_INT, width,
207208
"height", G_TYPE_INT, height,
208-
"framerate", GST_TYPE_FRACTION, 30, 1,
209+
"framerate", GST_TYPE_FRACTION, framerate, 1,
209210
NULL);
210211
return gst_caps_can_intersect(query_caps, src_caps);
211212
}
212213

213-
static bool resolution_supported(GstCaps *src_caps, CustomData &data, int width, int height) {
214-
if (format_supported_by_source(src_caps, true, width, height)) {
214+
static bool resolution_supported(GstCaps *src_caps, CustomData &data, int width, int height, int framerate) {
215+
if (format_supported_by_source(src_caps, true, width, height, framerate)) {
215216
data.h264_stream_supported = true;
216-
} else if (format_supported_by_source(src_caps, false, width, height)) {
217+
} else if (format_supported_by_source(src_caps, false, width, height, framerate)) {
217218
data.h264_stream_supported = false;
218219
} else {
219220
return false;
@@ -322,7 +323,7 @@ int gstreamer_init(int argc, char* argv[]) {
322323

323324
if (argc < 2) {
324325
LOG_ERROR(
325-
"Usage: AWS_ACCESS_KEY_ID=SAMPLEKEY AWS_SECRET_ACCESS_KEY=SAMPLESECRET ./kinesis_video_gstreamer_sample_app my-stream-name width height");
326+
"Usage: AWS_ACCESS_KEY_ID=SAMPLEKEY AWS_SECRET_ACCESS_KEY=SAMPLESECRET ./kinesis_video_gstreamer_sample_app my-stream-name -w width -h height -f framerate -b bitrateInKBPS");
326327
return 1;
327328
}
328329

@@ -336,19 +337,53 @@ int gstreamer_init(int argc, char* argv[]) {
336337
/* init GStreamer */
337338
gst_init(&argc, &argv);
338339

340+
/* init stream format */
341+
int opt, width = 0, height = 0, framerate=30, bitrateInKBPS=512;
342+
char *endptr;
343+
while ((opt = getopt(argc, argv, "w:h:f:b:")) != -1) {
344+
switch (opt) {
345+
case 'w':
346+
width = strtol(optarg, &endptr, 0);
347+
if (*endptr != '\0') {
348+
g_printerr("Invalid width value.\n");
349+
return 1;
350+
}
351+
break;
352+
case 'h':
353+
height = strtol(optarg, &endptr, 0);
354+
if (*endptr != '\0') {
355+
g_printerr("Invalid height value.\n");
356+
return 1;
357+
}
358+
break;
359+
case 'f':
360+
framerate = strtol(optarg, &endptr, 0);
361+
if (*endptr != '\0') {
362+
g_printerr("Invalid framerate value.\n");
363+
return 1;
364+
}
365+
break;
366+
case 'b':
367+
bitrateInKBPS = strtol(optarg, &endptr, 0);
368+
if (*endptr != '\0') {
369+
g_printerr("Invalid bitrate value.\n");
370+
return 1;
371+
}
372+
break;
373+
default: /* '?' */
374+
g_printerr("Invalid arguments\n");
375+
return 1;
376+
}
377+
}
378+
339379
/* init Kinesis Video */
340380
char stream_name[MAX_STREAM_NAME_LEN];
341-
SNPRINTF(stream_name, MAX_STREAM_NAME_LEN, argv[1]);
381+
SNPRINTF(stream_name, MAX_STREAM_NAME_LEN, argv[optind]);
342382
kinesis_video_init(&data, stream_name);
343-
int width = 0, height = 0;
344-
char *endptr_w, *endptr_h;
345-
if (argc == 4) {
346-
width = strtol(argv[2], &endptr_w, 0);
347-
height = strtol(argv[3], &endptr_h, 0);
348-
if (*endptr_w != '\0' || *endptr_h != '\0') {
349-
g_printerr("Invalid resolution value.\n");
350-
return 1;
351-
}
383+
384+
if ((width == 0 && height != 0) || (width != 0 && height == 0)) {
385+
g_printerr("Invalid resolution\n");
386+
return 1;
352387
}
353388

354389
/* create the elemnents */
@@ -403,7 +438,7 @@ int gstreamer_init(int argc, char* argv[]) {
403438
gst_element_set_state(data.source, GST_STATE_NULL);
404439

405440
if (width != 0 && height != 0) {
406-
if (!resolution_supported(src_caps, data, width, height)) {
441+
if (!resolution_supported(src_caps, data, width, height, framerate)) {
407442
g_printerr("Resolution %dx%d not supported by video source\n", width, height);
408443
return 1;
409444
}
@@ -414,7 +449,7 @@ int gstreamer_init(int argc, char* argv[]) {
414449
for (int i = 0; i < res_width.size(); i++) {
415450
width = res_width[i];
416451
height = res_height[i];
417-
if (resolution_supported(src_caps, data, width, height)) {
452+
if (resolution_supported(src_caps, data, width, height, framerate)) {
418453
found_resolution = true;
419454
break;
420455
}
@@ -445,7 +480,7 @@ int gstreamer_init(int argc, char* argv[]) {
445480
"format", G_TYPE_STRING, "I420",
446481
"width", G_TYPE_INT, width,
447482
"height", G_TYPE_INT, height,
448-
"framerate", GST_TYPE_FRACTION, 30, 1,
483+
"framerate", GST_TYPE_FRACTION, framerate, 1,
449484
NULL);
450485
} else {
451486
source_caps = gst_caps_new_simple("video/x-h264",
@@ -461,11 +496,11 @@ int gstreamer_init(int argc, char* argv[]) {
461496
if (!data.h264_stream_supported){
462497
if (vtenc) {
463498
g_object_set(G_OBJECT (data.encoder), "allow-frame-reordering", FALSE, "realtime", TRUE, "max-keyframe-interval",
464-
45, "bitrate", 512, NULL);
499+
45, "bitrate", bitrateInKBPS, NULL);
465500
} else if (isOnRpi) {
466-
g_object_set(G_OBJECT (data.encoder), "control-rate", 1, "target-bitrate", 5000000, NULL);
501+
g_object_set(G_OBJECT (data.encoder), "control-rate", 1, "target-bitrate", bitrateInKBPS*10000, NULL);
467502
} else {
468-
g_object_set(G_OBJECT (data.encoder), "bframes", 0, "key-int-max", 45, "bitrate", 512, NULL);
503+
g_object_set(G_OBJECT (data.encoder), "bframes", 0, "key-int-max", 45, "bitrate", bitrateInKBPS, NULL);
469504
}
470505
}
471506

@@ -476,7 +511,7 @@ int gstreamer_init(int argc, char* argv[]) {
476511
"alignment", G_TYPE_STRING, "au",
477512
"width", G_TYPE_INT, width,
478513
"height", G_TYPE_INT, height,
479-
"framerate", GST_TYPE_FRACTION, 30, 1,
514+
"framerate", GST_TYPE_FRACTION, framerate, 1,
480515
NULL);
481516
if (!data.h264_stream_supported) {
482517
gst_caps_set_simple(h264_caps, "profile", G_TYPE_STRING, "baseline",

kinesis-video-native-build/install-script

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/bash
22
#
3-
# Installs the open source dependencies
3+
# Installs the open source dependencies
44
# for Kinesis Video Sdk demo application
5-
# and builds the demo application
5+
# and builds the demo application
66
#
77

88
set -e
99

1010
# Confirm the tools
11-
echo " Starting to build the Kinesis Video Stream Demo Application
11+
echo " Starting to build the Kinesis Video Stream Demo Application
1212
- will be using the following open source libraries and tools
1313
openssl
1414
curl
@@ -122,7 +122,7 @@ if [ ! -f $DOWNLOADS/local/lib/liblog4cplus.dylib ]; then
122122
cd $DOWNLOADS
123123
tar -xvf log4cplus-1.2.0.tar.xz
124124
cd $DOWNLOADS/log4cplus-1.2.0
125-
./configure --prefix=$DOWNLOADS/local/
125+
./configure --prefix=$DOWNLOADS/local/
126126
make
127127
make install
128128
fi
@@ -144,7 +144,7 @@ if [ ! -f $DOWNLOADS/local/lib/libgettextlib.dylib ]; then
144144
make install
145145
fi
146146
fi
147-
147+
148148

149149
echo "Checking libffi at $DOWNLOADS/local/lib/libffi.a"
150150
if [ ! -f $DOWNLOADS/local/lib/libffi.dylib ]; then
@@ -233,6 +233,21 @@ if [[ $PLATFORM == 'linux' ]]; then
233233
fi
234234
fi
235235

236+
#-------------------------install program m4 --------------------------------------------------------------------
237+
if [ ! -f $DOWNLOADS/local/bin/m4 ]; then
238+
echo "m4 not found. Installing"
239+
if [ ! -f $DOWNLOADS/m4-1.4.10.tar.gz ]; then
240+
cd $DOWNLOADS
241+
curl -L "http://ftpmirror.gnu.org/m4/m4-1.4.10.tar.gz" -o "m4-1.4.10.tar.xz"
242+
fi
243+
cd $DOWNLOADS
244+
tar -xvf m4-1.4.10.tar.xz
245+
cd $DOWNLOADS/m4-1.4.10
246+
./configure --prefix=$DOWNLOADS/local CFLAGS="-I$DOWNLOADS/local/include" LDFLAGS="-L$DOWNLOADS/local/lib"
247+
make
248+
make install
249+
fi
250+
236251
# ----- libfl.2.dylib and libfl.2.so ---------------------
237252
if [ ! -f $DOWNLOADS/local/lib/libfl.2.dylib ]; then
238253
if [ ! -f $DOWNLOADS/local/lib/libfl.2.so ]; then
@@ -244,7 +259,7 @@ fi
244259
fi
245260
cd $DOWNLOADS
246261
tar -xvf flex-2.6.4.tar.xz
247-
cd $DOWNLOADS/flex-2.6.4
262+
cd $DOWNLOADS/flex-2.6.4
248263
./configure --prefix=$DOWNLOADS/local CFLAGS="-I$DOWNLOADS/local/include" LDFLAGS="-L$DOWNLOADS/local/lib"
249264
make
250265
make install
@@ -281,7 +296,7 @@ fi
281296
make
282297
make install
283298
fi
284-
fi
299+
fi
285300
fi
286301

287302
# --------- glib ------------------------------------------
@@ -327,21 +342,6 @@ if [ ! -f $DOWNLOADS/local/lib/libgtest.dylib ]; then
327342
fi
328343
fi
329344

330-
#-------------------------install program m4 --------------------------------------------------------------------
331-
if [ ! -f $DOWNLOADS/local/bin/m4 ]; then
332-
echo "m4 not found. Installing"
333-
if [ ! -f $DOWNLOADS/m4-1.4.10.tar.gz ]; then
334-
cd $DOWNLOADS
335-
curl -L "http://ftpmirror.gnu.org/m4/m4-1.4.10.tar.gz" -o "m4-1.4.10.tar.xz"
336-
fi
337-
cd $DOWNLOADS
338-
tar -xvf m4-1.4.10.tar.xz
339-
cd $DOWNLOADS/m4-1.4.10
340-
./configure --prefix=$DOWNLOADS/local CFLAGS="-I$DOWNLOADS/local/include" LDFLAGS="-L$DOWNLOADS/local/lib"
341-
make
342-
make install
343-
fi
344-
345345
#-------------------autoconf, autoheader, autom4te, autoreconf, autoscan, autoupdate, and ifnames------------------
346346
if [ ! -f $DOWNLOADS/local/bin/autoconf ]; then
347347
echo "autoconf not found. Installing"
@@ -516,7 +516,7 @@ if [ ! -f $DOWNLOADS/local/lib/gstreamer-1.0/libgstx264.dylib ]; then
516516
make install
517517
fi
518518
fi
519-
519+
520520
echo "Checking for yasm"
521521
if [ ! -f $DOWNLOADS/local/bin/yasm ]; then
522522
echo "yasm-1.3.0.tar.gz not found. Installing"
@@ -563,7 +563,7 @@ if [ ! -f $DOWNLOADS/local/lib/gstreamer-1.0/libgstlibav.dylib ]; then
563563
fi
564564
fi
565565

566-
566+
567567
sys_info=`uname -m`
568568
shopt -s nocasematch
569569
if [[ $sys_info =~ ^arm ]]; then

0 commit comments

Comments
 (0)