Changed clip_length to accept time.Duration
This commit is contained in:
parent
b339c385f4
commit
d8b8ed6b60
2 changed files with 18 additions and 5 deletions
|
@ -3,7 +3,7 @@
|
|||
Simple program to split video file into clips of requested length
|
||||
|
||||
```
|
||||
go run . --filename 'Family Guy - S01E01 - Death Has a Shadow SDTV.mkv' --clip_length 5
|
||||
go run . --filename 'Family Guy - S01E01 - Death Has a Shadow SDTV.mkv' --clip_length 5s
|
||||
```
|
||||
|
||||
# Dependencies
|
||||
|
|
21
main.go
21
main.go
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetVideoLength(ffprobeLocation string, fileName string) (seconds int, err error) {
|
||||
|
@ -34,12 +35,24 @@ func ProcessFileName(filename string) string {
|
|||
}
|
||||
func main() {
|
||||
filename := flag.String("filename", "", "video to make clips of")
|
||||
clip_length := flag.Int("clip_length", 2, "how many seconds long each clip should be")
|
||||
raw_clip_length := flag.String("clip_length", "2s", "how many seconds long each clip should be")
|
||||
clips_folder := flag.String("clips_folder", "clips", "folder to store clips in")
|
||||
ffmpegLocation := flag.String("ffmpeg", "ffmpeg", "specify ffmpeg location if its not in path")
|
||||
ffprobeLocation := flag.String("ffprobe", "ffprobe", "specify ffprobe location if its not in path")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
clip_lenght_f, err := time.ParseDuration(*raw_clip_length)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
clip_length := int(clip_lenght_f.Seconds())
|
||||
|
||||
if clip_length < 1 {
|
||||
log.Fatal("Please choose length longer than a second")
|
||||
}
|
||||
|
||||
if *filename == "" {
|
||||
log.Fatalln("Please insert video to make clips of")
|
||||
}
|
||||
|
@ -54,9 +67,9 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for start := 0; start <= length; start += *clip_length {
|
||||
fmt.Printf("Creating clip for seconds %d to %d\n", start, start+*clip_length)
|
||||
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("%s -ss %d -i \"%s\" -c copy -t %d \"%s/%s seconds %d to %d.mp4\"", *ffmpegLocation, start, *filename, clip_length, *clips_folder, ProcessFileName(*filename), start, start+*clip_length)).CombinedOutput()
|
||||
for start := 0; start <= length; start += clip_length {
|
||||
fmt.Printf("Creating clip for seconds %d to %d\n", start, start+clip_length)
|
||||
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("%s -ss %d -i \"%s\" -c copy -t %d \"%s/%s seconds %d to %d.mp4\"", *ffmpegLocation, start, *filename, clip_length, *clips_folder, ProcessFileName(*filename), start, start+clip_length)).CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Print(string(out))
|
||||
log.Fatal(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue