diff --git a/dsSupport/ConvertMovie/Convert.go b/dsSupport/ConvertMovie/Convert.go index 25781771..adce12c8 100644 --- a/dsSupport/ConvertMovie/Convert.go +++ b/dsSupport/ConvertMovie/Convert.go @@ -5,25 +5,33 @@ import ( ) func main() { + //测试方法: + //(1)在 Firefox中添加m3u8播放组件 + // https://jingyan.baidu.com/article/fdffd1f86f3e7ff3e98ca120.html + //源文件 source := "B7318F5D-46B8-4AA1-8811-1A9D65528E19.wmv" //1、目录实始化 ConvertUtil.InitDir(source) - //2、对视频文件进行切片 + + //2、生成关键帧 + ConvertUtil.ConvertToKeyFrame(source) + + //3、对视频文件进行切片 ConvertUtil.Cut(source) - //3、切片完成后,尝试进行转码 + //4、切片完成后,尝试进行转码 var childMovie = ConvertUtil.GetAllCutChild(source) for i := range childMovie { ConvertUtil.ConvertToH264Mp4(childMovie[i]) } - //4、生成拼接的索引文件 + //5、生成拼接的索引文件 ConvertUtil.GenerateIndexTxt(source, childMovie) - //5、合成MP4 + //6、合成MP4 ConvertUtil.Merge(source) - //6、清除垃圾 + //7、清除垃圾 ConvertUtil.ClearRubbish(source) - //7、查看转换结果 + //8、查看转换结果 ConvertUtil.ShowMovieInfo(source) - //8、转码为M3U8 + //9、转码为M3U8 ConvertUtil.ToM3u8(source) } diff --git a/dsSupport/Utils/ConvertUtil/ConvertUtil.go b/dsSupport/Utils/ConvertUtil/ConvertUtil.go index ac4edffb..1acb0b7e 100644 --- a/dsSupport/Utils/ConvertUtil/ConvertUtil.go +++ b/dsSupport/Utils/ConvertUtil/ConvertUtil.go @@ -26,6 +26,7 @@ func init() { const WorkingPath = "/" const WorkingCutPath = "/Cut/" const WorkingMp4Path = "/Mp4/" +const WorkingKeyFramePath="/KeyFrame/" /** 功能:获取指定源文件的不同工作目录 @@ -64,6 +65,7 @@ func InitDir(source string) { //2、创建新目录 os.MkdirAll(getWorkingPath(source, WorkingCutPath), os.ModePerm) os.Mkdir(getWorkingPath(source, WorkingMp4Path), os.ModePerm) + os.Mkdir(getWorkingPath(source,WorkingKeyFramePath),os.ModePerm) } /** @@ -73,7 +75,7 @@ func InitDir(source string) { */ func Cut(source string) { //1、源视频文件 - sourcePath := getSourcePath(source) + source + sourcePath := getWorkingPath(source,WorkingKeyFramePath) + source //2、获取文件后缀 extension := path.Ext(source) //3、输出的文件通配名称 @@ -186,3 +188,16 @@ func ToM3u8(source string) { //删除mp4 os.Remove(getTargetPath(source)+source[0:36]+".mp4") } + +/** +功能:将文件转换为每帧都是关键帧 +作者:黄海 +时间:2020-07-09 + */ +func ConvertToKeyFrame(source string){ + if FileUtil.Exists(getWorkingPath(source,WorkingKeyFramePath)+source){ + os.Remove(getWorkingPath(source,WorkingKeyFramePath)+source) + } + CommonUtil.Exec(ffmpeg, getWorkingPath(source,WorkingKeyFramePath), `-i`, + getSourcePath(source)+source,`-strict`, `-2`, `-qscale`, `0`,`-intra`, getWorkingPath(source,WorkingKeyFramePath)+source) +} \ No newline at end of file diff --git a/dsSupport/main.go b/dsSupport/main.go index b535b708..fb3046b2 100644 --- a/dsSupport/main.go +++ b/dsSupport/main.go @@ -17,6 +17,7 @@ func main(){ //M3u8目录 // http://127.0.0.1:9000/M3u8/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/B7318F5D-46B8-4AA1-8811-1A9D65528E19.m3u8 r.Static("/M3u8", "./Target") + // 指定地址和端口号 r.Run(":9000") } diff --git a/dsSupport/修改关键帧.txt b/dsSupport/修改关键帧.txt new file mode 100644 index 00000000..373ac768 --- /dev/null +++ b/dsSupport/修改关键帧.txt @@ -0,0 +1 @@ +./ffmpeg/ffmpeg.exe -i E:\Work\dsMin\dsSupport\Source\B7\B7318F5D-46B8-4AA1-8811-1A9D65528E19.wmv -strict -2 -qscale 0 -intra E:\Work\dsMin\dsSupport\Target\B7\B7318F5D-46B8-4AA1-8811-1A9D65528E19.wmv \ No newline at end of file