「ffmpeg配合java」ffmpeg使用教程

博主:adminadmin 2022-11-30 09:10:06 107

今天给各位分享ffmpeg配合java的知识,其中也会对ffmpeg使用教程进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

怎么用java读取ffmpeg输出流

public static void main(String[] args) {

String result = processFLV("E:\\test\\京视传媒\\体育类\\xiao.flv");

PatternCompiler compiler =new Perl5Compiler();

try {

String regexDuration ="Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";

String regexVideo ="Video: (.*?), (.*?), (.*?)[,\\s]";

String regexAudio ="Audio: (\\w*), (\\d*) Hz";

Pattern patternDuration = compiler.compile(regexDuration,Perl5Compiler.CASE_INSENSITIVE_MASK);

PatternMatcher matcherDuration = new Perl5Matcher();

if(matcherDuration.contains(result, patternDuration)){

MatchResult re = matcherDuration.getMatch();

System.out.println("提取出播放时间 ===" +re.group(1));

System.out.println("开始时间 =====" +re.group(2));

System.out.println("bitrate 码率 单位 kb==" +re.group(3));

}

Pattern patternVideo = compiler.compile(regexVideo,Perl5Compiler.CASE_INSENSITIVE_MASK);

PatternMatcher matcherVideo = new Perl5Matcher();

if(matcherVideo.contains(result, patternVideo)){

MatchResult re = matcherVideo.getMatch();

System.out.println("编码格式 ===" +re.group(1));

System.out.println("视频格式 ===" +re.group(2));

System.out.println(" 分辨率 == =" +re.group(3));

}

Pattern patternAudio = compiler.compile(regexAudio,Perl5Compiler.CASE_INSENSITIVE_MASK);

PatternMatcher matcherAudio = new Perl5Matcher();

if(matcherAudio.contains(result, patternAudio)){

MatchResult re = matcherAudio.getMatch();

System.out.println("音频编码 ===" +re.group(1));

System.out.println("音频采样频率 ===" +re.group(2));

}

} catch (MalformedPatternException e) {

e.printStackTrace();

}

}

// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)

private static String processFLV(String inputPath) {

/*

if (!checkfile(inputPath)){

_log.warn(inputPath+" is not file");

return false;

}

*/

ListString commend=new java.util.ArrayListString();

// commend.add("e:\\videoconver\\ffmpeg\\ffmpeg ");//可以设置环境变量从而省去这行

commend.add("ffmpeg");

commend.add("-i");

commend.add(inputPath);

try {

ProcessBuilder builder = new ProcessBuilder();

builder.command(commend);

builder.redirectErrorStream(true);

Process p= builder.start();

//1. start

BufferedReader buf = null; // 保存ffmpeg的输出结果流

String line = null;

//read the standard output

buf = new BufferedReader(new InputStreamReader(p.getInputStream()));

StringBuffer sb= new StringBuffer();

while ((line = buf.readLine()) != null) {

System.out.println(line);

sb.append(line);

continue;

}

int ret = p.waitFor();//这里线程阻塞,将等待外部转换进程运行成功运行结束后,才往下执行

//1. end

return sb.toString();

} catch (Exception e) {

// System.out.println(e);

return null;

}

}

java 调用 ffmpeg 进行视频截取

ffmpeg -y -i SF160114692.flv -vcodec copy -acodec copy -ss 00:02:00.000

-t 0:5:30 -f flv 3.flv

(1)用-ss指定开始时间,用hh:mm:ss[.ms]格式,或者换算成用秒计。

(2)用-t指定时间长度,和-ss的格式一样,用hh:mm:ss[.ms]格式,或者换算成用秒计。

java中可以使用ProcessBuilder调用命令行

用Java和ffmpeg做视频拆帧

我用的是基于C++的ffmpeg开发,ffmpeg原本是针对linux下的GCC编译器,当然通过MinGW也可以在win下进行编译,但是需要安装额外的编译环境,你可以上chinavideo上去看看,那上面说的很清楚,的你所说的问题也不是很难,多看看开发文档就可以解决了。

使用JAVA调用ffmpeg组件进行视频转换时不成功

FFMPEG没有java可以直接调用的API,网上那些基本上是通过调用cmd命令来实现转换的。这种方法很容易出错,效率低而且也不容易调试。最好的办法是让提供商提供flv格式的文件。如果不行你只有测试一下直接用FFMPEG的图形界面转看结果如何,然后尝试更换参数,视频文件和FFMPEG版本。

请教大神,java调用ffmpeg,将两段.wav音频,拼接成一段.wav音频,怎么做?

ffmpeg是c实现的,java想调它的api,起码要写一层jni出来,直接在jni层调用ffmpeg的api,然抛到java层去invoke.

当然还有一种,直接用命令实现,首先你需要编译出可以在你当前环境上运行的ffmpeg,然后配置好拼接音频的参数,使用Runtime的exec来执行这个命令,这种方法虽然简单,但是一旦换个执行环境可能就没有办法使用你本机编译的ffmpeg了,所以不推荐。

ffmpeg配合java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于ffmpeg使用教程、ffmpeg配合java的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-30,除非注明,否则均为首码项目网原创文章,转载请注明出处。