package com.video.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.video.cofig.AuthService;
import com.video.enums.VideoStatusEnum;
import com.video.pojo.Bgm;
import com.video.pojo.Comments;
import com.video.pojo.Videos;
import com.video.service.BgmService;
import com.video.service.VideoService;
import com.video.utils.*;
import io.swagger.annotations.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.UUID;
@RestController
@Api(value = "视频相关业务的接口", tags = {"视频相关业务的controller"})
@RequestMapping("/video")
public class VideoController extends BasicController {
@Autowired
private RestTemplate restTemplate;
@Resource
private BgmService bgmService;
@Resource
private VideoService videoService;
@ApiOperation(value = "上传视频", notes = "上传视频的接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", required = true,
dataType = "String", paramType = "form"),
@ApiImplicitParam(name = "bgmId", value = "背景音乐id", required = false,
dataType = "String", paramType = "form"),
@ApiImplicitParam(name = "videoSeconds", value = "背景音乐播放长度", required = true,
dataType = "String", paramType = "form"),
@ApiImplicitParam(name = "videoWidth", value = "视频宽度", required = true,
dataType = "String", paramType = "form"),
@ApiImplicitParam(name = "videoHeight", value = "视频高度", required = true,
dataType = "String", paramType = "form"),
@ApiImplicitParam(name = "desc", value = "视频描述", required = false,
dataType = "String", paramType = "form")
})
@PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
public KJSONResult upload(String userId,
String bgmId, double videoSeconds,
int videoWidth, int videoHeight,
String desc,
@ApiParam(value = "短视频", required = true)
MultipartFile file) throws Exception {
if (StringUtils.isBlank(userId)) {
return KJSONResult.errorMsg("用户id不能为空...");
}
// 文件保存的命名空间
// 保存到数据库中的相对路径
String uploadPathDB = "/" + userId + "/video";
String coverPathDB = "/" + userId + "/video";
FileOutputStream fileOutputStream = null;
InputStream inputStream = null;
// 文件上传的最终保存路径
String finalVideoPath = "";
try {
if (file != null) {
String fileName = file.getOriginalFilename();
// abc.mp4
String arrayFilenameItem[] = fileName.split("\\.");
String fileNamePrefix = "";
for (int i = 0; i < arrayFilenameItem.length - 1; i++) {
fileNamePrefix += arrayFilenameItem[i];
}
// fix bug: 解决小程序端OK,PC端不OK的bug,原因:PC端和小程序端对临时视频的命名不同
// String fileNamePrefix = fileName.split("\\.")[0];
if (StringUtils.isNotBlank(fileName)) {
finalVideoPath = FILE_SPACE + uploadPathDB + "/" + fileName;
// 设置数据库保存的路径
uploadPathDB += ("/" + fileName);
coverPathDB = coverPathDB + "/" + fileNamePrefix + ".jpg";
File outFile = new File(finalVideoPath);
if (outFile.getParentFile() != null || !outFile.getParentFile().isDirectory()) {
// 创建父文件夹
outFile.getParentFile().mkdirs();
}
fileOutputStream = new FileOutputStream(outFile);
inputStream = file.getInputStream();
IOUtils.copy(inputStream, fileOutputStream);
}
} else {
return KJSONResult.errorMsg("上传出错...");
}
} catch (Exception e) {
e.printStackTrace();
return KJSONResult.errorMsg("上传出错...");
} finally {
if (fileOutputStream != null) {
fileOutputStream.flush();
fileOutputStream.close();
}
}
// 判断bgmId是否为空,如果不为空,
// 那就查询bgm的信息,并且合并视频,生产新的视频
if (StringUtils.isNotBlank(bgmId)) {
Bgm bgm = bgmService.queryBgmById(bgmId);
String mp3InputPath = FILE_SPACE + bgm.getPath();
MergeVideoMp3 tool = new MergeVideoMp3(FFMPEG_EXE);
outMusic om = new outMusic(FFMPEG_EXE);
String videoInputPath = finalVideoPath;
String videoOutputName = UUID.randomUUID().toString() + ".mp4";
String videoMusicOutName = UUID.randomUUID().toString() + ".mp4";
uploadPathDB = "/" + userId + "/video" + "/" + videoOutputName;
String outMusicName = "/" + userId + "/video" + "/" + videoMusicOutName;
finalVideoPath = FILE_SPACE + uploadPathDB;
String outMusic1 = FILE_SPACE + outMusicName;
om.convertor(videoInputPath,outMusic1);
tool.convertor(outMusic1, mp3InputPath, videoSeconds, finalVideoPath);
}
System.out.println("uploadPathDB=" + uploadPathDB);
System.out.println("finalVideoPath=" + finalVideoPath);
// 对视频进行截图
FetchVideoCover videoInfo = new FetchVideoCover(FFMPEG_EXE);
videoInfo.getCover(finalVideoPath, FILE_SPACE + coverPathDB);
// 保存视频信息到数据库
Videos video = new Videos();
video.setAudioId(bgmId);
video.setUserId(userId);
video.setVideoSeconds((float) videoSeconds);
video.setVideoHeight(videoHeight);
video.setVideoWidth(videoWidth);
video.setVideoDesc(desc);
video.setVideoPath(uploadPathDB);
video.setCoverPath(coverPathDB);
video.setStatus(VideoStatusEnum.SUCCESS.value);
video.setCreateTime(new Date());
String videoId = videoService.saveVideo(video);
return KJSONResult.ok(videoId);
}
@ApiOperation(value = "上传封面", notes = "上传封面的接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", required = true,
dataType = "String", paramType = "form"),
@ApiImplicitParam(name = "videoId", value = "视频主键id", required = true,
dataType = "String", paramType = "form")
})
@PostMapping(value = "/uploadCover", headers = "content-type=multipart/form-data")
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
如果您下载了本程序,但是该程序存在问题无法运行,那么您可以选择退款或者寻求我们的帮助(如果找我们帮助的话,是需要追加额外费用的)。另外,您不会使用资源的话(这种情况不支持退款),也可以找我们帮助(需要追加额外费用) 随着移动互联网技术的发展和用户需求的变化,【小程序名称】应运而生,以其轻量化、便捷化的设计理念为用户提供了一种全新的服务模式。作为一款无需下载安装即可使用的应用,【小程序名称】依托于微信庞大的生态系统,让用户在微信内就能轻松实现各种功能操作。 【小程序名称】的核心功能主要集中在【具体服务领域】,例如在线购物、本地生活服务、教育学习或健康管理等。它简化了传统APP繁琐的注册登录流程,支持微信一键授权登录,极大地提升了用户体验。用户通过搜索或扫描二维码,瞬间即可开启使用,享受快速加载、流畅运行的服务。 该小程序界面设计简洁明了,布局合理,易于上手。同时,其特色功能如实时更新的信息推送、个性化推荐以及社交分享功能,让用户能够及时获取所需信息,并方便地将优质内容分享至朋友圈或好友,实现信息的高效传播与互动。 【小程序名称】注重数据安全与隐私保护,严格遵守国家法律法规和微信平台的规定,确保用户数据的安全无虞。此外,其背后的开发团队持续迭代更新,根据用户反馈不断优化产品性能,提升服务质量,致力于打造一个贴近用户需求、充满活力的小程序生态。 总结来说,【小程序名称】凭借其小巧便携、快捷高效的特性,不仅节省了用户的手机存储空间,更为用户提供了无缝衔接的便利服务,是现代生活中不可或缺的一部分,真正实现了“触手可及”的智能生活新体验。只需轻点屏幕,无限精彩尽在掌握之中。
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序短视频社交系统后端.zip (407个子文件)
VideoController.class 13KB
VideoServiceImpl.class 7KB
UserCF.class 7KB
DefaultWorkerIdStrategy.class 7KB
UserController.class 6KB
DefaultRandomCodeStrategy.class 6KB
UserServiceImpl.class 5KB
HttpReq.class 5KB
Utils.class 5KB
RegistLoginController.class 5KB
RedisOperator.class 4KB
ZKCuratorClient$1.class 4KB
MiniInterceptor.class 4KB
FileLock.class 4KB
Serializes.class 4KB
Swagger2.class 4KB
MasterDataSourceConfiguration.class 3KB
Props.class 3KB
MergeVideoMp3.class 3KB
ZKCuratorClient.class 3KB
SpringRestTemplateController.class 3KB
AuthService.class 3KB
IdWorker.class 3KB
KJSONResult.class 3KB
WebMvcConfig.class 3KB
outMusic.class 3KB
FetchVideoCover.class 3KB
TimeAgoUtils.class 2KB
JsonUtils.class 2KB
FFMpegTest.class 2KB
UserCRUDServiceImpl.class 2KB
Sid.class 2KB
UserCRUDController.class 2KB
Ip.class 2KB
BGMOperatorTypeEnum.class 2KB
DayPrefixRandomCodeStrategy.class 2KB
IPv4Utils.class 2KB
ResourceConfig.class 1KB
PagedResult.class 1KB
RestTemplateConfig.class 1KB
BgmServiceImpl.class 1KB
Code.class 1KB
BgmController.class 1KB
DayCode.class 1KB
VideoStatusEnum.class 1KB
Props$Silent.class 1KB
Id.class 1004B
VideosCustomMapper.class 934B
Application.class 929B
BasicController.class 914B
MD5Utils.class 861B
VideoService.class 830B
DefaultWorkerIdStrategy$1.class 793B
DefaultRandomCodeStrategy$1.class 718B
DefaultWorkerIdStrategy$2.class 697B
UserService.class 684B
VideosApiApplicationTests.class 647B
HelloWorldController.class 636B
VideosServiceApplicationTests.class 635B
Sid$1.class 541B
MyMapper.class 518B
UsersMapper.class 515B
CommentsCustomMapper.class 487B
SearchRecordsMapper.class 440B
InvalidSystemClock.class 371B
UsersLikeVideosMapper.class 354B
UsersReportMapper.class 342B
UsersFansMapper.class 336B
CommentsMapper.class 333B
VideosMapper.class 327B
BgmMapper.class 318B
BgmService.class 292B
Test.class 255B
UserCRUDService.class 245B
RandomCodeStrategy.class 203B
WorkerIdStrategy.class 201B
mvnw.cmd 6KB
mvnw.cmd 6KB
.DS_Store 10KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.gitignore 303B
.gitignore 269B
videos-api.iml 15KB
videos-service.iml 13KB
videos-common.iml 13KB
WchatVideo-dev.iml 1KB
maven-wrapper.jar 47KB
maven-wrapper.jar 47KB
maven-wrapper.jar 47KB
maven-wrapper.jar 47KB
VideoController.java 14KB
UserCF.java 10KB
VideoServiceImpl.java 6KB
DefaultWorkerIdStrategy.java 6KB
Videos.java 6KB
UserController.java 5KB
VideosVO.java 5KB
DefaultRandomCodeStrategy.java 5KB
共 407 条
- 1
- 2
- 3
- 4
- 5
资源评论
JJJ69
- 粉丝: 6235
- 资源: 5778
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功