ffmepg入门学习三 java通过摄像头截取图片
作者:互联网
1.准备
有可连接的摄像头,例如大华、海康
ffmpeg下载:https://blog.csdn.net/qq_16855077/article/details/89839708
例如下面rtsp各个品牌的url不同,这里就不过多的说明
rtsp://admin:123456@192.168.7.55:554/Streaming/Channels/101?transportmode=unicast
2.截图
- package com.qihui.qxj.services.system;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.List;
- import org.junit.Test;
- public class Test1 {
- @Test
- public void test1() {
- List commend = new ArrayList();
- commend.add("c:/bin/ffmpeg.exe");
- commend.add("-i");
- commend.add("rtsp://admin:123456@192.168.7.55:554/Streaming/Channels/101?transportmode=unicast");
- commend.add("-s");
- commend.add("4096*1800");
- commend.add("-b");
- commend.add("4M");
- commend.add("-y");
- commend.add("-f");
- commend.add("image2");
- commend.add("-an");
- commend.add("-loglevel");
- commend.add("8");
- commend.add("d:/project/direct/40/a1.jpg");
- Process p = null;
- try {
- ProcessBuilder builder = new ProcessBuilder(commend);
- builder.command(commend);
- p = builder.start();
- p.getOutputStream().close();
- doWaitFor(p);
- p.destroy();
- System.out.println(1122);
- } catch (Exception e) {
- PrintCatchErrorMsg.Print(e, "Part", "getRSTPPicture.catch", "Exception");
- p.destroy();
- }
- }
- public static int doWaitFor(Process p) {
- InputStream in = null;
- InputStream err = null;
- int exitValue = -1;
- try {
- in = p.getInputStream();
- err = p.getErrorStream();
- boolean finished = false;
- while(!finished) {
- try {
- Character c;
- while(in.available() > 0) {
- c = new Character((char)in.read());
- System.out.print(c);
- }
- while(err.available() > 0) {
- c = new Character((char)err.read());
- System.out.print(c);
- }
- exitValue = p.exitValue();
- finished = true;
- } catch (IllegalThreadStateException var19) {
- Thread.currentThread();
- Thread.sleep(500L);
- }
- }
- } catch (Exception var20) {
- } finally {
- try {
- if (in != null) {
- in.close();
- }
- } catch (IOException var18) {
- }
- if (err != null) {
- try {
- err.close();
- } catch (IOException var17) {
- }
- }
- }
- return exitValue;
- }
- }
c:/bin/ffmpeg.exe ffmepeg的位置
-i 地址
-s 分辨率
-b 码率
-y 如果文件存在,再替换
注意:如果内网环境可以截图,外网环境截图失败,需要把协议转为tcp,增加两行代码
- commend.add("-rtsp_transport");
- commend.add("tcp");
转载自:https://blog.csdn.net/qq_16855077/article/details/90207118
luoyong_blog 发布了42 篇原创文章 · 获赞 115 · 访问量 1万+ 私信 关注标签:try,java,err,截取,commend,add,ffmepg,catch,import 来源: https://blog.csdn.net/luoyong_blog/article/details/104497416