FFmpeg framework series: video compression

1. Introduction and installation of FFmpeg

I will teach you in this five-minute JAVA code: FFmpeg implementation video demo (window version) is very detailed, install FFmepg on windows/Linux, I will not elaborate here.

2. Compress the video

To compress mp4 video, use H.264 video compression algorithm and AAC audio compression algorithm, the video frame rate is 10fps, the audio bit rate is 32k, the execution command is as follows:

ffmpeg.exe -i xxx.mp4  -r 10 -b:a 32k  end.mp4

3. The effect is as follows

Insert picture description here

4. Complete source code

public class ExecWindowCMD {
    
    

    public static void main(String[] args) {
    
    

     
        //视频压缩
        compressVedio();
    }

    //视频压缩
    public static void compressVedio(){
    
    
      
        String cmdStr = "F:\\ffmpegDemo\\ffmpeg\\bin\\ffmpeg.exe -i  F:\\ffmpegDemo\\aaa.mp4 -r 10 -b:a 32k  F:\\ffmpegDemo\\aaa2.mp4";
        Runtime run = Runtime.getRuntime();
        try {
    
    
            Process process = run.exec("c:/nircmd.exe elevate  " + cmdStr);
            InputStream in = process.getInputStream();
            while (in.read() != -1) {
    
    
                System.out.println(in.read());
            }
            in.close();
            process.waitFor();
        } catch (Exception e) {
    
    
            e.printStackTrace();
        }
        System.out.println("----视频压缩成功----");
    }

Guess you like

Origin blog.csdn.net/u010312671/article/details/108739970