• ffmpeg2段视频合成一段


    查看分辨率
    帧率和编码器
    ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height,avg_frame_rate -of default=noprint_wrappers=1 rs2.mp4
    
    得到,编码器,分辨率,还有帧率
    codec_name=h264
    width=1920
    height=1080
    avg_frame_rate=60/1
    
    
    
    
    

    都是在帧率和分辨率以及编码器相同的情况下

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

    这种是不知道为什么尝试了很久,都只能生成一个视频,合成出来的结果不对,必须用txt来弄。

    而得

     file.txt

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

    然后代码得

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

    java代码

    查看文件的分辨率


     

    1. import com.alibaba.fastjson.JSONObject;
    2. import java.io.BufferedReader;
    3. import java.io.IOException;
    4. import java.io.InputStreamReader;
    5. public class VideoInfo {
    6. public static void main(String[] args) {
    7. String videoPath = "path/to/video.mp4";
    8. try {
    9. ProcessBuilder processBuilder = new ProcessBuilder(
    10. "ffprobe",
    11. "-v", "error",
    12. "-select_streams", "v:0",
    13. "-show_entries", "stream=codec_name,width,height,avg_frame_rate",
    14. "-of", "json",
    15. videoPath
    16. );
    17. Process process = processBuilder.start();
    18. // 读取ffprobe命令的输出
    19. BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    20. StringBuilder output = new StringBuilder();
    21. String line;
    22. while ((line = reader.readLine()) != null) {
    23. output.append(line);
    24. }
    25. process.waitFor();
    26. // 解析JSON输出
    27. JSONObject jsonObject = JSONObject.parseObject(output.toString());
    28. JSONArray streams = jsonObject.getJSONArray("streams");
    29. JSONObject contentParamJson = streams.getJSONObject(0);
    30. System.out.println(contentParamJson);
    31. System.out.println(jsonObject);
    32. } catch (IOException | InterruptedException e) {
    33. e.printStackTrace();
    34. }
    35. }
    36. }

    按照指定的帧率合成视频

    -r "帧率"
  • 相关阅读:
    Linux--进程控制
    总结 NAT 机制的工作流程及优缺点
    mac 配置 httpd nginx php-fpm 详细记录 已解决
    【算法】数学之旅,根据素数特征寻找底数
    golang学习笔记——日志记录
    (6)点云数据处理学习——RGBD图
    作业 1创建用户
    CSP-J第二轮试题-2020年-1.2题
    vBox+K8s坑记录
    我已经31了
  • 原文地址:https://blog.csdn.net/qq_38403590/article/details/131719825