Init
This commit is contained in:
parent
264c97183e
commit
3faede7b1c
74 changed files with 6228 additions and 1 deletions
23
util/av/audio.go
Normal file
23
util/av/audio.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
)
|
||||
|
||||
func AudioFromVideo(videoPath string, audioPath string) error {
|
||||
err := ffmpeg.
|
||||
Input(videoPath).
|
||||
Output(audioPath, ffmpeg.KwArgs{
|
||||
"map": "a",
|
||||
"vn": nil,
|
||||
"f": "mp3",
|
||||
"ab": "128k",
|
||||
}).
|
||||
Silent(true).
|
||||
OverWriteOutput().
|
||||
Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
46
util/av/merge_audio.go
Normal file
46
util/av/merge_audio.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
)
|
||||
|
||||
func MergeVideoWithAudio(
|
||||
videoFile string,
|
||||
audioFile string,
|
||||
) error {
|
||||
tempFileName := videoFile + ".temp"
|
||||
outputFile := videoFile
|
||||
|
||||
err := os.Rename(videoFile, tempFileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rename file: %w", err)
|
||||
}
|
||||
|
||||
defer os.Remove(tempFileName)
|
||||
defer os.Remove(audioFile)
|
||||
|
||||
videoStream := ffmpeg.Input(tempFileName)
|
||||
audioStream := ffmpeg.Input(audioFile)
|
||||
|
||||
err = ffmpeg.Output(
|
||||
[]*ffmpeg.Stream{videoStream, audioStream},
|
||||
outputFile,
|
||||
ffmpeg.KwArgs{
|
||||
"map": []string{"0:v:0", "1:a:0"},
|
||||
"movflags": "+faststart",
|
||||
"c:v": "copy",
|
||||
"c:a": "copy",
|
||||
}).
|
||||
Silent(true).
|
||||
OverWriteOutput().
|
||||
Run()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to merge files: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
35
util/av/remux.go
Normal file
35
util/av/remux.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
)
|
||||
|
||||
func RemuxFile(
|
||||
inputFile string,
|
||||
) error {
|
||||
tempFileName := inputFile + ".temp"
|
||||
outputFile := inputFile
|
||||
err := os.Rename(inputFile, tempFileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rename file: %v", err)
|
||||
}
|
||||
err = ffmpeg.
|
||||
Input(tempFileName).
|
||||
Output(outputFile, ffmpeg.KwArgs{
|
||||
"c": "copy",
|
||||
}).
|
||||
Silent(true).
|
||||
OverWriteOutput().
|
||||
Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remux file: %v", err)
|
||||
}
|
||||
err = os.Remove(tempFileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove temp file: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
27
util/av/thumbnail.go
Normal file
27
util/av/thumbnail.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
)
|
||||
|
||||
func ExtractVideoThumbnail(
|
||||
videoPath string,
|
||||
thumbnailPath string,
|
||||
) error {
|
||||
err := ffmpeg.
|
||||
Input(videoPath).
|
||||
Output(thumbnailPath, ffmpeg.KwArgs{
|
||||
"vframes": 1,
|
||||
"f": "image2",
|
||||
"ss": "00:00:01",
|
||||
"c:v": "mjpeg",
|
||||
"q:v": 10, // not sure
|
||||
}).
|
||||
Silent(true).
|
||||
OverWriteOutput().
|
||||
Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
18
util/av/videoinfo.go
Normal file
18
util/av/videoinfo.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
"github.com/tidwall/gjson"
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
)
|
||||
|
||||
func GetVideoInfo(filePath string) (int64, int64, int64) {
|
||||
probeData, err := ffmpeg.Probe(filePath)
|
||||
if err != nil {
|
||||
return 0, 0, 0
|
||||
}
|
||||
duration := gjson.Get(probeData, "format.duration").Int()
|
||||
width := gjson.Get(probeData, "streams.0.width").Int()
|
||||
height := gjson.Get(probeData, "streams.0.height").Int()
|
||||
|
||||
return duration, width, height
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue