diff --git a/README.md b/README.md index 0e56050..dae0712 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ 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 ``` +# Dependencies + +This program relies on ffmpeg so make sure to install it + # Running with nix ``` nix run git+https://git.catnip.ee/miisu/clip-maker -- --filename 'Video.mp4' diff --git a/build.nix b/build.nix index eab3844..345fa9a 100644 --- a/build.nix +++ b/build.nix @@ -8,4 +8,12 @@ "-s" "-w" ]; + + nativeBuildInputs = with pkgs; [ + makeWrapper + ]; + + postInstall = '' + wrapProgram $out/bin/clip-maker --prefix PATH : ${lib.makeBinPath [ pkgs.ffmpeg ]} + ''; } \ No newline at end of file diff --git a/flake.nix b/flake.nix index 59dd31d..ff37604 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,7 @@ devShells.default = mkShell rec { buildInputs = with pkgs; [ go + ffmpeg ]; }; packages.default = pkgs.callPackage ./build.nix { }; diff --git a/main.go b/main.go index 90813d5..0e8912e 100644 --- a/main.go +++ b/main.go @@ -11,15 +11,9 @@ import ( "strings" ) -func GetVideoLength(fileName string) (seconds int, err error) { - // var path string - // path, err = filepath.Abs(fileName) - // if err != nil { - // return - // } - +func GetVideoLength(ffprobeLocation string, fileName string) (seconds int, err error) { var out []byte - out, err = exec.Command("/bin/sh", "-c", fmt.Sprintf("ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 \"%s\"", fileName)).CombinedOutput() + out, err = exec.Command("/bin/sh", "-c", fmt.Sprintf("%s -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 \"%s\"", ffprobeLocation, fileName)).CombinedOutput() if err != nil { return } @@ -40,30 +34,32 @@ func ProcessFileName(filename string) string { } func main() { filename := flag.String("filename", "", "video to make clips of") - clip_length := flag.Int("clip_length", 2, "how long each clip should be") + clip_length := flag.Int("clip_length", 2, "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() if *filename == "" { log.Fatalln("Please insert video to make clips of") } + fmt.Println("Creating clips folder:", *clips_folder) if err := os.MkdirAll(*clips_folder, 0777); err != nil { log.Fatal(err) } - length, err := GetVideoLength(*filename) + length, err := GetVideoLength(*ffprobeLocation, *filename) if err != nil { 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("ffmpeg -ss %d -i \"%s\" -c copy -t %d \"%s/%s seconds %d to %d.mp4\"", start, *filename, clip_length, *clips_folder, ProcessFileName(*filename), start, start+*clip_length)).CombinedOutput() + 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) } } - }