網(wǎng)站估值網(wǎng)絡(luò)營(yíng)銷課程感悟
命令行版本
ffmpeg -y -i "rtsp://你的rtsp地址" -vcodec copy -f mp4 d:/1.mp4
中間的rtsp網(wǎng)址一定要加上雙引號(hào),避免出現(xiàn)url有特殊字符的問(wèn)題
java代碼版本
如果不支持tcp協(xié)議,去掉下面兩個(gè)參數(shù)即可,加上這兩個(gè)參數(shù)是因?yàn)閒fmpeg默認(rèn)使用udp協(xié)議,會(huì)導(dǎo)致丟包
-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;}