普通视频转灰度视频三步走(试验阶段)

前言:字符画版的极乐净土超好看的,以此为切入点,学了一下用FFMPEG和Java代码整合。

我的思路:

1 . 将视频切割为60FPS的一张张图片;

2 . 分别将图片转为相应的灰度图片或者字符画图片;

3 .将灰度图片合称为一个60FPS的视频(此时没有声音);

由于时间和能力有限,先用代码实现到这里,此篇文章只是提供一个实现的基础调用代码和相关思路。

如有好的其他思路欢迎留言。

图片转化速度太慢了,我把一个两分钟的视频提取了9600张图片,结果转化速度大概有 5S/张。

ConvertToGray.Java

具体细节原理网上很多,慢慢看

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 = ImageIO.read(new 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);
		        } 
	    	}
	    	 
	        
	        
	    }
	}

Mp4ToPic.Java

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()) {  
	            System.out.println("*******************ok****well*****done********************");  
	        }  
	    }  
	 
	 
	 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";
	        
	        System.out.println(command1);
	        
	        try {  
	        	Process process1=Runtime.getRuntime().exec(command1);
	        	status=true;
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  

	        return status;  
	    }
}

PicToMP4.Java

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 ";
		System.out.println(command2);
		try {  
        	//Process process1=Runtime.getRuntime().exec(command1);
    
        	
        	Process process2 = Runtime.getRuntime().exec(command2);
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
		System.out.println("over****************");
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值