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