java 对rtmp视频流进行截图 ffmpeg

来源:互联网 发布:信息管理与网络维护 编辑:程序博客网 时间:2024/05/27 14:13

  1. windows

  1. 下载安装ffmpeg插件,配置环境变量
  2. ffmpeg -i rtmp://live.hkstv.hk.lxdns.com/live/hks -vframes 1 -y -f image2 -t 1 -s 600x480 /usr/a.jpg
  3. -i “rtmp..........    ”    :后接自己的地址

    -y                              :覆盖输出文件,即如果1.***文件已经存在的话,不经提示就覆盖掉了

    -t 0.001                   :设置纪录时间 hh:mm:ss[.xxx]格式的记录时间也支持

    -ss 1                       :延迟1秒后开始

    -f image2               :以图片格式保存

  4. public static String transfer(String inFile, String outFile) { 
    String command = "ffmpeg -i "+inFile +" -vframes 1 -y -f image2 -t 1 -s 600x480 "+ outFile;
     try {
               Process process = Runtime.getRuntime().exec(command);//执行命令
               InputStreamReader ir = new InputStreamReader(process.getInputStream());
               LineNumberReader input = new LineNumberReader(ir);
               String line;
               while ((line = input.readLine()) != null) {//输出结果
               }
           } catch (java.io.IOException e) {
               System.err.println("IOException " + e.getMessage());//捕捉异常
           }
     return outFile;
    }

  5. linux

  6. --------------------------使用yum在centos下安装最新版的ffmpeg-------------------------------------------------------


    1.安装编译环境,如果系统有就不用安装了。


    yum install -y automake autoconf libtool gcc gcc-c++ 


    yum install make


    yum install svn




    2.可以通过svn命令获取最新的ffmpeg了




    svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg




    3.你会发现在你所在的目录,自动出现一个ffmpeg的目录,就是你下载的源代码。


    切换到ffmpeg目录下,执行以下命令。


    ./configure


    make 


    make install






    4.【配置Path】:
           安装完成以后并不能直接使用 ffmpeg 命令执行,系统会提示并没有这样的命令,需要进一步进行配置Path:
    编辑profile文件:
            vi /etc/profile
           i (插入)
           在文件末尾加上两句话:
           export FFMPEG_HOME=/usr/local/ffmpeg 
           export PATH=$FFMPEG_HOME/bin:$PATH
           保存并退出:按Esc键 输入:wq! 回车
    使修改生效:source /etc/profile




    5. ffmpeg -v

1 0