User:Lucongli/sandbox

Source: Wikipedia, the free encyclopedia.

下载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
  • cmake编译
 # 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

运行算法

  • 打开Eclipse导入c++工程
 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)
  • 编译并运行



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


配置插件运行环境

  • 安装gstreamer-1.8.3
 # 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
  • 安装glib-2.0
 # apt-get install glib-2.0 --fix-missing
  • 安装opencv-2.4.8
 参考wiki: LIVE Theta: Stitching-algorithm(ubuntu)重现

运行插件

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


编译安装opencv-3.3.0

  • 下载页面末端的源码
opencv: https://opencv.org/opencv-3-3.html
解压到目录~/opencv-3.3.0
  • 安装工具和依赖库
# 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
  • 手动或终端下载并安装gstreamer,得到头文件及链接库路径
  • 打开opencv-3.3.0/CMakeLists.txt,文件开始添加cmake编译所需的gstreamer的头文件和链接库路径:
 #下载编译后得到的gstreamer1.0及插件的头文件位置
 include_directories(/usr/local/include/gstreamer_include)
 #下载编译后得到的gstreamer1.0及插件的链接库位置
 link_directories(/usr/local/lib/gstreamer_lib)
  • cmake编译
 # 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
  • 添加环境变量
 头文件:
 添加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

下载并运行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
  • VideoJS代码
<!DOCTYPE HTML>
<html>
<head>
  <title>Video.js Test Suite</title>
<link href="//vjs.zencdn.net/4.10/video-js.css" rel="stylesheet">
<script src="//vjs.zencdn.net/4.10/video.js"></script>

</head>
<body>
 <video id="example_video_1" class="video-js vjs-default-skin" controls width="640" height="264"
     controls autoplay preload="auto" width="600" height="300"
     data-setup='{"techorder" : ["flash"] }'>

 <source src="rtmp://172.25.85.144:1935/myapp/test1" type="rtmp/mp4">

</video>
</body>
</html>
  • Theta 直播
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

编译并安装Gstreamer

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

  • 下载代码
# git clone https://github.com/GStreamer/gst-omx.git
# git clone https://github.com/GStreamer/gstreamer.git
# git clone https://github.com/GStreamer/gst-plugins-base.git


  • 编译 gstreamer
# cd gstreamer
# ./configure
# make 
# make install
  • 编译 gst-plugins-base
# cd gst-plugins-base
# ./autogen.sh --noconfigure
# ./configure

直播测试

  • Gstreamer + USB Camera
gst-launch-1.0 -e videotestsrc ! queue ! videoconvert ! x264enc ! flvmux streamable=true ! queue ! rtmpsink location='rtmp://172.25.85.144/myapp/justin live=true'
  • 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"
  • filesrc(video and audio)
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.
  • 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推音频流和视频流

推音频流

  • 查看音频设备,找到usb Ricoh Theta S的音频设备
 #cat /proc/asound/cards
  • 查看音频设备名称,找到对应的card,device数值
 #arecord -l
  • 打开Theta处于live模式,注:我的设备card,device值为2,0,即hw:后面的值
 #ffmpeg -f alsa -ar 32000 -ac 1 -i hw:2,0 -strict -2 -acodec aac -f flv local.mp3

推视频流

  • 查看设备
 #ls /dev
  • 打开Theta处于live模式,注:我的设备/dev/video0
 #ffmpeg -f video4linux2 -pix_fmt yuv422p -i /dev/video0 -pix_fmt yuv420p -vcodec libx264 -f flv local.mp4

同时推音频和视频流

 #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

  • install GStreamer
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 python-gi
sudo apt install python-gi
  • install python-gobject
sudo apt install python-gobject
  • 如果上述安装过后还是不好用,可以用如下的方法安装相应的gst python
sudo apt install python-gst-1.0



GPL和LGPL:

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