Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56352
  • 博文数量: 22
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 232
  • 用 户 组: 普通用户
  • 注册时间: 2020-11-30 14:45
个人简介

专注流媒体、视频物联网、云计算、大数据开发

文章分类

全部博文(22)

文章存档

2021年(18)

2020年(4)

我的朋友

分类: 系统运维

2021-09-09 10:40:57

大家知道很多视频点播平台都是具备倍速播放功能的,在我们EasyDSS平台中,也有项目团队提出需求,需要根据用户参数可自行修改视频播放速度。

对于该需求的实现,我们首先要根据请求的视频倍数,重新生成hash文件名,否则会出现文件名覆盖的情况。其次,在生成源视频文件后制作一个元素率的视频备份。最后将源文件删除,将备份文件作为源,生成源文件名的加速文件。

部分参考代码如下:

点击(此处)折叠或打开

  1. func CreateSpeedFile(path, input string, speed float32) string {
  2.     var shellFile string
  3.     switch runtime.GOOS {
  4.     case "windows":
  5.         shellFile = "change_speed.bat"
  6.         f, _ := os.Create(shellFile)
  7.         inputPath := filepath.Join(path, fmt.Sprintf("%s", input))
  8.         outPath := filepath.Join(path, "temp.mp4")
  9.         f.Write([]byte(fmt.Sprintf("copy %s %s\n", inputPath, outPath)))
  10.         f.Write([]byte(fmt.Sprintf("del %s\n", inputPath)))
  11.         f.Write([]byte(fmt.Sprintf("%s -i %s", EasyTrans(), outPath)))
  12.         f.Write([]byte(fmt.Sprintf(" -filter_complex \"[0:v]setpts=%f*PTS[v];[0:a]atempo=%f[a]\"", 1/speed, speed)))
  13.         f.Write([]byte(fmt.Sprintf(" -map \"[v]\" -map \"[a]\" %s\n", inputPath)))
  14.         f.Write([]byte(fmt.Sprintf("del %s\n", outPath)))
  15.         f.Close()
  16.     case "linux":
  17.         inputPath := estring.FormatPath(filepath.Join(path, fmt.Sprintf("%s", input)))
  18.         outPath := estring.FormatPath(filepath.Join(path, "temp.mp4"))
  19.         cmd := exec.Command("/bin/bash","-c",fmt.Sprintf("cp %s %s\n", inputPath, outPath))
  20.         err := cmd.Run()
  21.         if err!=nil{
  22.             return ""
  23.         }
  24.         cmd = exec.Command("/bin/bash","-c",fmt.Sprintf("rm %s\n", inputPath))
  25.         err = cmd.Run()
  26.         if err!=nil{
  27.             return ""
  28.         }
  29.         sh := fmt.Sprintf("%s -i %s -filter_complex \"[0:v]setpts=%f*PTS[v];[0:a]atempo=%f[a]\" -map \"[v]\" -map \"[a]\" %s\n",EasyTrans(), outPath, 1/speed, speed,inputPath)
  30.         cmd = exec.Command("/bin/bash","-c",sh)
  31.         err = cmd.Run()
  32.         if err!=nil{
  33.             return ""
  34.         }
  35.         cmd = exec.Command("/bin/bash","-c",fmt.Sprintf("rm %s\n", outPath))
  36.         err = cmd.Run()
  37.         if err!=nil{
  38.             return ""
  39.         }
  40.     }
  41.     return shellFile
  42. }
EasyDSS开发简单,我们给客户提供了编程语言无关化的RESTfulAPI接口,可以很简单的进行二次开发和应用,并且各模块间无缝对接,亦可将EasyDSS流媒体服务器软件与其他第三方平台对接,组合灵活自由,这也是众多用户选择我们的重要原因之一。

阅读(468) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~