开发者

Including FFMPEG with a Java application on Mac

I'm writing a Java program that will be used on both Wi开发者_如何学Pythonndows and Mac. In the program, I'm using FFMPEG to convert a MOV file to an FLV. On Windows, it's no problem -- simply call the command. But on Mac, I'm not quite sure what to do. Does the user really have to install FFMPEG on their machine, or can it somehow be included in the Java application?

Thanks for any help/guidance!


You could also check out Xuggler, a Java wrapper for FFmpeg that works on Windows, Mac and Linux.


Haven't played with it yet, but isn't FFMPEG availabe as a library? Then you could simply call it via JNI or better JNA. This should work on both platforms.


If you are using the Java Media Framework (JMF), Fobs4JMF is a Java wrapper for FFMPEG that works as a JMF plugin.


I know this thread is very old but I figured I'd share my solution here in case anyone is still looking...

I added the following dependencies to my pom.xml

<!-- https://mvnrepository.com/artifact/org.bytedeco/ffmpeg -->
   <dependency>
       <groupId>org.bytedeco</groupId>
       <artifactId>ffmpeg</artifactId>
       <version>RELEASE</version>
   </dependency>

   <!-- https://mvnrepository.com/artifact/org.bytedeco/javacv-platform -->
   <dependency>
       <groupId>org.bytedeco</groupId>
       <artifactId>javacv-platform</artifactId>
       <version>RELEASE</version>
   </dependency>

   <!-- https://mvnrepository.com/artifact/org.bytedeco/javacpp -->
   <dependency>
       <groupId>org.bytedeco</groupId>
       <artifactId>javacpp</artifactId>
       <version>RELEASE</version>
   </dependency>

Then I use ProcessBuilder to execute FFMPEG commands. To merge audio and video, I use the following command:

String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
    try {
        ProcessBuilder pb = new ProcessBuilder(
                ffmpeg,
                "-i",
                [PATH TO AUDIO FILE],
                "-i",
                [PATH TO VIDEO FILE],
                "-acodec",
                "copy",
                "-vcodec",
                "copy",
                [PATH TO OUTPUT FILE]
        );
        
        pb.redirectErrorStream(true);
        Process process = pb.start();
        process.waitFor();

    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    } 


I got the solution of this library and now it is working for both windows and Mac environment.

You need not to install any extra library of ffmpeg for mac this jar contains this. You can find the jar by dropping a mail to - ffmpegmac600@gmail.com.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜