java使用ffmpeg拆分和拼接音频

ffmpeg是一个开源的跨平台音视频处理工具,它可以对音视频进行格式转换、压缩、采集、裁剪、剪辑等操作。ffmpeg能够处理的音视频格式很多,包括常见的mp4、avi、mov等格式,也包括一些不那么常见的格式。

ffmpeg最初是由法国程序员Fabrice Bellard编写的,现在已经成为了流行的音视频处理工具。ffmpeg支持命令行操作,也可以通过API集成到其他应用程序中使用。因为经过多年的发展,ffmpeg的性能和稳定性都非常高,被广泛应用于音视频处理领域,例如视频编辑软件、转码工具、流媒体服务器等。

按照指定时间对音频进行拆分

java 复制代码
 public static void split(String firstFragmentPath,
                             String targetPath, String startTime, String continuousTime) {

        try {
            String command="ffmpeg -i "+firstFragmentPath+" -ss "+startTime+" -t "+continuousTime+" "+targetPath+" -y";
            Runtime.getRuntime().exec(new String[]{"sh", "-c", command});
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

音频拼接

java 复制代码
public static Boolean concat(String concatFilePath,String destFile){
        try {
            final String command = String.format("ffmpeg -f concat -i %s -c copy %s -y", concatFilePath, destFile);
            Runtime.getRuntime().exec(new String[]{"sh", "-c", command});
            return Boolean.TRUE;
        } catch (IOException e) {
            e.printStackTrace();
            return Boolean.FALSE;
        }
    }

第一个参数需要传递指定格式的文件(concat.txt)

java 复制代码
file 'tmp0.wav'
file 'tmp1.wav'
file 'tmp2.wav'
file 'tmp3.wav'
file 'tmp4.wav'
file 'tmp5.wav'
file 'tmp6.wav'
file 'tmp7.wav'
file 'tmp8.wav'
相关推荐
清水白石0087 小时前
Python 编程实战全景:从基础语法到插件架构、异步性能与工程最佳实践
开发语言·python·架构
yaoxin5211238 小时前
390. Java IO API - WatchDir 示例
java·前端·python
Halo_tjn9 小时前
Java 基于字符串相关知识点
java·开发语言·算法
梦想的颜色9 小时前
java 利用redis来限制用户频繁点击
java·开发语言
报错小能手10 小时前
Swift 并发 Combine响应式框架
开发语言·ios·swift
万法若空10 小时前
C++ <memory> 库全方位详解
开发语言·c++
代码中介商10 小时前
C++ 类型转换深度解析:static_cast、dynamic_cast、const_cast、reinterpret_cast
开发语言·c++
青小莫10 小时前
C++之string(OJ练习)
开发语言·c++·stl
freshman_y10 小时前
一篇介绍C语言中二级指针和二维数组的文章
c语言·开发语言
-Marks-10 小时前
【C++编程】STL简介 --- (是什么 | 版本发展历程 | 六大组件 | 重要性缺陷以及如何学习)
开发语言·c++·学习·stl·stl版本