1.将arch/arm/configs/bcmrpi_quick_defconfig复制到源码根目录并改名.config
2.打开menuconfig,对linux内核进行配置
make ARCH=armCROSS_COMPILE=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-menuconfig
3.编译
make ARCH=arm CROSS_COMPILE= CROSS_COMPILE=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-
1.配置busybox
make ARCH=armCROSS_COMPILE=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-menuconfig
2.编译
make ARCH=arm CROSS_COMPILE= CROSS_COMPILE=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-
1.将busybox中的_install目录下面的东西复制过去
2.创建系统运行必须的目录
3.添加必须的配置文件
raspivid -t 0 -o - -h 480 -w 800 -fps 20 -b1500000 | ffmpeg -i - -acodec copy -vcodec copy -f flvrtmp://0.0.0.0/live/livestream
done
fi
# create vchiq device
[ -x /etc/init.d/vchiq ] &&/etc/init.d/vchiq start
echo
echo Greetings from standalone Raspberry Pi
echo
if [ -f /proc/cmdline -a -x/usr/local/bin/rpitestmode.sh ]; then
if grep rpitestmode /proc/cmdline>/dev/null; then
# wait for USB ennumeration to finish - otherwise test will fail
sleep 3
/usr/local/bin/rpitestmode.sh
fi
fi
# use an artificial SysRq-g to interrupt
# echo Attempting to enter the debugger!....
# echo g > /proc/sysrq-trigger
Vi etc/init.d/vchiq
将以下内容添加并保存
#! /bin/sh
### BEGIN INIT INFO
# Provides: vchiq
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: S
# Default-Stop: 0 6
# Short-Description: Creates /dev/vchiq.
# Description Searches /proc/devices for the vchiqdevice, and then
# creates /dev/vchiq usingthe found major device number.
# It is called from the bootscript.
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/vc/bin
echo $PATH
if ! type log_action_begin_msg >/dev/null 2>&1; then
log_action_begin_msg() { echo "$@"; }
fi
case "$1" in
start|restart|reload|force-reload|"")
[ "$VERBOSE" = no ] || log_action_begin_msg "Creatingvchiq device node"
rm -f /dev/vchiq
major=$(awk"\$2==\"vchiq\" {print \$1}" /proc/devices)
if [ -z "$major" ]; then
echo "Error: failed to locate vchiq device in /proc/devices"
exit 1
else
mknod /dev/vchiq c "$major" 0
chmod a+w /dev/vchiq
fi
;;
stop)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
*)
echo "Usage: vchiq start|stop" >&2
exit 3
;;
esac
:
添加dns服务配置
vi /etc/resolv.conf
nameserver 192.168.1.1
4.添加动态库
将/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/lib/目录下的动态链接库复制进rootfs/lib
cp -raf /home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/lib/*/rootfs/lib
剪裁动态库,去掉多余的东西
/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-strip /rootfs/lib/*so*
创建启动盘:将SD卡插进电脑,如果是虚拟机则再将sd卡连接到虚拟机上,在/dev /目录下查看SD卡的设备文件是那个
1、使用fdisk创建分区(fdisk用法不做详述)
创建分区1 :分区类型为primary ,大小12M就可以了,分区id为c
创建分区2:分区类型primery,大小大于50M分区id为83
以下是我的分区信息,供参考
Device Boot Start End Blocks Id System
/dev/sdc1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/sdc2 122880 15759359 7818240 83 Linux
2.将firmware/boot/中提供的启动代码复制进分区1中,可在Windows中直接复制,删除其中的两个内核镜像,将编译好的linux内核复制到该分区,并更名为kernel.img,
将制作好的根文件系统复制到分区二中
3.分区1中添加cmdline.txt文件
dwc_otg.lpm_enable=0 console=ttyAMA0,115200kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2init=/linuxrc rootfstype=ext4 elevator=deadline rootwait
~
4.分区1中添加config.txt文件
添加以下内容
start_x=1
gpu_mem=128
启动盘制作完成,可以启动系统看有没有问题
编译摄像头驱动:1.进入userland目录下的makefiles/cmake/toolchains/目录
Vi arm-linux-gnueabihf.cmake
将头几行改成
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-g++)
SET(CMAKE_ASM_COMPILER/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc)
SET(CMAKE_SYSTEM_PROCESSOR arm)
2.回到userland目录,运行buildme
./buildme
3.编译完成后,进入build目录,将编译好的东西复制进根文件系统
cp bin/* /rootfs/bin/
cp –a lib/* /rootfs/lib/
编译ffmpeg:(附录引用2)(我用的不是这个,原来那个现在打不开网页了,见附录引用3,现在这多了一步,我在文档中没有加进来,可能会出错,你悠着点) 1.将x264源码复制进ffmpeg源码目录,进入x264目录,运行configure
./configure--host=arm-unknown-linux-gnueabi --enable-static --disable-shared --host=arm-linux --disable-asm --cross-prefix==/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-
2.编译并安装x264
make
make install
3、配置ffmpeg,因为只用到了ffmpeg,所以把ffserver和ffplay禁用掉(禁用后大概35M,不禁用大概150M)
./configure --disable-ffserver--disable-ffplay --enable-static --enable-memalign-hack --enable-small--enable-decoder=h264 --enable-demuxers --enable-parsers --enable-protocols --enable-cross-compile--cross-prefix=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi---arch=arm --target-os=linux --prefix=./tmpfs--extra-cflags="-Ix264/" --extra-ldflags="-Lx264/"
4、编译并安装
make
make install
将会安装到ffmpeg目录下的tmpfs下面
5、进入tmpfs,复制bin目录下内容到rootfs/bin,复制lib内容到rootfs/lib
cp bin/* /rootfs/bin
cp –a lib/* /roofs/lib
进入x264 目录,复制bin目录下x264到rootfs/bin,复制libx264.arootfs/lib
cp x264 /rootfs/bin
cp libx264.a /roofs/lib
编译SRS(simple rtmp server) (附录引用4)进入srsd的 trunck目录
1.修改configure文件
vi configure
修改编译工具为自己使用的gcc
#####################################################################################
# generate auto headers file, depends onthe finished of options.sh
#####################################################################################
# the arm-ubuntu12 options for make fordepends
if [[ -z $SrsArmCC ]]; thenSrsArmCC="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc";fi
if [[ -z $SrsArmGCC ]]; thenSrsArmGCC="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc";fi
if [[ -z $SrsArmCXX ]]; thenSrsArmCXX="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-g++";fi
if [[ -z $SrsArmAR ]]; thenSrsArmAR="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ar";fi
if [[ -z $SrsArmLD ]]; thenSrsArmLD="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ld";fi
if [[ -z $SrsArmRANDLIB ]]; thenSrsArmRANDLIB="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ranlib";fi
echo "cc=$SrsArmCC gcc=$SrsArmGCCg++=$SrsArmCXX ar=$SrsArmAR ld=$SrsArmLD randlib=$SrsArmRANDLIB"
echo "#define SRS_AUTO_ARM_TOOL_CHAIN\"cc=$SrsArmCC gcc=$SrsArmGCC g++=$SrsArmCXX ar=$SrsArmAR ld=$SrsArmLDrandlib=$SrsArmRANDLIB\"" >> $SRS_AUTO_HEADERS_H
echo "" >> $SRS_AUTO_HEADERS_H
2、配置srs
./configure --with-hls --with-ssl--with-librtmp \
--without-ffmpeg --without-http-callback --without-bwtc--without-research \
--without-utest --without-gperf --without-gmc --without-gmp--without-gcp \
--without-gprof--without-arm-ubuntu12 –static
3、然后,重新编译ST,使用arm交叉编译工具:
cd ./objs/st-1.9&&
make clean&& patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
makeCC==/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc\
AR==/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ld\
RANDLIB==/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-randliblinux-debug
3、接着,重新编译ssl
cd ./objs/openssl-1.0.1f&&
rm -rf _release&& make clean &&
./Configure--prefix=`pwd`/_release -no-shared no-asm linux-armv4 &&
make CC=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc\
GCC=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc\
AR="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-arr" \
LD=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ld\
LINK=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc\
RANDLIB=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-randlib&&
make install
4、编译srs
makeGCC=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc\
CXX=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-g++\
AR==/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ar\
LINK==/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-g++server librtmp
5、复制编译好的内容到根文件系统
mkdir/rootfs/objs
cp objs/srs/rootfs/objs
cp -rf conf/rootfs/
conf中的是srs的启动配置文件
编译过程中可能会有cpu_conf未定义的错误,将其替换成1即可,
可以正常运行的摄像头监控系统基本搭建完成,就只差wifi配置工具了,可以用有线网测试系统运行是否正常,电脑端的ip设成192.168.100.1即可,RPI的ip为192.168.100.2
编译wpa_supplicant(附录引用5)进入wpa_supplicant的wpa_supplicant目录
1.修改.config文件
# Example configuration for variouscross-compilation platforms
#### sveasoft (e.g., for Linksys WRT54G)######################################
#CC=mipsel-uclibc-gcc
CC=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc-L/home/fan/openssl/lib
CFLAGS += -I/home/fan/openssl/include
#CPPFLAGS += -I../src/include-I../../src/router/openssl/include
LIBS += -L/home/fan/openssl/lib
其中的CC为编译用的gcc,并添加了-L指定链接库的目录,这里要修改我openssl的lib目录
Openssl在上一步的srs中已经编译,将目录指向它就行了
CFLAGS和LIBS都指向openssl的目录
2、编译
make
3、将编译出来的wpa_cli、wpa_passphrase、wpa_supplicant复制到根文件系统
完成将根文件系统复制到SD卡分区2
系统搭建到此完成,网络配置和程序的运行全部写进了etc/profile文件中
必须设置本地环回才能ping通自己,不然ffmpeg推流srs无法接收到,
Wifi配置工具可用,但是busybox自带的udhcpc命令无法给wlan0动态分配ip(可以从路由器获取到ip,但是不能设置到wlan0上)需要手动配置ip
观看视频流:
有6种flash播放器可用,把超链接地址的server改成树莓派的ip即可接收来着树莓派的rtmp视频流
Profile解释:/etc/profile: system-wide .profile file forthe Bourne shells
echo
echo -n "Processing /etc/profile..."
# no-op
exportPATH=$PATH:/opt/vc/bin //输出环境变量,是raspi*命令可用
ifconfig lo 127.0.0.1 //设置本地环回地址,没有的话只能ping同外网, ping同自己,无法使用0.0.0.0的ip
sleep 1s
ifconfig eth0192.168.100.2 //手动设置以太网ip
sleep 1s
echo "wlan configuring"
wpa_supplicant -B -iwlan0-c/etc/wpa_supplicant.conf //使用wifi配置工具配置wifi
sleep 1s
ifconfig wlan0192.168.1.19 //手动配置wifi的ip
route add default gw 192.168.1.1 //配置网关
echo "Done"
echo simple rtmp server starting
cd /
./objs/srs -c/conf/rtmp.conf //运行srs服务进程
sleep 1s
raspivid -t 0 -o - -h 480-w 800 -fps 20 -b 1500000 | ffmpeg -i - -acodec copy -vcodec copy -f flvrtmp://0.0.0.0/live/livestream //启动摄像头和ffmpeg推流
使用yeelink:1、在yeelink注册用户账户(不做说明)
注意在用户中心->账户->我的账户设置中可以查看ApiKey
在用户中心->我的设备->管理设备中可以查看设备地址
2、编译curl
进入curl源码目录
运行buildconf
./buildconf
运行配置脚本
CC=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-gcc AR=/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-arRANLIB="/home/fan/raspberry/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-ar-s" .configure --host=arm-riscos-aof --without-random --disable-shared
编译
make
安装
make install prefix=/rootfs
(一定要用绝对目录)
3、将跟新的文件系统复制到SD卡
4、在SD卡目录新建yeelink.sh
rm -f .yeelink.jpg
ffmpeg -i rtmp://0.0.0.0/live/livestream -r1 -vframes 1 -an -vcodec mjpeg .yeelink.jpg
其中ApiKey后的字符串和url后的地址根据不同的yeelink账户配置不同
修改权限
Chmod 777 yeelink.sh
5、添加用户与用户组(计划任务需要有用户)
在树莓派上使用busybox命令
adduser root
然后就会在etc目录下自动生成passwd 、group和shadow3个文件。但是运行该命令后会打印出如下消息: passwd:unknown uid 0
这表示不能为该用户设置密码,此时你会发现要passwd命令也无法使用。 解决的办法是,打开passwd文件,其内容为:
root:x:1000:1000:Linux User…:/home/root:/bin/sh
改为:
root::0:0:Linux User,,,:/home/root:/bin/sh
将用户ID和组ID均更改为0
打开group文件,其内容为: root:x:1000: 同样将组ID改为0 :
root::0:
6、添加计划任务
在profile中添加一行
crond –b
添加运行目录
mkdir var/spool & \
mkdir var/spool/cron & \
mkdir var/spool/cron/crontabs
重启树莓派,然后运行crontab命令,编辑计划任务
crontab –e
将下面内容复制进去
*/1 * * * * /yeelink.sh
保存。
Yeelink配置完成,将会每分钟上传一次图片到yeelink上面,可以通过yeelink查看上传的图片
附录:1、树莓派内核编译:
2、交叉编译树莓派的ffmpeg:
4、在rpi上编译srs:
5、编译wpa_supplicant:
6、SRS的中文wiki:
7、SRS使用网页播放器播放视频(支持多种播放器):