javacv ffmpeg使用原生ffmpeg命令方式
更新時(shí)間:2024年11月07日 10:00:02 作者:搬山境KL攻城獅
在使用javacv集成ffmpeg進(jìn)行視頻處理時(shí),發(fā)現(xiàn)使用ffmpeg-6.0-1.5.9版本出現(xiàn)原生命令執(zhí)行失敗的問題,通過降級(jí)至ffmpeg-5.1.2-1.5.8版本,問題得到解決,此外,ffprobe可以用于獲取視頻屬性,需確保視頻片段屬性一致性
javacv ffmpeg使用原生ffmpeg命令
測試過程中,
發(fā)現(xiàn)ffmpeg-6.0-1.5.9-linux-x86_64.jar
存在問題(ffmpeg原生命令執(zhí)行失?。?/p>
降級(jí)到ffmpeg-5.1.2-1.5.8-linux-x86_64.jar
版本正常
<javacv.version>1.5.8</javacv.version> <dependencies> <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>${javacv.version}</version> </dependency> <dependency> <groupId>org.bytedeco</groupId> <artifactId>ffmpeg</aifactId> <version>5.1.2-${javacv.version}</version> <classifier>linux-x86_64</classifier> </dependency> </dependencies> <profiles> <profile> <id>Windows</id> <activation> <os> <!-- mvn enforcer:display-info --> <family>windows</family> </os> </activation> <dependencies> <dependency> <groupId>org.bytedeco</groupId> <artifactId>ffmpeg</artifactId> <version>5.1.2-${javacv.version}</version> <classifier>windows-x86_64</classifier> </dependency> </dependencies> </profile> <profile> <id>Mac</id> <activation> <os> <!-- mvn enforcer:display-info --> <family>mac</family> </os> </activation> <dependencies> <dependency> <groupId>org.bytedeco</groupId> <artifactId>ffmpeg</artifactId> <version>5.1.2-${javacv.version}</version> <classifier>macosx-x86_64</classifier> </dependency> </dependencies> </profile> </profiles>
1. ffmpeg
org.bytedeco.ffmpeg.ffmpeg org.bytedeco.ffmpeg.ffprobe
- 版本號(hào)
String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class); System.out.println("ffmpeg path=>" + ffmpeg); ProcessBuilder pb = new ProcessBuilder(ffmpeg, "-version"); pb.inheritIO().start().waitFor();
- 直接拼接視頻(前提各個(gè)視頻片段幀率等屬性一致)
// 輸入視頻文件路徑 List<String> inputFiles = Arrays.asList("video1.mp4", "video2.mp4"); // 輸出視頻文件路徑 String outputFile = "output.mp4"; // 拼接模板文件 String modelFile = "modelFile.txt"; // 創(chuàng)建拼接模板文件 try (BufferedWriter writer = new BufferedWriter(new FileWriter(modelFile))) { for (String inputFile : inputFiles) { writer.write("file '" + inputFile + "'"); writer.newLine(); } } catch (IOException e) { e.printStackTrace(); return; } String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class); ProcessBuilder pb = new ProcessBuilder(ffmpeg, "-f", "concat", "-safe", "0", "-i", modelFile, "-c", "copy", outputFile); pb.inheritIO().start().waitFor();
2. ffprobe
- 版本號(hào)
public static void main(String[] args) throws IOException, InterruptedException { String ffprobe = Loader.load(org.bytedeco.ffmpeg.ffprobe.class); System.out.println("ffprobe path=>" + ffprobe); ProcessBuilder pb = new ProcessBuilder(ffprobe, "-version"); pb.inheritIO().start().waitFor(); }
- 視頻屬性
更多用法:help、大模型
ffprobe -h topic
String ffprobe = Loader.load(org.bytedeco.ffmpeg.ffprobe.class); ProcessBuilder pb = new ProcessBuilder(ffprobe, "-v", "error", "-print_format", "json", "-show_streams", "video1.mp4"); pb.inheritIO().start().waitFor();
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
LibrarySystem圖書管理系統(tǒng)開發(fā)(一)
這篇文章主要為大家詳細(xì)介紹了LibrarySystem圖書管理系統(tǒng)開發(fā),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05IntelliJ IDEA(或者JetBrains PyCharm)中彈出"IntelliJ IDEA License
今天小編就為大家分享一篇關(guān)于IntelliJ IDEA(或者JetBrains PyCharm)中彈出"IntelliJ IDEA License Activation"的解決辦法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10解決Spring配置文件中bean的property屬性中的name出錯(cuò)問題
這篇文章主要介紹了解決Spring配置文件中bean的property屬性中的name出錯(cuò)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07