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();

    }

}


转载于:https://www.cnblogs.com/uwannerme/p/5692830.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值