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){}
}
}
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.
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 %^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.