Results 1 to 2 of 2

Thread: [ask] Using ffmpeg in java

  1. #1
    Join Date
    Dec 2009
    Beans
    4

    [ask] Using ffmpeg in java

    can anyone helpl me how to use ffmpeg in java??

  2. #2
    Join Date
    Apr 2006
    Beans
    800
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: [ask] Using ffmpeg in java

    Do you mean a) executing ffmpeg commandline conversions in Java code or b) using a Java wrapper library for ffmpeg?

    a) Simple example using Java Runtime to exec a ffmpeg command (avconv -version).
    Note: I'm using 'avconv' instead of 'ffmpeg' since Ubuntu/Debian has shifted to use the libav fork of ffmpeg.

    PHP Code:
    import java.util.*;
    import java.io.*;

    class 
    StreamGobbler extends Thread {
        
    InputStream is;
        
    String type;

        
    StreamGobbler(InputStream isString type) {
            
    this.is is;
            
    this.type type;
        }

        public 
    void run() {
            try {
                
    InputStreamReader isr = new InputStreamReader(is);
                
    BufferedReader br = new BufferedReader(isr);
                
    String line=null;
                while ( (
    line br.readLine()) != null)
                    
    System.out.println(type ">" line);    
                } catch (
    IOException ioe)
                  {
                    
    ioe.printStackTrace();  
                  }
        }
    }

    public class 
    ExecExample {

        public static 
    void main(String[] args) {
            try {
                
    Runtime rt Runtime.getRuntime();
                
    Process proc rt.exec("avconv -version");

                
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");            
                
                
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
                    
                
    errorGobbler.start();
                
    outputGobbler.start();
                
                
    int exitVal proc.waitFor();
                
    System.out.println("ExitValue: " exitVal);
                
            } catch(
    Throwable t) {
                
    t.printStackTrace();
            }
        }

    b) I'd suggest Xuggler, or you can google for another with 'ffmpeg java wrapper' or similar.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •