官方下载地址: .html#releases
我这里使用版本: ffmpeg_3.2_ 可以百度网盘分享给大家
安装的环境为 Centos 64位操作系统
安装时须为 root 用户进行操作
#解压
tar -zxvf ffmpeg_3.2_#进入目录
cd ffmpeg_3.2_repo#安装可能需要一点时间
sh setup.sh
ffmpeg -i a.png -y -vf scale=100:100/a thumb.jpg
ffmpeg -i bb.mp4 -y -vframes 1 -vf scale=100:100/a thumb.jpg
package com.beyond.utils;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.InputStreamReader;/*** 执行shell命令ffmpeg工具类 liang*/
public class ShellCommandUtil {private static final Logger logger = Logger(ShellCommandUtil.class);/**** @param sourceFile 原文件路径* @param thumbFile 目标文件路径* @param thumbWidth 宽度* @param thumbHigh 高度* @return* ffmpeg -i a.png -y -vf scale=100:100/a thumb.jpg*/public static boolean ffmpegImg(String sourceFile, String thumbFile, String thumbWidth, String thumbHigh){String cmd = " ffmpeg -i " + sourceFile + " -y -vf scale=" + thumbWidth + ":" + thumbHigh + "/a " + thumbFile;execCmd(cmd, null);logger.info("ShellCommandUtil---ffmpegImg==", cmd);File file = new File(thumbFile);if(!ists()){return false;}return true;}/**** @param sourceFile* @param thumbFile* @param thumbWidth* @param thumbHigh* @return* ffmpeg -i bb.mp4 -y -vframes 1 -vf scale=100:100/a thumb.jpg*/public static boolean ffmpegVideo(String sourceFile, String thumbFile, String thumbWidth, String thumbHigh){String cmd = " ffmpeg -i " + sourceFile + " -y -vframes 1 -vf scale=" + thumbWidth + ":" + thumbHigh + "/a " + thumbFile;execCmd(cmd, null);logger.info("ShellCommandUtil---ffmpegVideo==", cmd);File file = new File(thumbFile);if(!ists()){return false;}return true;}/*** 执行系统命令, 返回执行结果* @param cmd 需要执行的命令* @param dir 执行命令的子进程的工作目录, null 表示和当前主进程工作目录相同*/public static String execCmd(String cmd, File dir) {StringBuilder result = new StringBuilder();Process process = null;BufferedReader bufrIn = null;BufferedReader bufrError = null;try {String[] commond = {"/bin/sh","-c",cmd};// 执行命令, 返回一个子进程对象(命令在子进程中执行)process = Runtime().exec(commond, null, dir);// 方法阻塞, 等待命令执行完成(成功会返回0)process.waitFor();// 获取命令执行结果, 有两个结果: 正常的输出 和 错误的输出(PS: 子进程的输出就是主进程的输入)bufrIn = new BufferedReader(new InputStream(), "UTF-8"));bufrError = new BufferedReader(new ErrorStream(), "UTF-8"));// 读取输出String line = null;while ((line = adLine()) != null) {result.append(line).append('n');}while ((line = adLine()) != null) {result.append(line).append('n');}}catch (Exception e){e.printStackTrace();}finally {closeStream(bufrIn);closeStream(bufrError);// 销毁子进程if (process != null) {process.destroy();}}// 返回执行结果String();}private static void closeStream(Closeable stream) {if (stream != null) {try {stream.close();} catch (Exception e) {e.printStackTrace();}}}}
本文发布于:2024-01-30 21:34:34,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170662167622991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |