Java使用ffmpeg


首先完成基本的Java調用ffmpeg代碼實現

package com.example.ffmpegtest01.service.impl;

import com.example.ffmpegtest01.service.OperationService;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class OperationServiceImpl implements OperationService {

    @Override
    public Boolean ForAvi(String sourcePath, String targetPath) {//sourcePtah是對應的文件的路徑
        String webroot = "D:\\devsoft\\ffmpeg\\bin";
        Runtime run= null;
        System.out.println(new File(webroot).getAbsolutePath());
        try{
            run = Runtime.getRuntime();
            long start = System.currentTimeMillis();
            //File diretory = new File("");
            System.out.println("開始");
            Process p = run.exec(new File(webroot).getAbsolutePath()+"/ffmpeg -i "+sourcePath+" -codec copy "+targetPath);
            System.out.println("結束");
            long end = System.currentTimeMillis();
            System.out.println("轉化結束"+(end-start));
            p.getOutputStream().close();
            p.getInputStream().close();
            p.getErrorStream().close();
            p.waitFor();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }finally {
            run.freeMemory();
        }
    }
}

Java操作ffmpeg優秀博客

如何用java代碼調用ffmpeg進行視頻轉碼

ffmpeg一些命令

博客借鑒

使用FFmpeg提取視頻中的圖像(根據幀間隔、時間間隔)

ffmpeg提取音頻視頻,合並音頻視頻

ffmfeg


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM