ffmpeg2 video synthesis

View resolution 
frame rate and encoder ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height,avg_frame_rate -of default=noprint_wrappers=1 rs2.mp4 get, encoder, resolution, 
and frame rate codec_name=h264 
width=1920 
height=1080 
avg_fra me_rate=60/1







All with the same frame rate, resolution and encoder

ffmpeg -i "concat:input1.mp4|input2.mp4" -c copy output.mp4

I don’t know why I have been trying for a long time, but I can only generate a video, and the result of the synthesis is wrong, so I have to use txt to get it.

get

 file.txt

file 'rs.mp4'
file 'rs2.mp4'

Then the code gets

ffmpeg -f concat -i "file.txt" -c:v copy ttt3.mp4

java code

View file resolution


 

import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class VideoInfo {

    public static void main(String[] args) {
        String videoPath = "path/to/video.mp4";

        try {
            ProcessBuilder processBuilder = new ProcessBuilder(
                    "ffprobe",
                    "-v", "error",
                    "-select_streams", "v:0",
                    "-show_entries", "stream=codec_name,width,height,avg_frame_rate",
                    "-of", "json",
                    videoPath
            );

            Process process = processBuilder.start();

            // 读取ffprobe命令的输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder output = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                output.append(line);
            }

            process.waitFor();

            // 解析JSON输出
            JSONObject jsonObject = JSONObject.parseObject(output.toString());
            JSONArray streams = jsonObject.getJSONArray("streams");
            JSONObject contentParamJson = streams.getJSONObject(0);
            System.out.println(contentParamJson);
            System.out.println(jsonObject);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Synthesize video at a specified frame rate

-r "frame rate"

Guess you like

Origin blog.csdn.net/qq_38403590/article/details/131719825