0

I want to write a program that converts video into frames using FFMPEG. When I use it on the Ubuntu terminal, it works fine. But when I try to put it into the Java code, it gives me a runtime error. Did I make a mistake in my code below?

import java.util.*;
import java.awt.*;
import java.lang.*;
import java.lang.Runtime;
import java.io.*;
import java.io.IOException;

public class ConvertVideoToImage
{
    private SingletonServer ss = null;

    public ConvertVideoToImage(SingletonServer ss)
    {
        this.ss = ss;
    }

    public void run()
    {
        convertVideo();
    }

    public void convertVideo()
    {
        try
        {
            Runtime rt = Runtime.getRunTime().exec("ffmpeg" + "-i" +         "display.wmv" + "image%d.jpg");
        }
        catch(Exception e){}
    }

}

Edit:

I have changed the code like you suggested, but it also doesn't work. And when I Googled it, I found out that someone put the full path inside the executable and it became like this:

Runtime.getRuntime().exec("/home/pc3/Documents/ffmpeg_temp/ffmpeg -i display.wmv image%d.jpg")

BTW, thanks for the reply. I have another question. Is it possible to make a counter for FFMPEG? I used this command in the Ubuntu terminal to make it convert a video to 30 frames/1seconds:

ffmpeg -i display.wmv image%d.jpg

This will automatically generate numbers like image1.jpg, image2.jpg, to image901.jpg. Is it possible to make a counter for this? Because I need to count the files and control the number.

Thanks in advance.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Eric
  • 401
  • 4
  • 13
  • 21

1 Answers1

0

When you call exec, you should not specify the parameters in the command string, instead, pass them in an array as second parameter.

Process p = Runtime.getRunTime().exec("ffmpeg",
               new String[]{"-i", "display.wmv", "image%d.jpg"));
//                        are you sure regarding this %^
MByD
  • 135,866
  • 28
  • 264
  • 277
  • thanks for the reply . i have change the code like you suggest but i doesn't work also . and i google it, i found out that someone put the full path inside the exec and it becomd like this Runtime.getRuntime().exec("/home/pc3/Documents/ffmpeg_temp/ffmpeg -i display.wmv image%d.jpg") it can compile without error. is there possible to use a counter to replace the image%d.jpg ? thanks in advance – Eric Apr 17 '12 at 07:32