一、采集:使用python调用摄像头采集,原设想是使用树莓派摄像头采集,但是经费紧张买不起,先用摄像头凑合下,反正很简单。
                  原理就是先录一小段视频,然后循环播放,用celery做任务控制,每5秒钟录一段很小的视频,然后再循环录制。控制录制开始和停止的方法就是在redis钟设置一个键,录像程序运行的前提是这个键允许录制,如果要求录制停止就把这个键设置为停止。每5秒循环录制。正式使用后用python调用ffmpeg的命令进行推流直播,录制视频的格式是avi格式,要记得定时删除。录视频使用opencv的cv2库。注意安装最新版的opencv
二、安装simple rtmp server:从github上下载simple rtmp server,使用rtmp播放https://github.com/ossrs/srs。
                     安装方法http://blog.csdn.net/Henry_wk/article/details/50377881
                     安装时记得apt-get的源要使用默认源
                      安装好之后改配置文件,目录在trunk/conf/rtmp.conf,配置文件如下
                      
# the config for srs to delivery RTMP
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleRTMP
# @see full.conf for detail config.

listen              1935;
max_connections    1000;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    transcode {
        # whether the transcode enabled.
        # if off, donot transcode.
        # default: off.
        enabled    on;
        # the ffmpeg 
        ffmpeg      ./objs/ffmpeg/bin/ffmpeg;
        # the transcode engine for matched stream.
        # all matched stream will transcoded to the following stream.
        # the transcode set name(ie. hd) is optional and not used.
        engine example {
            # whether the engine is enabled
            # default: off.
            enabled        on;
            # input format, can be:
            # off, do not specifies the format, ffmpeg will guess it.
            # flv, for flv or RTMP stream.
            # other format, for example, mp4/aac whatever.
            # default: flv
            iformat        avi;
            # ffmpeg filters, follows the main input.
            vfilter {
                # the logo input file.
                i              ./doc/ffmpeg-logo.png;
                # the ffmpeg complex filter.
                # for filters, @see: http://ffmpeg.org/ffmpeg-filters.html
                filter_complex  'overlay=10:10';
            }
            # video encoder name. can be:
            #      libx264: use h.264(libx264) video encoder.
            #      copy: donot encoder the video stream, copy it.
            #      vn: disable video output.
            vcodec          libx264;
            # video bitrate, in kbps
            # @remark 0 to use source video bitrate.
            # default: 0
            vbitrate        1500;
            # video framerate.
            # @remark 0 to use source video fps.
            # default: 0
            vfps            25;
            # video width, must be even numbers.
            # @remark 0 to use source video width.
            # default: 0
            vwidth          768;
            # video height, must be even numbers.
            # @remark 0 to use source video height.
            # default: 0
            vheight        320;
            # the max threads for ffmpeg to used.
            # default: 1
            vthreads        12;
            # x264 profile, @see x264 -help, can be:
            # high,main,baseline
            vprofile        main;
            # x264 preset, @see x264 -help, can be: 
            #      ultrafast,superfast,veryfast,faster,fast
            #      medium,slow,slower,veryslow,placebo
            vpreset        medium;
            # other x264 or ffmpeg video params
            vparams {
                # ffmpeg options, @see: http://ffmpeg.org/ffmpeg.html
                t              100;
                # 264 params, @see: http://ffmpeg.org/ffmpeg-codecs.html#libx264
                coder          1;
                b_strategy      2;
                bf              3;
                refs            10;
            }
            # audio encoder name. can be:
            #      libfdk_aac: use aac(libfdk_aac) audio encoder.
            #      copy: donot encoder the audio stream, copy it.
            #      an: disable audio output.
            acodec          libfdk_aac;
            # audio bitrate, in kbps. [16, 72] for libfdk_aac.
            # @remark 0 to use source audio bitrate.
            # default: 0
            abitrate        70;
            # audio sample rate. for flv/rtmp, it must be:
            #      44100,22050,11025,5512
            # @remark 0 to use source audio sample rate.
            # default: 0
            asample_rate    44100;
            # audio channel, 1 for mono, 2 for stereo.
            # @remark 0 to use source audio channels.
            # default: 0
            achannels      2;
            # other ffmpeg audio params
            aparams {
                # audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
                # @remark SRS supported aac profile for HLS is: aac_low, aac_he, aac_he_v2
                profile:a  aac_low;
                bsf:a      aac_adtstoasc;
            }
            # output format, can be:
            #      off, do not specifies the format, ffmpeg will guess it.
            #      flv, for flv or RTMP stream.
            #      other format, for example, mp4/aac whatever.
            # default: flv
            oformat        flv;
            # output stream. variables:
            #      [vhost] the input stream vhost.
            #      [port] the intput stream port.
            #      [app] the input stream app.
            #      [stream] the input stream name.
            #      [engine] the tanscode engine name.
            output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
        }
    }
}

              改好配置文件后启动srs,命令./obj/srs -c conf/rtmp这样就可以了
三、编码、推流:
              这个都使用工具完成了,是使用shell命令推流,命令为ffmpeg -re -i ./output.avi  -vcodec libx264 -acodec copy  -f flv -y rtmp://192.168.56.101/live/livestream; 
              是使用.246编码
四、分发: 用nginx反向代理,在nginx配置文件中加入如下,位置是和http同级
stream{
    upstream proxybackend{
      server localhost:1935;
    }
    server {
      listen 8888;
      proxy_pass proxybackend;
      }
}
五、解码、播放:都用vlc media player来做了。http://mirror.os6.org/videolan/vlc/2.2.6/win32/vlc-2.2.6-win32.exe
六、播放地址是:rtmp://192.168.56.101/live/livestream
七、没有互动没有弹幕没有打赏没有美颜,就是那么任性
八、关于循环录制推流的代码还在进一步测试中

使用ffmpeg进行网络直播的更多相关文章

  1. golang ffmpeg 做网络直播

    最近在公司做在线视频转码的工作,研究了下ffmpeg 最后直接研究了下网络直播,我是在我自己的mac 上面测试的,效果,还可以,先看看效果图吧 ffmpeg 我是通过brew安装 的,这步就略了 VL ...

  2. iOS:FFmpeg视频播放和直播框架

    视频直播和播放转码器框架 介绍: FFmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序.采用LGPL或GPL许可证. 它提供了录制.转换以及流化音视频的完整解决方案.它 ...

  3. 使用ffmpeg搭建HLS直播系统

    [时间:2018-04] [状态:Open] [关键词:流媒体,stream,HLS, ffmpeg,live,直播,点播, nginx, ssegment] 0 引言 本文作为HLS综述的后续文章. ...

  4. 网络直播电视之M3U8解析篇 (下)

    在上一篇文章中讲述了网络直播电视的M3U8解析和当中的keyword段.本章我将对我遇见到的不同数据源的M3U8文件进行列举和分析. 第一种:ts片段地址为文件名,下载地址为:http:\\www.X ...

  5. 收藏:视频网站(JavaEE+FFmpeg)/Nginx+ffmpeg实现流媒体直播点播系统

    FFmpeg安装(windows环境)http://www.cnblogs.com/xiezhidong/p/6924775.html 最简单的视频网站(JavaEE+FFmpeg)http://bl ...

  6. 利用Docker挂载Nginx-rtmp(服务器直播流分发)+FFmpeg(推流)+Vue.js结合Video.js(播放器流播放)来实现实时网络直播

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_75 众所周知,在视频直播领域,有不同的商家提供各种的商业解决方案,其中比较靠谱的服务商有阿里云直播,腾讯云直播,以及又拍云和网易云 ...

  7. ffmpeg推送直播流的技术进展

    首先安装好NGINX并打开服务 然后安装好ffmpeg 然后参考:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=2879051 ...

  8. ffmpeg+nginx搭建直播服务器

    Nginx与Nginx-rtmp-module搭建RTMP视频直播和点播服务器 https://zhuanlan.zhihu.com/p/28009037 FFmpeg总结(十三)用ffmpeg基于n ...

  9. iOS平台基于ffmpeg的视频直播技术揭秘

    现在非常流行直播,相信很多人都跟我一样十分好奇这个技术是如何实现的,正好最近在做一个ffmpeg的项目,发现这个工具很容易就可以做直播,下面来给大家分享下技术要点: 首先你得编译出ffmpeg运行所需 ...

随机推荐

  1. kafka原理

    今天因为工作接触kafka,先说说kafka是干嘛的. kafka: 说简单点他就是一个基于分布式的消息发布-订阅系统. 然后再理解一些专有名词: Kafka 专用术语 Broker:Kafka 集群 ...

  2. VS2015编译OpenSSL1.0.2源码

    更多详细信息http://blog.csdn.net/YAOJINGKAO/article/details/53041165?locationNum=10&fps=1 1.下载安装编译必须的A ...

  3. 我们复习.Net的这些日子里

    今天是我们复习前面学习的第三天,也是在今天我们结束了复习.之前上学时间感觉知识全是生僻的,在生活中很少用到,因此喜欢重复的记忆,而现在学习的知识全是现在乃至未来,将是每天我们使用的,所以就感觉没必要重 ...

  4. memset和memcpy函数、atoi函数

    memset void *memset(void *s,int c,size_t n) 总的作用:将已开辟内存空间 s 的首 n 个字节的值设为值 c.如下: // 1.将已开辟内存空间s的首n个字节 ...

  5. 《C++ Primer Plus》第12章 类和动态内存分配 学习笔记

    本章介绍了定义和使用类的许多重要方面.其中的一些方面是非常微妙甚至很难理解的概念.如果其中的某些概念对于您来说过于复杂,也不用害怕——这些问题对于大多数C++的初学者来说都是很难的.通常,对于诸如复制 ...

  6. Java中list对象的三种遍历方式

    1.增强for循环 for(String str : list) {//其内部实质上还是调用了迭代器遍历方式,这种循环方式还有其他限制,不建议使用. System.out.println(str); ...

  7. /usr/local/java/jdk1.8.0_11

  8. 使用log4net记录日志到数据库(含有自定义属性)

    记录日志是管理系统中对用户行为的一种监控与审核,asp.net中记录日志的方式有很多种,这里我只介绍一下最近用到的log4net,关于他的具体介绍网上有很多,我讲一下他的用法. 第一步:在配置文件中的 ...

  9. Android dialog 全屏

    Android中让Dialog全屏: 一.在style中定义样式: <?xml version="1.0" encoding="utf-8"?> & ...

  10. 10.Curator队列

        Curator也提供ZK Recipe的分布式队列实现.利用ZK的 PERSISTENTSEQUENTIAL节点,可以保证放入到队列中的项目是按照顺序排队的.如果单一的消费者从队列中取数据,那 ...