Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding configurable bitrate, readme updates from issues #17

Merged
merged 4 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ If you will be compiling while running over SSH, please use in a background term
If you are compilng FFmpeg, be aware, this will build a NON REDISTRIBUTABLE FFmpeg.
You will not be able to share the built binaries under any license.

This script requires Python 3.6+

## MPEG DASH / HLS

DASH is a great way to use your device as standalone streaming server with a easy to view webpage hosted on the Pi.
Expand Down Expand Up @@ -56,42 +58,40 @@ sudo python3 streaming_setup.py --compile-ffmpeg --run-as pi
## Script Options

```
usage: streaming_setup [-h] [-v] [-d DEVICE] [-s VIDEO_SIZE] [-f INPUT_FORMAT]
[-c CODEC] [--ffmpeg-params FFMPEG_PARAMS]
[--index-file INDEX_FILE]
[--on-reboot-file ON_REBOOT_FILE]
[--systemd-file SYSTEMD_FILE] [--compile-ffmpeg]
[--camera-info] [--minimal] [--run-as RUN_AS]
[--disable-fdk-aac] [--disable_avisynth]
[--disable-dav1d] [--disable-zimg] [--disable-kvazaar]
[--disable-libxavs] [--disable-libsrt] [--rebuild-all]
[--safe]

streaming_setup version 1.4.0
usage: streaming_setup [-h] [-v] [--ffmpeg-command] [-d DEVICE] [-s VIDEO_SIZE] [-r] [--rtsp-url RTSP_URL] [-f INPUT_FORMAT] [-b BITRATE]
[-c CODEC] [--ffmpeg-params FFMPEG_PARAMS] [--index-file INDEX_FILE] [--on-reboot-file ON_REBOOT_FILE]
[--systemd-file SYSTEMD_FILE] [--compile-ffmpeg] [--compile-only] [--camera-info]
[--minimal] [--run-as RUN_AS] [--disable-fdk-aac] [--disable_avisynth] [--disable-dav1d]
[--disable-zimg] [--disable-kvazaar] [--disable-libxavs] [--disable-libsrt] [--rebuild-all] [--safe]

streaming_setup version 1.6

optional arguments:
-h, --help show this help message and exit
-v, --version
--ffmpeg-command print the automated FFmpeg command and exit
-d DEVICE, -i DEVICE, --device DEVICE
Camera. Selected: /dev/video0
-s VIDEO_SIZE, --video-size VIDEO_SIZE
The video resolution from the camera (using 2592x1944)
The video resolution from the camera (using 1920x1080)
-r, --rtsp Use RTSP instead of DASH / HLS
--rtsp-url RTSP_URL Provide a remote RTSP url to connect to and don't set up a local server
-f INPUT_FORMAT, --input-format INPUT_FORMAT
The format the camera supports (using h264)
-b BITRATE, --bitrate BITRATE
Streaming bitrate, is auto calculated by default
-c CODEC, --codec CODEC
Conversion codec (using 'copy')
--ffmpeg-params FFMPEG_PARAMS
specify additional FFmpeg params, helpful if not
copying codec e.g.: '-b:v 4M -maxrate 4M -bufsize 8M'
specify additional FFmpeg params, helpful if not copying codec e.g.: '-b:v 4M -maxrate 4M -buffsize 8M'
--index-file INDEX_FILE
--on-reboot-file ON_REBOOT_FILE
--systemd-file SYSTEMD_FILE
--compile-ffmpeg
--compile-only
--camera-info Show all detected cameras [/dev/video(0-9)] and exit
--minimal Minimal FFmpeg compile including h264, x264, alsa
sound and fonts
--run-as RUN_AS compile programs as provided user (suggested 'pi',
defaults to 'root')
--minimal Minimal FFmpeg compile including h264, x264, alsa sound and fonts
--run-as RUN_AS compile programs as provided user (suggested 'pi', defaults to 'root')
--disable-fdk-aac Normally installed on full install
--disable_avisynth Normally installed on full install
--disable-dav1d Normally installed on full install
Expand All @@ -101,8 +101,17 @@ optional arguments:
--disable-libsrt Normally installed on full install
--rebuild-all Recompile all libraries
--safe disable overwrite of existing or old scripts

```

## License

MIT License - Copyright (c) 2020 Chris Griffith


## Debuging

### Error: ioctl(VIDIOC_STREAMON) failure : 1, Operation not permitted

Go into raspi-config and up the video memory (memory split) to 256 and reboot. (thanks to #15 [rezrov](https://github.com/cdgriffith/pi_streaming_setup/issues/15))

24 changes: 18 additions & 6 deletions streaming_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from argparse import ArgumentParser

__author__ = "Chris Griffith"
__version__ = "1.5.1"
__version__ = "1.6"

log = logging.getLogger("streaming_setup")
command_log = logging.getLogger("streaming_setup.command")
Expand Down Expand Up @@ -146,10 +146,13 @@ def parse_arguments():
parser.add_argument("--rtsp-url", default="",
help="Provide a remote RTSP url to connect to and don't set up a local server")
parser.add_argument("-f", "--input-format", default=fmt, help=f"The format the camera supports (using {fmt})")
parser.add_argument("-b", "--bitrate", default="dynamic", help=f"Streaming bitrate, is auto calculated by default."
f" (Will be ignored if the codec is 'copy')")
parser.add_argument("-c", "--codec", default=codec, help=f"Conversion codec (using '{codec}')")
parser.add_argument(
"--ffmpeg-params",
help="specify additional FFmpeg params, helpful if not copying codec e.g.: '-b:v 4M -maxrate 4M -buffsize 8M' ",
"--ffmpeg-params", default="",
help="specify additional FFmpeg params, MUST be doubled quoted! helpful "
"if not copying codec e.g.: '\"-b:v 4M -maxrate 4M -buffsize 8M\"' ",
)
parser.add_argument("--index-file", default="/var/lib/streaming/index.html")
parser.add_argument("--on-reboot-file", default="/var/lib/streaming/setup_streaming.sh")
Expand Down Expand Up @@ -658,17 +661,25 @@ def prepare_ffmpeg_command(input_format,
ffmpeg_params,
fmt,
disable_hls=False,
path=None):
path=None,
bitrate="dynamic"):
default_paths = {'dash': "/dev/shm/streaming/manifest.mpd",
"rtsp": "rtsp://localhost:8554/streaming"}
if not path:
path = default_paths[fmt]

if ffmpeg_params:
ffmpeg_params = ffmpeg_params.strip("\"'")

if codec != "copy":
if "-b" not in ffmpeg_params:
if "-b" not in ffmpeg_params and bitrate == "dynamic":
x, y = video_size.split("x")
bitrate = (int(x) * int(y) * 2) // 1024
ffmpeg_params += f" -b:v {bitrate}k"
else:
if not bitrate.lower().endswith(("m", "k", "g")):
bitrate += "k"
ffmpeg_params += f" -b:v {bitrate}"

if fmt == "dash":
out = ("-f dash -remove_at_exit 1 -window_size 5 -use_timeline 1 -use_template 1 "
Expand Down Expand Up @@ -807,7 +818,8 @@ def main():
codec=args.codec,
ffmpeg_params=args.ffmpeg_params,
fmt="rtsp" if args.rtsp else "dash",
path=output_path
path=output_path,
bitrate=args.bitrate
)

if args.ffmpeg_command:
Expand Down