前言:
最近做的一个项目需要使用arm开发板调用摄像头获取图片数据发送到后端,由于开发板是fedora系统,所以踩了不少坑。特此记录下来。
一.先对Fedora镜像源进行一次更新
https://developer.aliyun.com/mirror/fedora
1.如果在配置好后,获取 GPG 密钥失败:[Errno 14] curl#37 - “Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7”
https://blog.csdn.net/who__are__you_/article/details/82628390
2.如果安装包时出现:
$ dnf install xxx
$ Error: Failed to synchronize cache for repo
https://blog.csdn.net/l1175832366/article/details/104175396
3.如果运行sudo yum makecache生成缓存会报错:
执行以下命令:
sed -i 's/releases\/$releasever/releases\/32/g' /etc/yum.repos.d/fedora.repo
sed -i 's/updates\/$releasever/updates\/32/g' /etc/yum.repos.d/fedora-updates.repo
二.配置nginx和rtmp
https://blog.csdn.net/heng615975867/article/details/80519274 配置完成后,把下载目录里面的nginx-rtmp-module-master移到/usr/local/nginx中,因为可能没有移过去
三.配置FFmpeg
https://blog.csdn.net/weixin_30539625/article/details/98516616 安装完之后可能需要添加环境变量:
vim /etc/profile
添加一行
export PATH=/usr/local/ffmpeg/bin/:$PATH\
刷新环境
souce /etc/profile
四.在局域网内进行推流拉流
1.推流
将里面的地址修改成你要推流的地址
rtmpUrl = "rtmp://139.159.142.192:1935/live/1"
如果想要调用摄像头的参数设为0显示找不到摄像头,就参考下面的查找本机摄像头序号。因为我用的是AI开发板,所以直接输入0可能调用不了。
vid = cv2.VideoCapture(r"/usr/local/web/studey/mysite/chat/video/4.mp4")
import cv2
import queue
import os
import numpy as np
from threading import Thread
import datetime, _thread
import subprocess as sp
from time import *
mutex = _thread.allocate_lock()
frame_queue = queue.Queue()
rtmpUrl = "rtmp://139.159.142.192:1935/live/1"
command = ['ffmpeg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', "{}x{}".format(640, 480),
'-r', str(25.0),
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-f', 'flv',
rtmpUrl]
def Video():
vid = cv2.VideoCapture(r"/usr/local/web/studey/mysite/chat/video/4.mp4")
if not vid.isOpened():
raise IOError("Couldn't open webcam or video")
while (vid.isOpened()):
return_value, frame = vid.read()
frame_queue.put(frame)
def push_frame():
accum_time = 0
curr_fps = 0
fps = "FPS: ??"
prev_time = time()
while True:
if len(command) > 0:
p = sp.Popen(command, stdin=sp.PIPE)
break
while True:
if frame_queue.empty() != True:
frame = frame_queue.get()
p.stdin.write(frame.tostring())
def run():
thread1 = Thread(target=Video, )
thread1.start()
thread2 = Thread(target=push_frame, )
thread2.start()
if __name__ == '__main__':
run()
2.拉流
拉流使用你的推流地址
vid = cv2.VideoCapture("你的推流地址")
3.查看链接摄像头号:
https://blog.csdn.net/weixin_44345862/article/details/91047938?ops_request_misc=&request_id=&biz_id=102&utm_term=%E6%9F%A5%E7%9C%8B%E8%BF%9E%E6%8E%A5%E6%91%84%E5%83%8F%E5%A4%B4%E5%8F%B7&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-0-91047938.nonecase&spm=1018.2226.3001.4187
五.fedora进行opencv3.2配置
https://blog.csdn.net/keith_bb/article/details/54172899?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-2.tagcolumn&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-2.tagcolumn
|