SpringBoot 实现大文件视频转码(转码基于FFMPEG实现),java基础入门第二版课后题答案

本文介绍了如何在SpringBoot应用中利用FFmpeg进行大文件视频转码,包括转码类FileManagementHelper的实现,以及FFmpeg DockerFile的创建,用于构建包含JDK1.8和FFmpeg环境的镜像。
摘要由CSDN通过智能技术生成

1、FileManagementHelper 视频转码类

package com.openailab.oascloud.file.common.helper;

import com.openailab.oascloud.file.common.config.BootstrapConfig;

import com.openailab.oascloud.file.common.consts.BootstrapConst;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;

import java.io.File;

import java.io.IOException;

import java.util.Arrays;

import java.util.LinkedList;

/**

  • @description: 视频转码

  • @author: zhangzhixiang

  • @createDate: 2019/12/11

  • @version: 1.0

*/

@Component

public class FileManagementHelper {

private static final Logger LOG = LoggerFactory.getLogger(FileManagementHelper.class);

@Autowired

private BootstrapConfig bootstrapConfig;

/**

  • 文件转码

  • @param filePath

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2019/12/10

*/

public int transcode(String filePath) {

//1、获取文件名和后缀

String ext = getExt(filePath);

String fileDir = getFileDir(filePath);

String fileName = getFileName(filePath);

//2、删除同名文件

File originFile = new File(fileDir + fileName + BootstrapConst.SPOT + ext);

if (originFile.exists()){

originFile.delete();

}

//3、视频转码

LinkedList ffmpegCmds = new LinkedList<>();

ffmpegCmds.add(“ffmpeg”);

ffmpegCmds.add("-i");

ffmpegCmds.add(bootstrapConfig.getFileRoot() + filePath);

ffmpegCmds.add("-c:v");

ffmpegCmds.add(“libx264”);

ffmpegCmds.add("-strict");

ffmpegCmds.add("-2");

ffmpegCmds.add(bootstrapConfig.getFileRoot() + fileDir + BootstrapConst.PATH_SEPARATOR + fileName + “.mp4”);

ProcessBuilder builder = new ProcessBuilder();

builder.command(ffmpegCm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值