我希望通过Raspberry Pi 3在YouTube上进行实时流传输。当我从shell手动运行时,脚本可以正常工作。当我将该脚本添加到文件sudo nano /etc/rc.local
中以在启动时自动运行时,它仅在Raspberry Pi下次启动时首次运行时停止运行,并显示错误“无法打开连接网络无法访问”。
这是我用于通过Raspberry Pi在YouTube上进行实时流式传输的脚本。
raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | avconv -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
我希望每次Raspberry Pi启动时都自动运行此脚本,而不会出现任何错误。
有关更多信息,请检查this链接。
答案 0 :(得分:0)
经过多次尝试,我找到了解决方案。 这很简单。只需在我的案例livestream.py中创建一个任何名称的新python文件,然后粘贴代码即可。
import os
os.system(raspivid -o - -t 0 -vf -hf -fps 25 -b 600000 | avconv -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
)
可以通过使用此脚本在Raspberry Pi中安装php来运行
sudo apt-get install php5-fpm php5-mysql
并运行文件livestream.php,PHP代码为
<?php
exec("raspivid -o - -t 0 -vf -hf -fps 25 -b 600000 | avconv -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
");
?>