Three steps from ordinary video to grayscale video (test stage)

Keywords: Java

The pure land of blissful in character drawing is very beautiful. As a starting point, I learned how to integrate FFMPEG and Java code.

My thoughts:

1. Cut the video into 60FPS pictures;

2. Turn the picture into corresponding gray picture or character picture respectively;

3. The gray image is called a 60FPS video (there is no sound at this time);

Due to the limited time and ability, we first use code to achieve this. This article only provides a basic calling code and related ideas for implementation.

If you have any other ideas, please leave a message.

The image conversion speed is too slow. I extracted 9600 images from a two minute video, and the conversion speed is about 5S.


There are many details on the Internet. Take a look

public class ConvertToGray {
//	    public static int getGray(Color pixel) {
//	        return (pixel.getRed()*30+pixel.getGreen()*60+pixel.getBlue()*10)/100;
//	    }
	    public static void main(String[] args) throws IOException {
	    	int a=1;
	    	String path = "C:\\Users\\Administrator\\Desktop\\ffmpeg\\photo6\\"+a+".jpeg";
	    	for(a=1;a<=9600;a++) {
	    		BufferedImage bufferedImage = File(path));
		    	int width = bufferedImage.getWidth();  
		        int height = bufferedImage.getHeight(); 
		    	BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); 
		        for(int i= 0 ; i < width ; i++){  
		            for(int j = 0 ; j < height; j++){  
		            int rgb = bufferedImage.getRGB(i, j);  
		            grayImage.setRGB(i, j, rgb);  
		            String grayPath= "C:\\Users\\Administrator\\Desktop\\gray\\"+a+".jpg"; 
		            File newFile = new File(grayPath);  
			        ImageIO.write(grayImage, "jpg", newFile);


public class FFmpeg {
	 private final static String PATH = "C:\\Users\\Administrator\\Desktop\\ffmpeg\\input\\1.mp4"; 
	 public static void main(String[] args) {  
//	        if (!checkfile(PATH)) {  
//	            System.out.println(PATH + " is not file");  
//	            return;  
//	        }  
	        if (process()) {  
	 private static boolean checkfile(String path) {  
	        File file = new File(path);  
	        if (!file.isFile()) {  
	            return false;  
	        return true;  
	 private static boolean process() {  
	        boolean status = false;  
	        String command1="ffmpeg -i  C:\\Users\\Administrator\\Desktop\\ffmpeg\\input\\1.mp4 " +
	        "-r 60 -f image2 C:\\Users\\Administrator\\Desktop\\ffmpeg\\photo6\\%d.jpeg";
	        try {  
	        	Process process1=Runtime.getRuntime().exec(command1);
	        } catch (Exception e) {  

	        return status;  


public class PicYoMP4 {
	public static void main(String[] args) {
		String command2="ffmpeg -y -r 60 -i C:\\Users\\Administrator\\Desktop\\ffmpeg"+
        		"\\photo5\\%d.jpeg -vcodec libx264 C:\\Users\\Administrator\\Desktop\\ffmpeg\\666.mp4 ";
		try {  
        	//Process process1=Runtime.getRuntime().exec(command1);
        	Process process2 = Runtime.getRuntime().exec(command2);
        } catch (Exception e) {  


Posted by EricC on Wed, 08 Jan 2020 07:40:43 -0800