2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Raspberry Pi zero WHでyoutubeライブ配信

Last updated at Posted at 2021-04-27

問題

ffmpegのパラメータ調べたり面倒くさそう。

解決策

alexellis2/streamingを使う。
Live stream to YouTube with your Raspberry Pi and Docker
YouTube live-streaming made easy

まずdocker、docker-composeを入れる

$ curl -sSL https://get.docker.com | sh
$ sudo usermod -aG docker <username>  # piとかに変える これでdockerコマンドがsudo無しで出来る
$ sudo apt update
$ sudo apt install -y python3-pip libffi-dev 
$ sudo pip3 install docker-compose # python経由で入れるとスルッと入る

docker-compose.ymlとentry.sh

docker-compose.yml
version: "3"
services:
  live:
    image: alexellis2/streaming:07-05-2018
    privileged: true
    volumes:
      - ./entry.sh:/root/entry.sh
    entrypoint: ["/root/entry.sh", "********自分のストリームキー********"]

元々のentry.shだとどうしてもfpsが20を下回り、youtube側でバッファの遅延が起きていたので、動画サイズを落として、ビットレートも落とした。

entry.sh
#!/bin/bash

echo Live-stream secret: $1
# https://support.google.com/youtube/answer/2853702#zippy=%2Cp%2Cp-fps
raspivid -o - -t 0 -w 1280 -h 720 -fps 30 -b 3000000 -g 40 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i pipe:0 -c:v copy -c:a aac -ab 128k -g 40 -strict experimental -f flv -r 30 rtmp://a.rtmp.youtube.com/live2/$1
オリジナルのentry.sh
#!/bin/bash

echo Live-stream secret: $1

raspivid -o - -t 0 -w 1920 -h 1080 -fps 40 -b 8000000 -g 40 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264
-i pipe:0 -c:v copy -c:a aac -ab 128k -g 40 -strict experimental -f flv -r 30 rtmp://a.rtmp.youtube.com/live2/$1

docker-compose.ymlentry.shを同じ場所に置いて

$ docker-compose run --rm live

とすると良いと思う。
-w 1280 -h 720 -fps 30 -b 3000000だとfps=25は出てた。(室温23℃前後、CPU温度55℃前後)

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?