User:Lucongli/sandbox

下载opencv-2.4.8
地址：https://github.com/opencv/opencv/releases?after=2.4.9 解压文件到：~/opencv-2.4.8

编译安装opencv-2.4.8
# apt-get install cmake pkg-config git build-essential # apt-get install python-dev python-numpy libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev # cd /home/用户名/ # mkdir opencv2.4.8-build # cd opencv-2.4.8 # mkdir build # cd build # cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/home/用户名/opencv2.4.8-build .. # make # make install # cp -rf /home/用户名/opencv2.4.8-build/lib/* /lib # cp -rf /home/用户名/opencv2.4.8-build/include/* /usr/include
 * 安装依赖库
 * cmake编译

运行算法
Eclipse(c++)下载地址:https://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/oxygen1a 工程文件夹svn地址：http://172.25.81.16/svn/LIVETheta/trunk/Stitching-algorithm(Ubuntu)
 * 打开Eclipse导入c++工程
 * 编译并运行

http://172.25.81.16/svn/LIVETheta/trunk/Stitching-algorithm(windows) 700px
 * 工程包svn地址
 * 运行环境：vs2012、win7
 * vs2012运行配置：release、win32
 * 打开工程，点击运行，控制台输出结果，结果图片没有保存

配置插件运行环境
# apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0- plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools # apt-get install glib-2.0 --fix-missing 参考wiki: LIVE Theta: Stitching-algorithm(ubuntu)重现
 * 安装gstreamer-1.8.3
 * 安装glib-2.0
 * 安装opencv-2.4.8

运行插件
svn地址：http://172.25.81.16/svn/LIVETheta/trunk/ 文件夹：Gstreamer-plugin(single-frame) # cd /home/用户名/ # chmod a+x plugin.sh # ./plugin.sh
 * 插件地址
 * 将Gstreamer-plugin(single-frame)/ 中的所有文件复制到 /home/用户名/
 * 运行插件
 * 在/home/用户名/ 下将生成拼接好的图片test2

= 编译安装opencv-3.3.0 = opencv: https://opencv.org/opencv-3-3.html 解压到目录~/opencv-3.3.0 #下载编译后得到的gstreamer1.0及插件的头文件位置 include_directories(/usr/local/include/gstreamer_include) #下载编译后得到的gstreamer1.0及插件的链接库位置 link_directories(/usr/local/lib/gstreamer_lib) # cd ~/opencv-3.3.0 # mkdir build # cd build # cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/home/congli-lu/opencv3.3.0-build .. # make # make install
 * 下载页面末端的源码
 * 安装工具和依赖库
 * 1) apt-get install cmake pkg-config git build-essential
 * 2) apt-get install python-dev python-numpy libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
 * 手动或终端下载并安装gstreamer，得到头文件及链接库路径
 * 打开opencv-3.3.0/CMakeLists.txt，文件开始添加cmake编译所需的gstreamer的头文件和链接库路径：
 * cmake编译

头文件： 添加C_INCLUDE_PATH路径： 方法1> 终端 # export C_INCLUDE_PATH=<你要加入的路径> 只能在当前终端使用，终端关闭则失效. 方法2> ~/.bashrc（用于当前用户） # gedit ~/.bashrc export C_INCLUDE_PATH=<你要加入的路径1>:<你要加入的路径2>: ......         :$C_INCLUDE_PATH 生效： 保存文件 # source ~/.bashrc 关闭并打开一个新的终端： # echo $C_INCLUDE_PATH 方法3> /etc/profile（用于所有用户） # gedit /etc/profile export C_INCLUDE_PATH=<你要加入的路径1>:<你要加入的路径2>: ......       :$C_INCLUDE_PATH 生效： 保存文件，注销系统重新登录 # echo $C_INCLUDE_PATH
 * 添加环境变量

.so: 方法1> 终端 # export LD_LIBRARY_PATH=<你要加入的路径> 只能在当前终端使用，终端关闭则失效. 方法2> ~/.bashrc（用于当前用户） # gedit ~/.bashrc export LD_LIBRARY_PATH=<你要加入的路径1>:<你要加入的路径2>: ...... :$LD_LIBRARY_PATH 生效： 保存文件 # source ~/.bashrc 关闭并打开一个新的终端： # echo $C_INCLUDE_PATH 方法3> /etc/ld.so.conf（用于所有用户） # gedit /etc/ld.so.conf <你要加入的路径1> <你要加入的路径2> ...    生效： # ldconfig

= 测试opencv-3.3.0 = # cd ~/opencv-3.3.0/samples # cmake. # make -j $(nproc) 下载一张人脸图片man.jpg放到路径：~/opencv-3.3.0/samples/app # cd ~/opencv-3.3.0/samples/app # ./cpp-example-facedetect man.jpg

= 安装docker=
 * Linux 参考 http://172.25.81.121/wiki/index.php/%E5%A6%82%E4%BD%95%E7%BC%96%E8%AF%91Theta_SDK%E9%A1%B9%E7%9B%AE#Install_Docker


 * Windows 参考 http://172.25.81.121/wiki/index.php/%E5%A6%82%E4%BD%95%E7%BC%96%E8%AF%91Theta_SDK%E9%A1%B9%E7%9B%AE#Build_the_project_on_Amazon_Linux_on_Windows_Docker

= 下载并运行GStreamer开发镜像 = $docker pull jthou/ubuntu-gstreamer
 * 下载

$docker run -ti -v ~/Document:/data jthou/Ubuntu-gstreamer
 * 运行

''注意：-v ~/Document:/data的含义是将host的Document目录映射到container中的/data目录，这样在container中就可以直接访问host中的文件.

= 设置Proxy= root@7552c4fae24f:#export http_proxy=http://z00bxxxx:yourpsswd@proxy.jp.ricoh.com:8080 = 编译并测试GStreamer插件模板= root@7552c4fae24f:#mkdir -p /home/justinhou root@7552c4fae24f:#cd /home/justinhou root@7552c4fae24f:/home/justinhou#git clone git://anongit.freedesktop.org/gstreamer/gst-template.git （参考源）git clone http://anongit.freedesktop.org/git/gstreamer/gst-template.git
 * 下载

root@7552c4fae24f:/home/justinhou#cd gst-template/gst-plugin root@7552c4fae24f:/home/justinhou/gst-template/gst-plugin# ./autogen.sh root@7552c4fae24f:/home/justinhou/gst-template/gst-plugin# make root@7552c4fae24f:/home/justinhou/gst-template/gst-plugin# make install
 * 编译

root@7552c4fae24f:/home/justinhou/gst-template/gst-plugin# export GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0 root@7552c4fae24f:/home/justinhou/gst-template/gst-plugin# gst-inspect-1.0 plugin Factory Details: Rank                    none (0) Long-name               Plugin Klass                   FIXME:Generic Description             FIXME:Generic Template Element Author                  AUTHOR_NAME AUTHOR_EMAIL
 * 测试

Plugin Details: Name                    plugin Description             Template plugin Filename                /usr/local/lib/gstreamer-1.0/libgstplugin.so  Version                  1.0.0 License                 LGPL Source module           my-plugin-package Binary package          GStreamer Origin URL              http://gstreamer.net/

GObject +GInitiallyUnowned +GstObject +GstElement +GstPluginTemplate

Pad Templates: SRC template: 'src' Availability: Always Capabilities: ANY

SINK template: 'sink' Availability: Always Capabilities: ANY

Element Flags: no flags set

Element Implementation: Has change_state function: gst_element_change_state_func

Element has no clocking capabilities. Element has no indexing capabilities. Element has no URI handling capabilities.

Pads: SINK: 'sink' Implementation: Has chainfunc: gst_plugin_template_chain Has custom eventfunc: gst_plugin_template_sink_event Has custom queryfunc: gst_pad_query_default Has custom iterintlinkfunc: gst_pad_iterate_internal_links_default Pad Template: 'sink' SRC: 'src' Implementation: Has custom eventfunc: gst_pad_event_default Has custom queryfunc: gst_pad_query_default Has custom iterintlinkfunc: gst_pad_iterate_internal_links_default Pad Template: 'src'

Element Properties: name               : The name of the object flags: readable, writable String. Default: "plugintemplate0" parent             : The parent of the object flags: readable, writable Object of type "GstObject" silent             : Produce verbose output ? flags: readable, writable Boolean. Default: false

root@7552c4fae24f:/home/justinhou/gst-template/gst-plugin# gst-launch-1.0 -v filesrc location=/data/1122645391.jpg ! plugin ! filesink location=/data/test.jpg
 * 运行

VideoJs测试
ffmpeg -re -i /home/boyuan/local.mp4 -f flv rtmp://172.25.85.144/myapp/test1
 * 开启直播

<!DOCTYPE HTML> Video.js Test Suite  
 * VideoJS代码





ffmpeg -f v4l2 -i /dev/video0 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -strict -2 -s 1920x1080 -vcodec libx264 -pix_ fmt yuv420p -g 10 -vb 2500k -profile:v baseline -r 5 -f flv rtmp://172.25.85.144:1935/myapp/test1
 * Theta 直播

编译并安装Gstreamer
Ubuntu默认的Gstreamer包中很多插件都没有，所以只能自己编译和安装


 * 下载代码
 * 1) git clone https://github.com/GStreamer/gst-omx.git
 * 2) git clone https://github.com/GStreamer/gstreamer.git
 * 3) git clone https://github.com/GStreamer/gst-plugins-base.git


 * 编译 gstreamer
 * 1) cd gstreamer
 * 2) ./configure
 * 3) make
 * 4) make install


 * 编译 gst-plugins-base
 * 1) cd gst-plugins-base
 * 2) ./autogen.sh --noconfigure
 * 3) ./configure

直播测试
gst-launch-1.0 -e videotestsrc ! queue ! videoconvert ! x264enc ! flvmux streamable=true ! queue ! rtmpsink location='rtmp://172.25.85.144/myapp/justin live=true'
 * Gstreamer + USB Camera


 * filesrc

GST_DEBUG=2 gst-launch-1.0 filesrc location="/home/justin/mv/lizongsheng_2.mkv" ! decodebin name=t  t. ! flvmux name=mux   t. ! audioconvert ! voaacenc bitrate=128000 ! queue ! mux. mux. ! rtmpsink location="rtmp://172.25.85.144/hls/justin live=true"

GST_DEBUG=2 gst-launch-1.0 filesrc location="/home/justin/mv/lizongsheng_2.mkv" ! decodebin name=t  t. ! flvmux name=mux   t. ! videoconvert ! x264enc ! mux. mux. ! rtmpsink location="rtmp://172.25.85.144/hls/justin live=true" t. ! audioconvert ! voaacenc ! mux.
 * filesrc（video and audio）


 * Gstreamer + Camera(video and audio)

GST_DEBUG=2 gst-launch-1.0 flvmux name=mux  alsasrc device=hw:1,0 provide-clock=false ! queue ! audioresample ! audioconvert ! voaacenc bitrate=128000 ! mux. mux. ! rtmpsink location="rtmp://172.25.85.144/hls/shc live=true" v4l2src device=/dev/video0 ! queue ! videoconvert ! x264enc tune=zerolatency ! mux.


 * Gstreamer + Theta S (audio only)

GST_DEBUG=2 gst-launch-1.0 flvmux name=mux alsasrc device=hw:1,0 provide-clock=false ! queue ! audioconvert ! voaacenc ! mux. mux. ! rtmpsink location="rtmp://172.25.85.144/hls/shc live=true"


 * Gstreamer + Theta S (video only)

GST_DEBUG=2 gst-launch-1.0 flvmux name=mux v4l2src device=/dev/video0 ! queue ! jpegdec ! videoconvert ! x264enc tune=zerolatency ! mux. mux. ! rtmpsink location="rtmp://172.25.85.144/hls/shc live=true"


 * Gstreamer + Theta S (video and audio)

GST_DEBUG=2 gst-launch-1.0 flvmux name=mux alsasrc device=hw:2,0 ! queue ! audioconvert ! voaacenc bitrate=128000 ! mux. mux. ! rtmpsink location="rtmp://172.25.85.144/hls/shc live=true" v4l2src device=/dev/video0 ! queue ! jpegdec ! x264enc tune=zerolatency ! mux.

ffmpeg推音频流和视频流
推音频流 #cat /proc/asound/cards
 * 查看音频设备，找到usb Ricoh Theta S的音频设备

#arecord -l
 * 查看音频设备名称，找到对应的card，device数值

#ffmpeg -f alsa -ar 32000 -ac 1 -i hw:2,0 -strict -2 -acodec aac -f flv local.mp3 推视频流 #ls /dev #ffmpeg -f video4linux2 -pix_fmt yuv422p -i /dev/video0 -pix_fmt yuv420p -vcodec libx264 -f flv local.mp4
 * 打开Theta处于live模式，注：我的设备card，device值为2,0,即hw:后面的值
 * 查看设备
 * 打开Theta处于live模式，注：我的设备/dev/video0

同时推音频和视频流 #ffmpeg -f video4linux2 -pix_fmt yuv422p -i /dev/video0 -f alsa -ar 32000 -ac 1 -i hw:2,0 -strict -2 -acodec aac -pix_fmt yuv420p -vcodec libx264 -fflags +genpts -f flv rtmp://172.25.85.144/hls/mystream1 备注：(直接通过浏览器访问172.25.85.144/videojsThetaLive.html观看)

Setup Python GStreamer Dev env
sudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools
 * install GStreamer

sudo apt install python-gi
 * install python-gi

sudo apt install python-gobject
 * install python-gobject

sudo apt install python-gst-1.0
 * 如果上述安装过后还是不好用，可以用如下的方法安装相应的gst python

GPL和LGPL： 动态链接-->随意发布 改源码、静态链接--> 1）开源相关.c/.cpp文件（做封装器可避免开源） 2）LGPL的.txt声明 3）提供整个项目的所有.o文件
 * GPL: 改源码、静态链接、动态链接-->整个程序源码开源并服从GPL（alias：poison）.
 * LGPL: