Skip to content

Commit

Permalink
Version 1.7.1 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgriffith authored Sep 16, 2023
1 parent 86e751a commit 70502c3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 55 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,3 @@ venv*/
.idea/

config.yaml
*.log
8 changes: 0 additions & 8 deletions .idea/raspberry_pi_streaming_setup.iml

This file was deleted.

61 changes: 29 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Raspberry Pi Camera / Webcam streaming helper scripts

This script is designed to help automate turing a raspberry pi with a
compatible video4linux2 camera into a MPEG-DASH / HLS streaming server.
compatible video4linux2 camera into a MPEG-DASH / HLS / RTSP streaming server.

The steps it will attempt to take:

Expand All @@ -11,8 +11,6 @@ The steps it will attempt to take:
* (DASH/HLS) Create index.html file to view video stream at
* Create systemd service and enable it

Note: THERE IS NO NEED TO COMPILE FFMPEG YOURSELF IN MOST CASES. ONLY DO IT IF YOU KNOW YOU NEED AN UNUSUAL ENCODER.

This script requires Python 3.6+

## Grab the script
Expand Down Expand Up @@ -50,33 +48,12 @@ If you are connecting to an external RTSP server, pass in the `rtsp-url` argumen
sudo python3 streaming_setup.py --rtsp --rtsp-url rtsp://192.168.1.123:8554/raspberrypi
```

## Compile FFmpeg
If you want to compile FFmpeg you will need to grab the `compile_ffmpeg.py` file.


```
curl -O https://raw.githubusercontent.com/cdgriffith/pi_streaming_setup/master/compile_ffmpeg.py
```

I suggest setting the user to `pi` if making in your home directory.

```
sudo python3 streaming_setup.py --run-as pi
```

If you will be compiling while running over SSH, please use in a background terminal like "tmux" or "screen".

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.


## Streaming Setup Script Options

```
sudo python streaming_setup.py --help
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]
[--safe]
[--index-file INDEX_FILE] [--on-reboot-file ON_REBOOT_FILE] [--systemd-file SYSTEMD_FILE] [--camera-info] [--minimal] [--safe]
streaming_setup version 1.7
Expand All @@ -101,26 +78,46 @@ optional arguments:
--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
--safe disable overwrite of existing or old scripts
```

## License
## Compile FFmpeg
If you want to compile FFmpeg you will need to grab the `compile_ffmpeg.py` file.

MIT License - Copyright (c) 2023 Chris Griffith
> This will take hours on most Raspberry Pi devices!
Note: THERE IS NO NEED TO COMPILE FFMPEG YOURSELF IN MOST CASES. ONLY DO IT IF YOU KNOW YOU NEED AN UNUSUAL ENCODER.

```
curl -O https://raw.githubusercontent.com/cdgriffith/pi_streaming_setup/master/compile_ffmpeg.py
```

I suggest setting the user to `pi` if making in your home directory.

```
sudo python3 compile_ffmpeg.py --run-as pi
```

If you will be compiling while running over SSH, please use in a background terminal like "tmux" or "screen".

Adding `--install` it will install it to `/usr/local/bin/ffmpeg`. You can always do this later yourself by
going into the `FFmpeg` folder and typing `make install`

If you are compiling FFmpeg, be aware, this will build a NON-REDISTRIBUTABLE FFmpeg.
You will not be able to share the built binaries under any license.

## License

MIT License - Copyright (c) 2020-2023 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))


## Changes
## Major Changes

### 1.7

Expand Down
24 changes: 23 additions & 1 deletion compile_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@
Be aware, this will build a NON-REDISTRIBUTABLE FFmpeg.
You will not be able to share the built binaries under any license.
The MIT License
Copyright (c) 2020-2023 Chris Griffith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import logging
import os
Expand All @@ -17,7 +39,7 @@
from argparse import ArgumentParser

__author__ = "Chris Griffith"
__version__ = "1.7"
__version__ = "1.7.1"

log = logging.getLogger("compile_ffmpeg")
command_log = logging.getLogger("compile_ffmpeg.command")
Expand Down
37 changes: 24 additions & 13 deletions streaming_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,43 @@
* Update rc.local to run required setup script on reboot
* Create index.html file to view video stream at
* Create systemd service and enable it
The MIT License
Copyright (c) 2020-2023 Chris Griffith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

import logging
import os
import sys
import shutil
import pwd
import datetime
import json
from subprocess import run, CalledProcessError, PIPE, STDOUT, Popen
from pathlib import Path
from argparse import ArgumentParser

__author__ = "Chris Griffith"
__version__ = "1.7"
__version__ = "1.7.1"

log = logging.getLogger("streaming_setup")
command_log = logging.getLogger("streaming_setup.command")
Expand Down Expand Up @@ -84,16 +106,9 @@ def parse_arguments():
parser.add_argument("--index-file", default="/var/lib/streaming/index.html")
parser.add_argument("--on-reboot-file", default="/var/lib/streaming/setup_streaming.sh")
parser.add_argument("--systemd-file", default="/etc/systemd/system/stream_camera.service")
parser.add_argument("--compile-ffmpeg", action="store_true")
parser.add_argument("--compile-only", action="store_true")
parser.add_argument(
"--camera-info", action="store_true", help="Show all detected cameras [/dev/video(0-9)] and exit"
)
parser.add_argument(
"--minimal",
action="store_true",
help="Minimal FFmpeg compile including h264, x264, alsa sound and fonts",
)

parser.add_argument("--safe", action="store_true", help="disable overwrite of existing or old scripts")
return parser.parse_args()
Expand Down Expand Up @@ -525,10 +540,6 @@ def main():

install_ffmpeg()

if args.compile_only:
log.info("Compile complete!")
return

if args.rtsp and not args.rtsp_url:
rtsp_systemd = Path("/etc/systemd/system/rtsp_server.service")
install_rtsp(rtsp_systemd)
Expand Down

0 comments on commit 70502c3

Please sign in to comment.