{"id":29987472,"url":"https://github.com/chenliang15405/ffmpeg-common","last_synced_at":"2025-08-04T23:03:10.958Z","repository":{"id":52588348,"uuid":"209032201","full_name":"chenliang15405/ffmpeg-common","owner":"chenliang15405","description":"java关于ffmpeg命令实现音频、视频等操作的封装，提供易于操作的API","archived":false,"fork":false,"pushed_at":"2021-05-23T06:30:41.000Z","size":60,"stargazers_count":22,"open_issues_count":1,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-03T14:52:10.957Z","etag":null,"topics":["ffmpeg","ffmpeg-common","jar-maven","java-ffmpeg"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenliang15405.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-17T11:09:24.000Z","updated_at":"2025-05-27T08:04:11.000Z","dependencies_parsed_at":"2022-09-07T05:22:12.074Z","dependency_job_id":null,"html_url":"https://github.com/chenliang15405/ffmpeg-common","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chenliang15405/ffmpeg-common","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenliang15405%2Fffmpeg-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenliang15405%2Fffmpeg-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenliang15405%2Fffmpeg-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenliang15405%2Fffmpeg-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenliang15405","download_url":"https://codeload.github.com/chenliang15405/ffmpeg-common/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenliang15405%2Fffmpeg-common/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268578914,"owners_count":24273089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ffmpeg","ffmpeg-common","jar-maven","java-ffmpeg"],"created_at":"2025-08-04T23:01:10.566Z","updated_at":"2025-08-04T23:03:10.912Z","avatar_url":"https://github.com/chenliang15405.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ffmpeg-common\n**java关于ffmpeg命令实现音频、视频等操作的封装**\n\n\u003e 提供VideoOperation、AudioOperation操作工具类，方便实现对视频、音频等裁剪、合成、视频音频的拼接等一系列操作，方便操作和调用简单，需自定义ffmpeg的路径，因为后续可能出现ffmpeg版本等问题，所以自定义ffmpeg灵活可靠，提供更好的兼容性.\n\n下载ffmpeg的地址： [ffmpeg下载](http://ffmpeg.org)\n\n### 引入方式：\n\n\u003e 支持通过maven或者直接引入jar包的方式\n\n- jar包请到maven仓库中下载即可\n\n    [maven仓库地址](https://mvnrepository.com/artifact/com.github.chenliang15405/ffmpeg-common/3.2)\n\n- maven构建依赖：\n\n    ```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.chenliang15405\u003c/groupId\u003e\n        \u003cartifactId\u003effmpeg-common\u003c/artifactId\u003e\n        \u003cversion\u003e3.2\u003c/version\u003e\n    \u003c/dependency\u003e\n    ```\n\n## 1. VideoOperation 说明\n\u003e 视频操作对象，`VideoOperation`提供了操作视频的多种API\n\n- **使用示例：**\n    \n    ```java\n       public void testConverTest() throws IOException {\n          // 指定ffmpeg的绝对路径\n          String ffmpegEXE = \"/server/notes/ffmpeg\";\n          String inputPath = \"/server/notes/test/2222.mp4\";\n          String outPutPath = \"/server/test/1/convert.flv\";\n          // 创建VideoOperation对象\n          VideoOperation ffmpeg = VideoOperation.builder(ffmpegEXE);\n          // 将mp4格式转换为flv格式\n          Result result = ffmpeg.videoConvert(inputPath, outPutPath);  \n          // 返回结果为0表示正确\n          Assert.assertEquals(0, result.getCode());\n          // 转换的信息\n          System.out.println(result.getErrMessage());  \n       }\n      \n    ```\n- **VideoOperation API列表及说明：**\n\n    | API | 参数说明 | 方法说明 |\n    | ------ | ------ | ------ |\n    | videoConvert(String inputVideo, String outputVideo) | inputVideo 原始视频绝对路径（带视频名称）(xxx/1.mp4) \u003cbr/\u003e outputVideo  输出视频绝对路径（带视频名称）(xxx/1.flv) | 转换视频格式 |\n    | mergeVideoAndBgmWithOrigin(String bgm, String inputVideo, String outputVideo, double seconds) | bgm: 背景音乐路径\u003cbr\u003einputVideo: 输入音频路径\u003cbr\u003eoutputVideo: 输出视频路径\u003cbr\u003e seconds: 输出视频秒数 | 保留视频原声并增加背景音乐 |\n    | getVideoCoverImg(String inputVideo, String coverOut) | inputVideo: 原始视频绝对路径\u003cbr\u003e coverOut: 图片输出路径 | 获取视频的封面图 |\n    | getVideoCoverImgs(Integer startSeconds, String inputVideo,Integer everySecondImg, Integer seconds,String coverOutPath) |  startSeconds: 多少秒开始截图\u003cbr/\u003e  inputVideo: 需要截图的视频绝对路径 \u003cbr\u003e everySecondImg 每秒截多少张图\u003cbr\u003e seconds: 一共持续截图多少秒\u003cbr\u003e seconds 一共持续截图多少秒 \u003cbr\u003e  coverOutPath 截图生成的路径（图片名称会以001 002... 命名）| 对视频的指定秒开始截图，可截多张图 |\n    | wipeAudio(String inputVideo, String outputVideo) | inputVideo: 输入视频绝对路径\u003cbr\u003e outputVideo: 输出视频绝对路径 | 去除视频的音频 |\n    | videoScale(String inputVideo, String outWidth, String outHeight, String outputVideo) | inputVideo: 需要操作的原始视频绝对路径\u003cbr\u003e outWidth: 处理之后的视频的宽度\u003cbr\u003e outHeight: 处理之后的视频高度\u003cbr\u003eoutputVideo: 处理之后生成的新的视频绝对路径 | 视频缩放 |\n    | videoCrop(String inputVideo, String outWidth, String outHeight, String x, String y, String outputVideo) | inputVideo: 需要操作的原始视频绝对路径\u003cbr\u003eoutWidth: 处理之后的视频的宽度\u003cbr\u003eoutHeight: 处理之后的视频高度\u003cbr\u003eoutputVideo: 处理之后生成的新的视频绝对路径 | 视频的页面长宽进行裁剪 |\n    | videoRotate(String inputVideo, Integer angleNum, String outWidth, String outHeight, String outputVideo) | inputVideo: 需要操作的原始视频绝对路径\u003cbr\u003eangleNum: 旋转的角度，1：180度 2：90度\u003cbr\u003eoutWidth 输出视频的宽度，如果不指定，默认是输入视频的宽度\u003cbr\u003eoutHeight: 输出视频的高度，如果不指定，默认是输入视频的高度\u003cbr\u003eoutputVideo: 处理之后生成的新的视频绝对路径 | 视频角度旋转 |\n    | videoFps(String inputVideo, Integer fps, String outputVideo) | inputVideo: 需要操作的原始视频绝对路径\u003cbr\u003efps: 需要调节到多少帧\u003cbr\u003eoutputVideo: 处理之后生成的新的视频绝对路径 | 调节视频帧数 |\n    | gifConvertToVideo(String gif, String outputVideo) | gif: gif绝对路径\u003cbr\u003eoutputVideo: 输出视频绝对路径 | gif转换为video |\n    | videoConvertToGif(String inputVideo,  String outputGif, boolean highQuality) | inputVideo: 需操作视频的绝对路径\u003cbr\u003eoutputGif: 生成gif的输出绝对路径\u003cbr\u003ehighQuality 是否生成高质量gif | 视频转gif |\n    | videoCut(String inputVideo,String startTime, String seconds, String outputVideo) | inputVideo: 原始需要操作视频的绝对路径\u003cbr\u003estartTime 开始裁剪的时间 支持格式： 2  或  00:00:02 从2秒开始\u003cbr\u003eseconds  剪裁持续的时间 支持格式： 3 或 00:00:03 持续3秒\u003cbr\u003eoutputVideo 输出视频的绝对路径 | 对视频的播放时间进行裁剪 |\n    | mergeVideoAndBgmNoOrigin(String videoInputPath, String videoOutPath, String bgmInputPath, double seconds) | videoInputPath: 原始视频绝对路径\u003cbr\u003evideoOutPath  处理之后视频输出路径\u003cbr\u003ebgmInputPath  添加的背景音乐绝对路径\u003cbr\u003e seconds   输出视频的秒数 | 视频合并音频，给视频加上背景音乐，并不保留视频原声(此方法在Mac平台无效) |\n    | convertorWithBgmNoOriginCommon(String videoInputPath, String videoOutPath, String noSoundVideoPath, String bgmInputPath, double seconds) | videoInputPath: 原始视频绝对路径\u003cbr\u003evideoOutPath: 处理之后视频输出路径\u003cbr\u003enoSoundVideoPath: 原始视频去除音频的输出绝对路径\u003cbr\u003ebgmInputPath: 添加的背景音乐绝对路径\u003cbr\u003eseconds: 输出视频的秒数 | 视频合并音频，给视频加上背景音乐，并不保留视频原声，此方法比较通用，并且Mac可以使用 |\n    | transformVideoCover(String videoInputPath, String imagePath, String videoOutPath) | videoInputPath: 原始视频绝对路径\u003cbr\u003eimagePath  替换的封面图片绝对路径\u003cbr\u003evideoOutPath 新的视频输出路径\u003cbr\u003e | 修改视频封面图片 |\n    | mergeMultiOnlineVideos(File videoListFile, String videoOutPath) | videoListFile: 绝对路径下的视频list文件（参考sample文件：docs/video-example/video-online-example.txt）\u003cbr\u003evideoOutPath: 新视频输出路径\u003cbr\u003e | 合并多个在线视频（ts格式）, 根据文件中在线视频地址顺序合并（（参考sample文件：docs/video-example/video-online-example.txt）） |\n    | mergeMultiVideosOfTsOrMpegFormat(List\u003cString\u003e fileNameList, String videoOutPath) | fileNameList: 需要合并的视频文件集合，文件名称为绝对路径\u003cbr\u003evideoOutPath: 视频输出绝对路径 | 合并多个视频文件(此方法只适用ts格式文件,或者mpg/mpeg格式文件) |\n    | mergeMultiVideosByFile(File videoListFile, String videoOutPath) | videoListFile: 定义合并视频的文件，按照指定格式访问（文件示例：docs/video-example/video-example.txt）\u003cbr\u003evideoOutPath: 视频输出绝对路径文件名| 根据自定义文件中定义视频绝对路径信息，按照顺序合并视频（文件示例：docs/video-example/video-example.txt） |\n    | autoMergeMultiVideosByDir(String dir, String videoOutPath) | dir: 视频文件目录绝对路径\u003cbr\u003evideoOutPath: 视频输出绝对路径 | 根据文件目录，自动合并该目录下所有视频（默认合成的顺序按照文件名称进行排序）|\n\n- **合并视频注意事项**\n  - 合并的多个视频必须相同的分辨率，否则合成的视频会黑屏\n\n## 2. AudioOperation 说明\n\u003e 音频操作对象，`AudioOperation`提供了操作视频的多种API\n\n- **使用示例：**\n    ```java\n      public void audioFormatTest() {\n         // 指定ffmpeg的绝对路径\n         String ffmpegEXE = \"/server/notes/ffmpeg\";\n         String inputPath = \"/server/notes/VideoTest/amr.amr\";\n         String outPutPath = \"/server/notes/VideoTest/mp3.mp3\";\n         // 创建AudioOperation对象\n         AudioOperation ffmpeg = AudioOperation.builder(ffmpegEXE);\n         // 转换为音频的amr格式为mp3格式\n         Result result = ffmpeg.transFormatToMp3Audio(inputPath, outPutPath);\n         // 返回结果为0表示转换成功\n         Assert.assertEquals(0, result.getCode());\n         // 转换的信息\n         System.out.println(result.getErrMessage());\n      }\n\n  ```\n\n- **AudioOperation API列表及说明：**\n\n    | API | 参数说明 | 方法说明 |\n    | ------ | ------ | ------ |\n    | audioConcat(String bgmOutPath, String... bgmInputPath) | bgmOutPath: 输出音频文件\u003cbr\u003ebgmInputPath 输入的音频文件, 多值参数 | 将多个音频文件拼接为一个音频文件并输出 |\n    | audioCut(String bgmInputPath, String bgmOutPath, String startTime, String endTime) | bgmInputPath 音频输入绝对路径\u003cbr\u003ebgmOutPath 音频输出绝对路径\u003cbr\u003estartTime: 截取的开始时间(例如：00:00:00)\u003cbr\u003eendTime: 截取的结束时间(例如：00:06:38) | 通过指定开始时间和结束时间 裁剪音频 |\n    | getBgmFromVideo(String inputVideo, String outAudio) | inputVideo：视频绝对路径\u003cbr\u003eoutAudio: 输出音频绝对路径 | 从视频中提取音频 |\n    | transFormatAudio(String inputAudio, String outAudio) | inputAudio: 输入视频绝对路径\u003cbr\u003eoutAudio: 输出音频绝对路径 | 转换音频格式 |\n    | transFormatAmrAudio(String inputAudio, String outAudio) | inputAudio: 输入视频/音频绝对路径\u003cbr\u003eoutAudio 输出音频绝对路径 | 将其他格式的音频或视频转成AMR |\n    | transFormatToMp3Audio(String inputAudio, String outAudio) | inputAudio 输入视频绝对路径\u003cbr\u003eoutAudio 输出音频绝对路径 | 转换音频格式 mp3编码方式采用的是libmp3lame |\n    \n\n**3.返回结果说明**\n- Result对象\n    - code 表示返回的状态码： 0 表示正常\n    - errMessage 表示转换的信息： 不用于判断，是ffmpeg的转换过程产生的信息\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenliang15405%2Fffmpeg-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenliang15405%2Fffmpeg-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenliang15405%2Fffmpeg-common/lists"}