diff --git a/src/ustreamer/h264/encoder.c b/src/ustreamer/h264/encoder.c index ddb5d85..ed31cea 100644 --- a/src/ustreamer/h264/encoder.c +++ b/src/ustreamer/h264/encoder.c @@ -48,7 +48,7 @@ h264_encoder_s *h264_encoder_init(void) { h264_encoder_s *enc; A_CALLOC(enc, 1); enc->gop = 45; // 60 - enc->bps = 5000 * 1000; // Kbps * 1000 + enc->bitrate = 5000; // Kbps enc->fps = 0; // FIXME: 30 or 0? https://github.com/6by9/yavta/blob/master/yavta.c#L210 enc->run = run; @@ -175,7 +175,7 @@ int h264_encoder_prepare(h264_encoder_s *enc, const frame_s *frame) { OFMT(type) = MMAL_ES_TYPE_VIDEO; OFMT(encoding) = MMAL_ENCODING_H264; OFMT(encoding_variant) = MMAL_ENCODING_VARIANT_H264_DEFAULT; - OFMT(bitrate) = enc->bps; + OFMT(bitrate) = enc->bitrate * 1000; OFMT(es->video.frame_rate.num) = enc->fps; OFMT(es->video.frame_rate.den) = 1; RUN(output_port->buffer_size) = RUN(output_port->buffer_size_recommended) * 4; @@ -205,8 +205,8 @@ int h264_encoder_prepare(h264_encoder_s *enc, const frame_s *frame) { SET_PORT_PARAM(output, boolean, VIDEO_IMMUTABLE_INPUT, MMAL_FALSE); SET_PORT_PARAM(output, boolean, VIDEO_DROPPABLE_PFRAMES, MMAL_FALSE); SET_PORT_PARAM(output, boolean, VIDEO_ENCODE_INLINE_HEADER, MMAL_TRUE); // SPS/PPS: https://github.com/raspberrypi/userland/issues/443 - SET_PORT_PARAM(output, uint32, VIDEO_BIT_RATE, enc->bps); - SET_PORT_PARAM(output, uint32, VIDEO_ENCODE_PEAK_RATE, enc->bps); + SET_PORT_PARAM(output, uint32, VIDEO_BIT_RATE, enc->bitrate * 1000); + SET_PORT_PARAM(output, uint32, VIDEO_ENCODE_PEAK_RATE, enc->bitrate * 1000); SET_PORT_PARAM(output, uint32, VIDEO_ENCODE_MIN_QUANT, 16); SET_PORT_PARAM(output, uint32, VIDEO_ENCODE_MAX_QUANT, 34); SET_PORT_PARAM(output, uint32, VIDEO_ENCODE_FRAME_LIMIT_BITS, 1000000); diff --git a/src/ustreamer/h264/encoder.h b/src/ustreamer/h264/encoder.h index 048660e..185cefa 100644 --- a/src/ustreamer/h264/encoder.h +++ b/src/ustreamer/h264/encoder.h @@ -58,7 +58,7 @@ typedef struct { typedef struct { unsigned gop; // Interval between keyframes - unsigned bps; // Bit-per-sec + unsigned bitrate; // Kbit-per-sec unsigned fps; h264_encoder_runtime_s *run; diff --git a/src/ustreamer/options.c b/src/ustreamer/options.c index 4e261da..bade381 100644 --- a/src/ustreamer/options.c +++ b/src/ustreamer/options.c @@ -90,6 +90,8 @@ enum _OPT_VALUES { ADD_SINK(JPEG) # ifdef WITH_OMX ADD_SINK(H264) + _O_H264_BITRATE, + _O_H264_GOP, # endif # undef ADD_SINK @@ -179,6 +181,8 @@ static const struct option _LONG_OPTS[] = { ADD_SINK(jpeg, JPEG) # ifdef WITH_OMX ADD_SINK(h264, H264) + {"h264-bitrate", required_argument, NULL, _O_H264_BITRATE}, + {"h264-gop", required_argument, NULL, _O_H264_GOP}, # endif # undef ADD_SINK @@ -431,6 +435,8 @@ int options_parse(options_s *options, device_s *dev, encoder_s *enc, stream_s *s ADD_SINK(jpeg, JPEG) # ifdef WITH_OMX ADD_SINK(h264, H264) + case _O_H264_BITRATE: OPT_NUMBER("--h264-bitrate", stream->h264_bitrate, 100, 16000, 0); + case _O_H264_GOP: OPT_NUMBER("--h264-gop", stream->h264_gop, 0, 60, 0); # endif # undef ADD_SINK @@ -662,6 +668,8 @@ static void _help(FILE *fp, device_s *dev, encoder_s *enc, stream_s *stream, ser ADD_SINK(jpeg, JPEG) # ifdef WITH_OMX ADD_SINK(h264, H264) + SAY(" --h264-bitrate ───── H264 bitrate in Kbps. Default: %u.\n", stream->h264_bitrate); + SAY(" --h264-gop ──────────── Intarval between keyframes. Default: %u.\n", stream->h264_gop); # endif # undef ADD_SINK # ifdef WITH_GPIO diff --git a/src/ustreamer/stream.c b/src/ustreamer/stream.c index 87bd222..2df7b49 100644 --- a/src/ustreamer/stream.c +++ b/src/ustreamer/stream.c @@ -62,6 +62,10 @@ stream_s *stream_init(device_s *dev, encoder_s *enc) { A_CALLOC(stream, 1); stream->last_as_blank = -1; stream->error_delay = 1; +# ifdef WITH_OMX + stream->h264_bitrate = 5000; // Kbps + stream->h264_gop = 30; +# endif stream->proc = proc; stream->video = video; stream->dev = dev; diff --git a/src/ustreamer/stream.h b/src/ustreamer/stream.h index 8965e29..839bd7f 100644 --- a/src/ustreamer/stream.h +++ b/src/ustreamer/stream.h @@ -81,6 +81,8 @@ typedef struct { memsink_s *jpeg_sink; # ifdef WITH_OMX memsink_s *h264_sink; + unsigned h264_bitrate; + unsigned h264_gop; # endif process_s *proc;