FFMPEG 截取RTMP直播流图片命令

CentOS 6.5  yum安装FFMPEG步骤

1. 手动添加yum源配置

vi /etc/yum.repos.d/dag.repo

 
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=0
enabled=1

2.安装

yum -y install ffmpeg


ffmpeg截图

ffmpeg -i "rtmp://10.1.1.31/live/test live=1" -f image2 -ss 0 -vframes 1 -s 220*220 /tmp/a.jpg


3.Java调用命令行执行截图操作


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {

        for (String arg : args) {
            System.out.println(arg);
        }

        ProcessBuilder builder = new ProcessBuilder();
        builder.command("ffmpeg", "-i", "rtmp://10.1.1.31/live/test live=1", "-f", "image2", "-ss",
            "0", "-vframes", "1", "-s", args[0], "/tmp/fish/a.jpg");

        builder.redirectErrorStream(false);
        try {
            Process process = builder.start();
            InputStream in = process.getInputStream();
            System.out.println("正在进行截图,请稍候=======================");
            convertStreamToString(in);
            System.out.println("");
            InputStream errorStream = process.getErrorStream();
            if (errorStream != null && errorStream.read() > 0) {
                System.out.println("错误:");
                convertStreamToString(errorStream);
            }
            in.close();
        } catch (IOException e) {
            System.out.println("错误:");
            e.printStackTrace();
        }
    }

    public static String convertStreamToString(InputStream is) {

        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        StringBuilder sb = new StringBuilder();

        String line = null;

        try {
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
                sb.append(line + "/n");
            }
        } catch (IOException e) {

            e.printStackTrace();

        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();

    }

}


posted @ 2016-03-22 14:46  uwannerme  阅读(3209)  评论(2编辑  收藏  举报