当前位置: 首页 > news >正文

SpringBoot整合FFmpeg进行视频分片上传(Linux)

SpringBoot整合FFmpeg进行视频分片上传(Linux)

上传的核心思路:
1.将文件按一定的分割规则(静态或动态设定,如手动设置20M为一个分片),用slice分割成多个数据块。
2.为每个文件生成一个唯一标识Key,用于多数据块上传时区分所属文件。
3.所有分片上传完成,服务端校验合并标识为Key的所有分片为一个最终文件。

分片上传到意义:
将文件分片上传,在网络环境不佳时,可以对文件上传失败的部分重新上传,避免了每次上传都需要从文件起始位置上传的问题。
分片的附带好处还能很方便的实现进度条。

分片上传的原理:
使用ffmpeg,把视频文件切片成m3u8,并且通过springboot,可以实现在线的点播。
客户端上传视频到服务器,服务器对视频进行切片后,返回m3u8,封面等访问路径。可以在线的播放。

准备工作:
需要先在linux下安装FFmpeg,并配置环境变量
一:下载、解压
使用命令下载:

wget https://johnvansickle.com/ffmpeg/release-source/ffmpeg-4.1.tar.xz
#使用命令解压:
cd  /root/FFmpeg
tar -xvJf ffmpeg-4.1.tar.xz 
# 编辑准备
cd /root/FFmpeg/ffmpeg-4.1    # 切换到ffmpeg-4.1目录
yum install gcc  # 安装gcc编译器

yasm安装包

cd /root/FFmpeg
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz  #下载源码包
tar zxvf yasm-1.3.0.tar.gz #解压
cd yasm-1.3.0 #进入目录
./configure #配置
make && make install #编译安装

安装FFmpeg

cd /root/FFmpeg/ffmpeg-4.1/
./configure --enable-shared --prefix=/usr/local/ffmpeg-4.1
make && make install #编译安装

下载x264

cd /root/libx264/
yum -y install git
git clone https://git.videolan.org/git/x264.git

安装nasm

tar -xvf nasm-2.14.02.tar.gz 
cd nasm-2.14.02
./configure
make
sudo make install
#查看是否安装成功
nasm -version

安装x264

cd /root/FFmpeg/libx264/x264
./configure --prefix=/usr/softinstall/x264/ --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared
make
sudo make install

安装FFmpeg

#配置 /etc/ld.so.conf
vim /etc/ld.so.conf #通过vim指令进入位于etc目录中的ld.so.conf
#输入i进入插入模式,将第二行的内容插入到该文件
include ld.so.conf.d/*.conf
/usr/local/ffmpeg-4.1/libldconfig  #ldconfig 是一个动态链接库管理命令,其目的为了让动态链接库为系统所共享。
make
sudo make install
# ffmpeg  -i  /root/FFmpeg/wukel.mp4  -c:v  libx264  -c:a  copy  -hls_key_info_file  /root/FFmpeg/video_folder/20220308/test1/  -hls_time  15  -hls_playlist_type  vod  -hls_segment_filename  %06d.ts  index.m3u8
ldd ffmpeg
cd /root/FFmpeg/ffmpeg-4.1
./configure --prefix=/usr/softinstall/ffmpeg --enable-gpl --enable-shared --enable-libx264# 配置环境变量
vim /etc/profile
#配置如下
export FFMPEG_HOME=/usr/local/ffmpeg-4.1
export PATH=$FFMPEG_HOME/bin:$PATH
#修改完使用命令退出
~:wq
source /etc/profile
# 测试
ffmpeg -version
~~~~~~~~成功~~~~~~~~~

代码展示:
pom文件
pom.xml

	<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.4</version><relativePath /> <!-- lookup parent from repository --></parent><properties><java.version>1.8</java.version><javacv.version>1.5.4</javacv.version><ffmpeg.version>4.3.1-1.5.4</ffmpeg.version></properties><dependencies><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.2.2</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.5</version></dependency><!--web 模块 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><!--排除tomcat依赖 --><exclusion><artifactId>spring-boot-starter-tomcat</artifactId><groupId>org.springframework.boot</groupId></exclusion></exclusions></dependency><!--undertow容器 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-undertow</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--      javacv 和 ffmpeg的依赖包      --><dependency><groupId>org.bytedeco</groupId><artifactId>javacv</artifactId><version>${javacv.version}</version><exclusions><exclusion><groupId>org.bytedeco</groupId><artifactId>*</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.bytedeco</groupId><artifactId>ffmpeg-platform</artifactId><version>${ffmpeg.version}</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.6.5</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-undertow</artifactId></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><executable>true</executable></configuration></plugin></plugins></build>

yml配置
application.yml

server:port: 8086app:# 存储转码视频的文件夹video-folder: /root/FFmpeg/video_folderspring:servlet:multipart:enabled: true# 不限制文件大小max-file-size: -1# 不限制请求体大小max-request-size: -1# 临时IO目录location: "${java.io.tmpdir}"# 不延迟解析resolve-lazily: false# 超过1Mb,就IO到临时目录file-size-threshold: 1MBweb:resources:static-locations:- "classpath:/static/"- "file:${app.video-folder}" # 把视频文件夹目录,添加到静态资源目录列表

工具类
MediaInfo

import java.util.List;import com.google.gson.annotations.SerializedName;public class MediaInfo {public static class Format {@SerializedName("bit_rate")private String bitRate;public String getBitRate() {return bitRate;}public void setBitRate(String bitRate) {this.bitRate = bitRate;}}public static class Stream {@SerializedName("index")private int index;@SerializedName("codec_name")private String codecName;@SerializedName("codec_long_name")private String codecLongame;@SerializedName("profile")private String profile;}@SerializedName("streams")private List<Stream> streams;@SerializedName("format")private Format format;public List<Stream> getStreams() {return streams;}public void setStreams(List<Stream> streams) {this.streams = streams;}public Format getFormat() {return format;}public void setFormat(Format format) {this.format = format;}
}

TranscodeConfig

import lombok.Data;@Data
public class TranscodeConfig {private String poster = "00:00:00.001";				// 截取封面的时间			HH:mm:ss.[SSS]private String tsSeconds = "15";			// ts分片大小,单位是秒private String cutStart;			// 视频裁剪,开始时间		HH:mm:ss.[SSS]private String cutEnd;				// 视频裁剪,结束时间		HH:mm:ss.[SSS]public String getPoster() {return poster;}public void setPoster(String poster) {this.poster = poster;}public String getTsSeconds() {return tsSeconds;}public void setTsSeconds(String tsSeconds) {this.tsSeconds = tsSeconds;}public String getCutStart() {return cutStart;}public void setCutStart(String cutStart) {this.cutStart = cutStart;}public String getCutEnd() {return cutEnd;}public void setCutEnd(String cutEnd) {this.cutEnd = cutEnd;}@Overridepublic String toString() {return "TranscodeConfig [poster=" + poster + ", tsSeconds=" + tsSeconds + ", cutStart=" + cutStart + ", cutEnd="+ cutEnd + "]";}
}

FFmpegUtils

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;import javax.crypto.KeyGenerator;import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;import com.google.gson.Gson;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;public class FFmpegUtils {private static final Logger LOGGER = LoggerFactory.getLogger(FFmpegUtils.class);// 跨平台换行符private static final String LINE_SEPARATOR = System.getProperty("line.separator");/*** 生成随机16个字节的AESKEY* @return*/private static byte[] genAesKey ()  {try {KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");keyGenerator.init(128);return keyGenerator.generateKey().getEncoded();} catch (NoSuchAlgorithmException e) {return null;}}/*** 在指定的目录下生成key_info, key文件,返回key_info文件* @param folder* @throws IOException */private static Path genKeyInfo(String folder) throws IOException {// AES 密钥byte[] aesKey = genAesKey();// AES 向量String iv = Hex.encodeHexString(genAesKey());// key 文件写入Path keyFile = Paths.get(folder, "key");Files.write(keyFile, aesKey, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);// key_info 文件写入StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("key").append(LINE_SEPARATOR);					// m3u8加载key文件网络路径stringBuilder.append(keyFile.toString()).append(LINE_SEPARATOR);	// FFmeg加载key_info文件路径stringBuilder.append(iv);											// ASE 向量Path keyInfo = Paths.get(folder, "key_info");Files.write(keyInfo, stringBuilder.toString().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);return keyInfo;}/*** 指定的目录下生成 master index.m3u8 文件* @param file			master m3u8文件地址* @param indexPath			访问子index.m3u8的路径* @param bandWidth			流码率* @throws IOException*/private static void genIndex(String file, String indexPath, String bandWidth) throws IOException {StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("#EXTM3U").append(LINE_SEPARATOR);stringBuilder.append("#EXT-X-STREAM-INF:BANDWIDTH=" + bandWidth).append(LINE_SEPARATOR);  // 码率stringBuilder.append(indexPath);Files.write(Paths.get(file), stringBuilder.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);}/*** 转码视频为m3u8* @param source				源视频* @param destFolder			目标文件夹* @param config				配置信息* @throws IOException * @throws InterruptedException */public static void transcodeToM3u8(String source, String destFolder, TranscodeConfig config) throws IOException, InterruptedException {// 判断源视频是否存在if (!Files.exists(Paths.get(source))) {throw new IllegalArgumentException("文件不存在:" + source);}// 创建工作目录Path workDir = Paths.get(destFolder, "ts");Files.createDirectories(workDir);// 在工作目录生成KeyInfo文件Path keyInfo = genKeyInfo(workDir.toString());// 构建命令List<String> commands = new ArrayList<>();commands.add("ffmpeg");commands.add("-i")						;commands.add(source);					// 源文件commands.add("-c:v")					;commands.add("libx264");				// 视频编码为H264commands.add("-c:a")					;commands.add("copy");					// 音频直接copycommands.add("-hls_key_info_file")		;commands.add(keyInfo.toString());		// 指定密钥文件路径commands.add("-hls_time")				;commands.add(config.getTsSeconds());	// ts切片大小commands.add("-hls_playlist_type")		;commands.add("vod");					// 点播模式commands.add("-hls_segment_filename")	;commands.add("%06d.ts");				// ts切片文件名称if (StringUtils.hasText(config.getCutStart())) {commands.add("-ss")					;commands.add(config.getCutStart());	// 开始时间}if (StringUtils.hasText(config.getCutEnd())) {commands.add("-to")					;commands.add(config.getCutEnd());		// 结束时间}commands.add("index.m3u8");														// 生成m3u8文件// 构建进程Process process = new ProcessBuilder().command(commands).directory(workDir.toFile()).start();// 读取进程标准输出new Thread(() -> {try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {String line = null;while ((line = bufferedReader.readLine()) != null) {LOGGER.info(line);}} catch (IOException e) {}}).start();// 读取进程异常输出new Thread(() -> {try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {String line = null;while ((line = bufferedReader.readLine()) != null) {LOGGER.info(line);}} catch (IOException e) {}}).start();// 阻塞直到任务结束if (process.waitFor() != 0) {throw new RuntimeException("视频切片异常");}// 切出封面if (!screenShots(source, String.join(File.separator, destFolder, "poster.jpg"), config.getPoster())) {throw new RuntimeException("封面截取异常");}// 获取视频信息final MediaInfo[] mediaInfo = {getMediaInfo(source)};if (mediaInfo[0] == null) {throw new RuntimeException("获取媒体信息异常");}// 生成index.m3u8文件genIndex(String.join(File.separator, destFolder, "index.m3u8"), "ts/index.m3u8", mediaInfo[0].getFormat().getBitRate());// 删除keyInfo文件Files.delete(keyInfo);}/*** 获取视频文件的媒体信息* @param source* @return* @throws IOException* @throws InterruptedException*/public static MediaInfo getMediaInfo(String source) throws IOException, InterruptedException {List<String> commands = new ArrayList<>();commands.add("ffprobe");	commands.add("-i")				;commands.add(source);commands.add("-show_format");commands.add("-show_streams");commands.add("-print_format")	;commands.add("json");Process process = new ProcessBuilder(commands).start();MediaInfo mediaInfo = null;try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {mediaInfo = new Gson().fromJson(bufferedReader, MediaInfo.class);} catch (IOException e) {e.printStackTrace();}if (process.waitFor() != 0) {return null;}return mediaInfo;}/*** 截取视频的指定时间帧,生成图片文件* @param source		源文件* @param file			图片文件* @param time			截图时间 HH:mm:ss.[SSS]		* @throws IOException * @throws InterruptedException */public static boolean screenShots(String source, String file, String time) throws IOException, InterruptedException {List<String> commands = new ArrayList<>();commands.add("ffmpeg");commands.add("-i")				;commands.add(source);commands.add("-ss")				;commands.add(time);commands.add("-y");commands.add("-q:v")			;commands.add("1");commands.add("-frames:v")		;commands.add("1");commands.add("-f");				;commands.add("image2");commands.add(file);Process process = new ProcessBuilder(commands).start();// 读取进程标准输出new Thread(() -> {try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {String line = null;while ((line = bufferedReader.readLine()) != null) {LOGGER.info(line);}} catch (IOException e) {}}).start();// 读取进程异常输出new Thread(() -> {try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {String line = null;while ((line = bufferedReader.readLine()) != null) {LOGGER.error(line);}} catch (IOException e) {}}).start();return process.waitFor() == 0;}
}

controller调用
UploadController

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;import com.demo.ffmpeg.FFmpegUtils;
import com.demo.ffmpeg.TranscodeConfig;@RestController
@RequestMapping("/uploadController")
public class UploadController {@Value("${app.video-folder}")private String videoFolder;private Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));/*** 上传视频进行切片处理,返回访问路径* @param video* @param transcodeConfig* @return* @throws IOException */@PostMapping("/upload")@CrossOriginpublic Object upload (@RequestPart(name = "file", required = true) MultipartFile video,@RequestPart(name = "config", required = true) TranscodeConfig transcodeConfig) throws IOException {/**    参数传UUID去数据库查询需要转换的视频地址 进行入参public ResponseData upload (@RequestParam("uuid") String uuid) throws Exception {TranscodeConfig transcodeConfig = new TranscodeConfig();FastDfsFile fastDfsFile = sectionService.getSectionByUUID(uuid);if(fastDfsFile.getFastDfsFileUrl() == null){LOGGER.info("请上传视频!!");return ResponseData.warnWithMsg("请选择要上传的视频!");}MultipartFile video = UrlToMultipartFile.urlToMultipartFile(fastDfsFile.getFastDfsFileUrl());*/
LOGGER.info("文件信息:title={}, size={}", video.getOriginalFilename(), video.getSize());LOGGER.info("转码配置:{}", transcodeConfig);// 原始文件名称,也就是视频的标题String title = video.getOriginalFilename();// io到临时文件Path tempFile = tempDir.resolve(title);LOGGER.info("io到临时文件:{}", tempFile.toString());try {video.transferTo(tempFile);// 删除后缀title = title.substring(0, title.lastIndexOf(".")) + "-" + UUID.randomUUID().toString().replaceAll("-", "");// 按照日期生成子目录String today = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now());// 尝试创建视频目录Path targetFolder = Files.createDirectories(Paths.get(videoFolder, today, title));LOGGER.info("创建文件夹目录:{}", targetFolder);Files.createDirectories(targetFolder);// 执行转码操作LOGGER.info("开始转码");try {transcodeToM3u8(tempFile.toString(), targetFolder.toString(), transcodeConfig);} catch (Exception e) {LOGGER.error("转码异常:{}", e.getMessage());Map<String, Object> result = new HashMap<>();result.put("success", false);result.put("message", e.getMessage());return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);}// 封装结果Map<String, Object> videoInfo = new HashMap<>();videoInfo.put("title", title);videoInfo.put("m3u8", String.join("/", "", today, title, "index.m3u8"));videoInfo.put("poster", String.join("/", "", today, title, "poster.jpg"));//返回数据Map<String, Object> result = new HashMap<>();result.put("success", true);result.put("data", videoInfo);return result;} finally {// 始终删除临时文件Files.delete(tempFile);}}
}

Url转换MultipartFile的工具类
如controller中参数传的是URL 使用以下工具类转换一下即可
UrlToMultipartFile

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;public class UrlToMultipartFile {private static final Logger LOGGER = LoggerFactory.getLogger(UrlToMultipartFile.class);/*** inputStream 转 File*/public static File inputStreamToFile(InputStream ins, String name) throws Exception{//System.getProperty("java.io.tmpdir")临时目录+File.separator目录中间的间隔符+文件名File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);OutputStream os = new FileOutputStream(file);int bytesRead;int len = 8192;byte[] buffer = new byte[len];while ((bytesRead = ins.read(buffer, 0, len)) != -1) {os.write(buffer, 0, bytesRead);}os.close();ins.close();return file;}/*** file转multipartFile*/public static MultipartFile fileToMultipartFile(File file) {FileItemFactory factory = new DiskFileItemFactory(16, null);FileItem item=factory.createItem(file.getName(),"text/plain",true,file.getName());int bytesRead = 0;byte[] buffer = new byte[8192];try {FileInputStream fis = new FileInputStream(file);OutputStream os = item.getOutputStream();while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {os.write(buffer, 0, bytesRead);}os.close();fis.close();} catch (IOException e) {e.printStackTrace();}return new CommonsMultipartFile(item);}//url转MultipartFilepublic static MultipartFile urlToMultipartFile(String url) throws Exception {File file = null;MultipartFile multipartFile = null;try {HttpURLConnection httpUrl = (HttpURLConnection) new URL(url).openConnection();httpUrl.connect();file = UrlToMultipartFile.inputStreamToFile(httpUrl.getInputStream(),RandomStringUtils.randomAlphanumeric(8)+".mp4");LOGGER.info("---------"+file+"-------------");multipartFile = UrlToMultipartFile.fileToMultipartFile(file);httpUrl.disconnect();} catch (Exception e) {e.printStackTrace();}return multipartFile;}}

相关文章:

SpringBoot整合FFmpeg进行视频分片上传(Linux)

SpringBoot整合FFmpeg进行视频分片上传&#xff08;Linux&#xff09; 上传的核心思路&#xff1a; 1.将文件按一定的分割规则&#xff08;静态或动态设定&#xff0c;如手动设置20M为一个分片&#xff09;&#xff0c;用slice分割成多个数据块。 2.为每个文件生成一个唯一标识…...

eNSP综合小实验:VRRP、MSTP、Eth-Trunk、NAT、DHCP等技术应用

完成下图要求&#xff1a; 拓扑图&#xff1a; 配置命令&#xff1a; 由于交换机日志太多不便于复制&#xff0c;所以就复制命令。大概步骤如下&#xff1a; 第一步先分配IP地址&#xff0c;在sw1和sw2上创建VLAN100用于e0/0/3口配IP&#xff0c;在sw1、sw2、sw3、sw4上创建VL…...

正中优配:尾盘拉升的股票第二天的走势?

尾盘拉升是指买卖日快结束时股票价格呈现上涨的状况。关于许多投资者来说&#xff0c;这一般是好事情&#xff0c;因为它可认为他们带来更高的收益。但是&#xff0c;人们常常会问尾盘拉升的股票第二天的走势怎么。本文将从多个角度进行剖析。 首要&#xff0c;咱们需求认识到这…...

ios小组件报错:Please adopt containerBackground API

iOS 17 小组件报错:Please adopt containerBackground API 使用下面的方法解决了: 代码: extension View {func widgetBackground(_ backgroundView: some View) -> some View {if #available(iOSApplicationExtension 17.0, *) {return containerBackground(for: .wi…...

基于AWS的3D模型搜索服务实现

3D模型广泛应用于计算机游戏、电影、工程、零售业、广告等许多领域。市场上有很多制作3D模型的工具&#xff0c;但几乎没有工具可以直观地搜索3D模型数据库以找到类似的3D模型 因为开发好的 3D 模型搜索工具非常具有挑战性。 它需要复杂的计算和 AI/ML 框架来创建模型描述符并提…...

pycharm远程连接docker容器

pycharm远程连接docker容器 1.根据镜像创建容器2.进入容器3.修改容器的root密码4. 容器安装openssh-server和openssh-client5.修改SSH配置文件6.重启ssh服务7. 退出测试8.配置pycharm并连接docker容器9. 选择docker环境 1.根据镜像创建容器 sudo docker run -itd --nameconn_t…...

开源全球地理空间数据可视化框架——Cesium学习(2023.8.21)

Cesium学习 2023.8.21 1、Cesium简介1.1 Github上的Cesium 2、Cesium下载安装使用2.1 方式一&#xff1a;页面在线引用2.2 方式二&#xff1a;页面离线使用2.3 方式三&#xff1a;完整项目使用 3、CesiumJS学习教程&#xff08;快速上手 API文档&#xff09;3、Cesium官方示例…...

RT-Thread学习日记——点亮LED

最近开始接触RT-Thread&#xff0c;后面会单独建立专栏以此记录我的学习过程&#xff0c;如果能给你的学习提供参考&#xff0c;本人倍感荣幸。 学习工具&#xff1a;正点原子战舰开发板 一、、点亮LED 在RT-Thread的配置项里搜索LED可以看到和LED相关的很多内容&#xff0c…...

粘包问题(TCP面向字节流批量发送数据导致)

粘包问题出现的原因 由于TCP协议网络传输数据的基本单位是字节流&#xff0c;所以当应用程序收到了传输的数据时&#xff0c;看到的是一连串的字节数据&#xff0c;而TCP协议网络传输数据有滑动窗口的机制&#xff08;核心就是批量传输数据&#xff0c;推荐看TCP中窗口和滑动窗…...

selenium Chrome驱动下载地址

Chrome驱动官方最新版下载地址:https://googlechromelabs.github.io/chrome-for-testing/ 有稳定版&#xff0c;开发版等版本可以选择下载 选择 操作系统复制下载链接直接下载...

Linux命令200例:tar命令主要用于创建、查看和提取归档文件(常用)

&#x1f3c6;作者简介&#xff0c;黑夜开发者&#xff0c;全栈领域新星创作者✌。CSDN专家博主&#xff0c;阿里云社区专家博主&#xff0c;2023年6月csdn上海赛道top4。 &#x1f3c6;数年电商行业从业经验&#xff0c;历任核心研发工程师&#xff0c;项目技术负责人。 &…...

【Django】Task4 序列化及其高级使用、ModelViewSet

【Django】Task4 序列化及其高级使用、ModelViewSet Task4主要了解序列化及掌握其高级使用&#xff0c;了解ModelViewSet的作用&#xff0c;ModelViewSet 是 Django REST framework&#xff08;DRF&#xff09;中的一个视图集类&#xff0c;用于快速创建处理模型数据的 API 视…...

FFMPEG RTMP流打开速度慢优化方法一

先上使用方法&#xff1a; codec_ctx->flags | AVFMT_FLAG_NOBUFFER; AVFMT_FLAG_NOBUFFER 标记如果没有设置&#xff0c;就会导致打开时探测的数据包丢AVFormatContext的缓存区中。 播放的时候&#xff0c;就从这些数据包开始&#xff0c;但是整个探测过程时间可能较长&…...

NextJs - Middleware(中间件)

中间件允许您在请求完成之前运行代码。然后&#xff0c;根据传入的请求&#xff0c;您可以通过重写、重定向、修改请求或响应标头或直接响应来修改响应。 中间件在缓存内容和路由匹配之前运行。 使用规则 使用项目根目录中的文件 middleware.ts&#xff08;或 .js&#xff09…...

记录几个Hudi Flink使用问题及解决方法

前言 如题&#xff0c;记录几个Hudi Flink使用问题&#xff0c;学习和使用Hudi Flink有一段时间&#xff0c;虽然目前用的还不够深入&#xff0c;但是目前也遇到了几个问题&#xff0c;现在将遇到的这几个问题以及解决方式记录一下 版本 Flink 1.15.4Hudi 0.13.0 流写 流写…...

Go:测试框架GoConvey 简介

快速开始 GoConvey是一个完全兼容官方Go Test的测试框架&#xff0c;一般来说这种第三方库都比官方的功能要强大、更加易于使用、开发效率更高&#xff0c;闲话少说&#xff0c;先看一个example&#xff1a; package utils import (. "github.com/smartystreets/goconvey…...

JavaWeb-特殊文件(propertis与XML)

目录 Properties文件 一.properties介绍 二.properties使用 三.解决中文乱码问题 XML文件 一.XML介绍 二.XML文件的语法规则 三.XML的使用 Properties文件 一.properties介绍 1.什么是properties文件 Properties文件是一种常用的配置文件格式&#xff0c;用于存储键值…...

ffmpeg合并mp4视频文件

下载ffmpeg Download FFmpeg 2配置环境 右键此电脑-》属性-》高级系统设置 环境变量-》path 解压上面ffmpeg压缩包&#xff0c;找到bin目录&#xff0c;复制完整路径&#xff0c;添加到path环境变量中 测试ffmpeg ffmpeg合并MP4文件 创建一个文本文件&#xff0c;例如inpu…...

ATF BL1/BL2 ufs_read_blocks/ufs_write_blocks使用分析

ATF BL1/BL2 ufs_read_blocks/ufs_write_blocks使用分析 1 ATF的下载链接2 ATF BL1/BL2 ufs_read_blocks/ufs_write_blocks处理流程2.1 ATF BL1/BL2 ufs_read_blocks2.2 ATF BL1/BL2 ufs_write_blocks 3 UFS System Model4 ufs_read_blocks/ufs_write_blocks详细分析4.1 ufs_re…...

Elasticsearch(十二)搜索---搜索匹配功能③--布尔查询及filter查询原理

一、前言 本节主要学习ES匹配查询中的布尔查询以及布尔查询中比较特殊的filter查询及其原理。 复合搜索&#xff0c;顾名思义是一种在一个搜索语句中包含一种或多种搜索子句的搜索。 布尔查询是常用的复合查询&#xff0c;它把多个子查询组合成一个布尔表达式&#xff0c;这些…...

解决Windows下的docker desktop无法启动问题

以管理员权限运行cmd 报错&#xff1a; docker: error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/create: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows,…...

LLM生成式 AI 项目生命周期Generative AI project lifecycle

在本课程的其余部分中&#xff0c;您将学习开发和部署LLM驱动应用所需的技巧。在这个视频中&#xff0c;您将了解一个能帮助您完成此工作的生成式AI项目生命周期。此框架列出了从构思到启动项目所需的任务。到课程结束时&#xff0c;您应该对您需要做的重要决策、可能遇到的困难…...

java高并发系列 - 第13天:JUC中的Condition对象

java高并发系列 - 第13天:JUC中的Condition对象 java高并发系列第13篇文章 本文内容 synchronized中实现线程等待和唤醒Condition简介及常用方法介绍及相关示例使用Condition实现生产者消费者使用Condition实现同步阻塞队列Object对象中的wait(),notify()方法,用于线程等待…...

【TTY子系统】printf与printk深入驱动解析

tty子系统解析 tty子系统是一个庞大且复杂&#xff0c;也是内核维护者所头大的子系统。 At a first glance, the TTY layer wouldn’t seem like it should be all that challenging. It is, after all, just a simple char device which is charged with transferring byte-o…...

无涯教程-PHP - 全局变量函数

全局变量 与局部变量相反,可以在程序的任何部分访问全局变量。通过将关键字 GLOBAL 放置在应被识别为全局变量的前面,可以很方便地实现这一目标。 <?php$somevar15;function addit() {GLOBAL $somevar;$somevar;print "Somevar is $somevar";}addit(); ?> …...

shell脚本之循环语句

循环语句 循环含义 将某代码段重复运行多次&#xff0c;通常有进入循环的条件和退出循环的条件 for循环语句 一般知道循环次数使用for循环 第一类 格式1&#xff1a; for名称 in 取值次数;do;done; 格式2&#xff1a; for 名称 in {取值列表} do done# 打印20次 for i i…...

派森 #P122. 峰值查找

描述 给定一个长度为n的列表nums&#xff0c;请你找到峰值并返回其索引。数组可能包含多个峰值&#xff0c;在这种情况下&#xff0c;返回任何一个所在位置即可。 &#xff08;1&#xff09;峰值元素是指其值严格大于左右相邻值的元素。严格大于即不能有等于&#xff1b; &…...

基础网络详解4--HTTP CookieSession 思考

一、cookie技术思考 一台多用户浏览器发起了三笔请求&#xff0c;将某款产品放入购物车中&#xff0c;A一次&#xff0c;选择了篮球&#xff1b;B两次&#xff0c;第一次选了足球&#xff0c;第二次选了钢笔。如何确认选择篮球、足球、钢笔的请求属于谁呢&#xff1f;如果不确认…...

14. 利用Canvas自制时钟组件

1. 说明 在自定义时钟组件时&#xff0c;使用到的基本控件主要是Canvas&#xff0c;在绘制相关元素时有两种方式&#xff1a;一种时在同一个canvas中绘制所有的部件元素&#xff0c;这样需要不断的对画笔和画布的属性进行保存和恢复&#xff0c;容易混乱&#xff1b;另一种就是…...

微信小程序使用云存储和Markdown开发页面

最近想在一个小程序里加入一个使用指南的页面&#xff0c;考虑到数据存储和减少页面的开发工作量&#xff0c;决定尝试在云存储里上传Markdown文件&#xff0c;微信小程序端负责解析和渲染。小程序端使用到一个库Towxml。 Towxml Towxml是一个可将HTML、Markdown转为微信小程…...

【C++】运算符重载 | 赋值运算符重载

Ⅰ. 运算符重载 引入 ❓什么叫运算符重载&#xff1f; 就是&#xff1a;运用函数&#xff0c;将现有的运算符重新定义&#xff0c;使其能满足各种自定义类型的运算。 回想一下&#xff0c;我们以前运算的对象是不是都是int、char这种内置类型&#xff1f; 那我们自定义的“…...

Python学习 -- 类对象从创建到常用函数

在Python编程中&#xff0c;类是一种强大的工具&#xff0c;用于创建具有共同属性和行为的对象。本篇博客将详细介绍Python中类和对象的创建&#xff0c;类的属性和方法&#xff0c;以及一些常用的类函数&#xff0c;通过丰富的代码例子来帮助读者深入理解。 一、类和对象的创…...

数组分割(2023省蓝桥杯)n种讨论 JAVA

目录 1、题目描述&#xff1a;2、前言&#xff1a;3、动态规划&#xff08;bug)&#xff1a;3、递归 剪枝&#xff08;超时&#xff09;&#xff1a;4、数学&#xff08;正解&#xff09;&#xff1a; 1、题目描述&#xff1a; 小蓝有一个长度为 N 的数组 A [A0, A1,…, AN−…...

很好的启用window10专业版系统自带的远程桌面

启用window10专业版系统自带的远程桌面 文章目录 启用window10专业版系统自带的远程桌面前言1.找到远程桌面的开关2. 找到“应用”项目3. 打开需要远程操作的电脑远程桌面功能 总结 前言 Windows操作系统作为应用最广泛的个人电脑操作系统&#xff0c;在我们身边几乎随处可见。…...

TCP定制协议,序列化和反序列化

目录 前言 1.理解协议 2.网络版本计算器 2.1设计思路 2.2接口设计 2.3代码实现&#xff1a; 2.4编译测试 总结 前言 在之前的文章中&#xff0c;我们说TCP是面向字节流的&#xff0c;但是可能对于面向字节流这个概念&#xff0c;其实并不理解的&#xff0c;今天我们要介…...

YOLOX在启智AI GPU/CPU平台部署笔记

文章目录 1. 概述2. 部署2.1 拉取YOLOX源码2.2 拉取模型文件yolox_s.pth2.3 安装依赖包2.4 安装yolox2.5 测试运行2.6 运行报错处理2.6.1 ImportError: libGL.so.1: cannot open shared object file: No such file or directory2.6.2 ImportError: libgthread-2.0.so.0: cannot…...

23种设计模式攻关

&#x1f44d;一、创建者模式 &#x1f516;1.1、单例模式 单例模式&#xff08;Singleton Pattern&#xff09;&#xff0c;用于确保一个类只有一个实例&#xff0c;并提供全局访问点。 在某些情况下&#xff0c;我们需要确保一个类只能有一个实例&#xff0c;比如数据库连接…...

【jsthreeJS】入门three,并实现3D汽车展示厅,附带全码

首先放个最终效果图&#xff1a; 三维&#xff08;3D&#xff09;概念&#xff1a; 三维&#xff08;3D&#xff09;是一个描述物体在三个空间坐标轴上的位置和形态的概念。相比于二维&#xff08;2D&#xff09;只有长度和宽度的平面&#xff0c;三维增加了高度或深度这一维度…...

unity将结构体/列表与json字符串相互转化

编写Unity程序时&#xff0c;面对大量需要传输或者保存的数据时&#xff0c;为了避免编写重复的代码&#xff0c;故采用NewtonJson插件来将定义好的结构体以及列表等转为json字符串来进行保存和传输。 具体代码如下&#xff1a; using System; using System.IO; using Newtons…...

【Vue】vue2项目使用swiper轮播图2023年8月21日实战保姆级教程

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、npm 下载swiper二、使用步骤1.引入库声明变量2.编写页面3.执行js 总结 前言 swiper轮播图官网 参考文章&#xff0c;最好先看完他的介绍&#xff0c;再看…...

【算法日志】贪心算法刷题:单调递增数列,贪心算法总结(day32)

代码随想录刷题60Day 目录 前言 单调递增数列 贪心算法总结 前言 今天是贪心算法刷题的最后一天&#xff0c;今天本来是打算刷两道题&#xff0c;其中的一道hard题做了好久都没有做出来(主要思路错了)。然后再总结一下。 单调递增数列 int monotoneIncreasingDigits(int n…...

MATLAB算法实战应用案例精讲-【深度学习】模型压缩

目录 模型压缩概述 1. 为什么需要模型压缩 2. 模型压缩的基本方法 Patient-KD 1. Patient-KD 简介...

Matlab使用

Matlab使用 界面介绍 新建脚本&#xff1a;实际上就是新建一个新建后缀为.m的文件 新建编辑器&#xff1a;ctrlN 打开&#xff1a;打开最近文件&#xff0c;以找到最近写过的文件 点击路径&#xff0c;切换当前文件夹 预设&#xff1a;定制习惯用的界面 常见简单指令 ;…...

BladeX多数据源配置

启用多租户数据库隔离&#xff0c;会默认关闭mybatis-plus多数据源插件的启动&#xff0c;从而使用自定义的数据源识别 若不需要租户数据库隔离只需要字段隔离&#xff0c;而又需要用到多数据源的情况&#xff0c;需要前往LauncherService单独配置 数据源切换失败 详情请看说明…...

go里面关于超时的设计

设想一下你在接收源源不断的数据&#xff0c;如果有700ms没有收到&#xff0c;则认为是一个超时&#xff0c;需要做出处理。 逻辑上可以设计一个grouting,里面放一个通道&#xff0c;每收到一条数据进行相应处理。通道中夹杂一个timer定时器的处理&#xff0c;若通道在700ms内…...

Qt下使用ModbusTcp通信协议进行PLC线圈/保持寄存器的读写(32位有符号数)

文章目录 前言一、引入Modbus模块二、Modbus设备的连接三、各寄存器数据的读取四、各寄存器数据的写入五、示例完整代码总结 前言 本文主要讲述了使用Qt的Modbus模块来进行ModbusTcp的通信&#xff0c;实现对PLC的线圈寄存器和保持寄存器的读写&#xff0c;基于TCP/IP的Modbus…...

ElasticSearch学习2

1、索引的操作 1、创建索引 对ES的操作其实就是发送一个restful请求&#xff0c;kibana中在DevTools中进行ES操作 创建索引时需要注意ES的版本&#xff0c;不同版本的ES创建索引的语句略有差别&#xff0c;会导致失败 如下创建一个名为people的索引&#xff0c;settings&…...

3D角色展示

先看效果&#xff1a; 再看代码&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>3D卡片悬停</title><style>font-face {font-family: "Exoct";src: url("htt…...

前端面试:【Angular】打造强大Web应用的全栈框架

嗨&#xff0c;亲爱的Angular探险家&#xff01;在前端开发的旅程中&#xff0c;有一个全栈框架&#xff0c;那就是Angular。Angular提供了模块化、组件化、依赖注入、路由和RxJS等特性&#xff0c;助力你构建强大、可扩展的Web应用。 1. 什么是Angular&#xff1f; Angular是…...

数据结构:栈和队列

文章目录 一、栈1.栈的概念及结构1.栈的概念及结构2.栈的实现 2.栈的顺序表实现1.栈的结构体和实现的功能函数2.栈的初始化&#xff0c;入栈和出栈操作3.栈的其他操作 3.栈的链表实现1.栈的结构体和实现的功能函数2.栈功能函数的实现 二、队列1.队列的概念及结构1.队列的概念及…...