current position:Home>Optimization of MP4 file missing seconds caused by TS files when downloading videos from easydss video platform

Optimization of MP4 file missing seconds caused by TS files when downloading videos from easydss video platform

2022-06-24 12:43:23Tsingsee green rhino video

EasyDSS The video platform supports video downloading , A copy of the downloaded video file will be kept ts file , At the same time mp4 The format of is saved in the video folder . Under some custom projects ,EasyDSS After downloading the video of MP4 File missing seconds . Although we have dealt with similar problems before , But the reasons for this problem are different .

The problem is actually related to the video file ts Related documents , When the system downloads mp4 When you file , The backend first queries the corresponding ts file , And because the EasyDSS The query for is not complete , Only then causes the user to download MP4 The file is incomplete .

To solve such problems , We change the logic of the system to synthesize according to the downloaded parameters m3u8 file , Use it again m3u8 File transfer mp4 file , The reference codes are as follows :

    // Generate m3u8
    //m3u8TS, err := r.getRecordM3U8File(id, start, end, videoID, true)
    _,fileRealPath_m3u8, err:=service.GeneterateRecordM3u8(id,starttime, endtime,true)
    if err != nil {
        AbortWithString(c, http.StatusBadRequest, " Generate M3U8 error ")
    //m3u8 turn MP4
    //mp4_name := id+"_"+starttime+"_"+starttime+".mp4"
    filePath_mp4 := trans.M3U8ToMP4_TimeName(fileRealPath_m3u8,mp4Path)
    if filePath_mp4 == "" {
        AbortWithString(c, http.StatusBadRequest, "M3U8 turn MP4 Failure ")
    r.operFile(c, operate, filePath_mp4, videoID)

The composite will be deleted finally m3u8 file ,mp4 Regular file cleaning , The code to free unnecessary disk space is as follows :

After the solution, the complete can be downloaded successfully mp4 file :

copyright notice
author[Tsingsee green rhino video],Please bring the original link to reprint, thank you.

Random recommended