zoukankan      html  css  js  c++  java
  • EasyDSS开发视频点播倍速播放的过程(附部分代码)

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

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

    部分参考代码如下:

    func CreateSpeedFile(path, input string, speed float32) string {
    	var shellFile string
    	switch runtime.GOOS {
    	case "windows":
    		shellFile = "change_speed.bat"
    		f, _ := os.Create(shellFile)
    		inputPath := filepath.Join(path, fmt.Sprintf("%s", input))
    		outPath := filepath.Join(path, "temp.mp4")
    		f.Write([]byte(fmt.Sprintf("copy %s %s
    ", inputPath, outPath)))
    		f.Write([]byte(fmt.Sprintf("del %s
    ", inputPath)))
    		f.Write([]byte(fmt.Sprintf("%s -i %s", EasyTrans(), outPath)))
    		f.Write([]byte(fmt.Sprintf(" -filter_complex "[0:v]setpts=%f*PTS[v];[0:a]atempo=%f[a]"", 1/speed, speed)))
    		f.Write([]byte(fmt.Sprintf(" -map "[v]" -map "[a]" %s
    ", inputPath)))
    		f.Write([]byte(fmt.Sprintf("del %s
    ", outPath)))
    		f.Close()
    	case "linux":
    		inputPath := estring.FormatPath(filepath.Join(path, fmt.Sprintf("%s", input)))
    		outPath := estring.FormatPath(filepath.Join(path, "temp.mp4"))
    		cmd := exec.Command("/bin/bash","-c",fmt.Sprintf("cp %s %s
    ", inputPath, outPath))
    		err := cmd.Run()
    		if err!=nil{
    			return ""
    		}
    		cmd = exec.Command("/bin/bash","-c",fmt.Sprintf("rm %s
    ", inputPath))
    		err = cmd.Run()
    		if err!=nil{
    			return ""
    		}
    		sh := fmt.Sprintf("%s -i %s -filter_complex "[0:v]setpts=%f*PTS[v];[0:a]atempo=%f[a]" -map "[v]" -map "[a]" %s
    ",EasyTrans(), outPath, 1/speed, speed,inputPath)
    		cmd = exec.Command("/bin/bash","-c",sh)
    		err = cmd.Run()
    		if err!=nil{
    			return ""
    		}
    		cmd = exec.Command("/bin/bash","-c",fmt.Sprintf("rm %s
    ", outPath))
    		err = cmd.Run()
    		if err!=nil{
    			return ""
    		}
    	}
    	return shellFile
    }

    EasyDSS开发简单,我们给客户提供了编程语言无关化的RESTfulAPI接口,可以很简单的进行二次开发和应用,并且各模块间无缝对接,亦可将EasyDSS流媒体服务器软件与其他第三方平台对接,组合灵活自由,这也是众多用户选择我们的重要原因之一。

  • 相关阅读:
    shell基础知识8-xargs命令
    shell基础知识7-字段分隔符与迭代器
    shell基础知识6-在不按回车键的情况下读入N个字符
    DevOps
    DevOps
    Jenkins
    Jenkins
    Jenkins
    Jenkins
    Gerrit
  • 原文地址:https://www.cnblogs.com/easydss/p/15268564.html
Copyright © 2011-2022 走看看