命令行版本
ffmpeg -y -i "rtsp://你的rtsp地址" -vcodec copy -f mp4 d:/1.mp4
中间的rtsp网址一定要加上双引号,避免出现url有特殊字符的问题
java代码版本
如果不支持tcp协议,去掉下面两个参数即可,加上这两个参数是因为ffmpeg默认使用udp协议,会导致丢包
-rtsp_transport、-tcp
public static Boolean RTSPToMp4(String rstpUrl, String filePath) {if(StrUtil.isBlank(rstpUrl) || StrUtil.isBlank(filePath)) {return false;}ProcessBuilder extractBuilder = new ProcessBuilder("C:\\Program Files (x86)\\ffmpeg\\ffmpeg.exe"", "-y", "-rtsp_transport", " tcp", "-i",rstpUrl, "-vcodec", "copy", "-f", "mp4", filePath);try {extractBuilder.inheritIO().start().waitFor();} catch (InterruptedException | IOException e) {e.printStackTrace();return false;}return true;}