写点什么

SpringBoot 实现大文件视频转码(转码基于 FFMPEG 实现)(1)

用户头像
极客good
关注
发布于: 刚刚

/**


  • 获取文件名

  • @param filePath

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10


*/


public String getFileName(String filePath) {


return filePath.substring(filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR) + 1, filePath.lastIndexOf("."));


}


}


class PrintStream extends Thread {


java.io.InputStream __is = null;


public PrintStream(java.io.InputStream is) {


__is = is;


}


@Override


public void run() {


try {


while (this != null) {


int _ch = __is.read();


if (_ch != -1) {


System.out.print((char) _ch);


} else {


break;


}


}


} catch (Exception e) {


e.printStackTrace();


}


}


}


2、BootstrapConst 类?


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


/**


  • @Classname: com.openailab.oascloud.security.common.consts.BootstrapConst

  • @Description: 简单常量定义

  • @Author: zxzhang

  • @Date: 2019/10/8


*/


public class BootstrapConst {


/**


  • 文件缓冲区大小


*/


public static final Integer INPUT_BUFFER_SIZE = 8192;


/**


  • 文件分隔符


*/


public static final char PATH_SEPARATOR = '/';


/**


  • 文件点


*/


public static final char SPOT = '.';


/**


  • 常量一


*/


public static final Integer ONE = 1;


/**


  • 成功


*/


public static final Integer SUCCESS = 1;


/**


  • 失败


*/


public static final Integer FAIL = 0;


/**


  • true


*/


public static final Boolean TRUE = true;


/**


  • false


*/


public static final Boolean FALSE = false;


}


三、FFMPeg DockerFile 实现




首先我们构建具有 JDK1.8 和 FFMPeg 环境的镜像


FROM jrottenberg/ffmpeg:centos


MAINTAINER oas.cloud


ADD jdk-8u231-linux-x64.tar.gz /usr/local/


ENV JAVA_HOME /usr/local/jdk1.8.0_231


ENV CLASSPATH JAVA_HOME/lib/tools.jar


ENV PATH JAVA_HOME/bin


WORKDIR /usr/local/oas/


然后将上述文件构建出的镜像的 tag 打为我们自己的镜像仓库地址,改为 10.12.1.202:8088/oascloud/ffmpeg:v1.0,我们的应用程序就可以以上述镜像文件(10.12.1.202:8088/oascloud/ffmpeg:v1.0)为基础构建出新的应用程序镜像,应用程序的 DockerFile 如下:


FROM 10.12.1.202:8088/oascloud/ffmpeg:v1.0


MAINTAINER oas.cloud


ENV LC_ALL=zh_CN.utf8


ENV LANG=zh_CN.utf8


ENV LANGUAGE=zh_CN.utf8


RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8


ARG JAR_FILE


COPY ${JAR_FILE} /usr/local/oas/


WORKDIR /usr/local/oas/


代码结构如下:


![](https://img-blog.csdnimg.cn/2020


【一线大厂Java面试题解析+核心总结学习笔记+最新架构讲解视频+实战项目源码讲义】
浏览器打开:qq.cn.hn/FTf 免费领取
复制代码


0121124156980.png)


附上 Kubernetes 编排文件,deploy.yaml 内容如下:


apiVersion: apps/v1


kind: Deployment


metadata:


name: openailab-data-file-management


namespace: oas-tengine2dev


labels:


name: openailab-data-file-management


spec:


replicas: 1


selector:


matchLabels:


name: openailab-data-file-management


template:


metadata:


labels:


name: openailab-data-file-management


spec:


affinity:


nodeAffinity:


requiredDuringSchedulingIgnoredDuringExecution:


nodeSelectorTerms:


  • matchExpressions:

  • key: env


operator: In


values:


  • tengine2dev


containers:


  • name: openailab-data-file-management


image: 10.12.1.202:8088/tengine2/openailab-data-file-management:latest


env:


  • name: APOLLO_APP_ID


value: 'tengine2-data-file-management'


  • name: APOLLO_EUREKA_URI


value: 'http://10.98.100.95:8080/'


  • name: APOLLO_NAMESPACE


value: 'application'


  • name: SPRING_EUREKA_URI


value: 'http://10.111.176.222:8080/eureka/'


volumeMounts:


  • name: openailab-data-file-management


mountPath: /usr/local/logs


  • name: file


mountPath: /usr/local/oas/file


command: ['sh','-c','java -server -Xms2048m -Xmx3072m -Djava.io.tmpdir=/var/tmp -Duser.timezone=Asia/Shanghai -jar openailab-data-file-management-*.jar --server.port=8080 --spring.profiles.active=remote']


ports:


  • containerPort: 8080


resources:


requests:


memory: 256Mi


cpu: 150m


limits:


memory: 2048Mi


cpu: 300m


initContainers:


  • name: init-apollo


image: busybox


command: ['sh', '-c']


args:


  • echo Prepare to apollo initialize..;


until nc -w 1 -z 10.98.100.95 8080;


do echo Waiting for eureka initialization to complete..; sleep 10; done;


echo Eureka is ready.;


until nc -w 1 -z 10.98.100.95 8090;


do echo Waiting for admin initialization to complete..; sleep 10; done;


echo Admin is ready.;


echo Apollo Initialization successful!;


volumes:


  • name: openailab-data-file-management


hostPath:


path: /usr/local/logs


  • name: file


hostPath:


path: /usr/local/oas/file


svc.yaml 内容如下:


apiVersion: v1


kind: Service


metadata:


name: openailab-data-file-management


namespace: oas-tengine2dev


labels:


name: openailab-data-file-management


spec:


type: NodePort


ports:


  • nodePort: 32318


targetPort: 8080


port: 8080


protocol: TCP


selector:


name: openailab-data-file-management

用户头像

极客good

关注

还未添加个人签名 2021.03.18 加入

还未添加个人简介

评论

发布
暂无评论
SpringBoot 实现大文件视频转码(转码基于FFMPEG实现)(1)