Small improvements
This commit is contained in:
parent
4fe9ccbab5
commit
b339c385f4
4 changed files with 21 additions and 12 deletions
|
@ -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
|
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
|
# Running with nix
|
||||||
```
|
```
|
||||||
nix run git+https://git.catnip.ee/miisu/clip-maker -- --filename 'Video.mp4'
|
nix run git+https://git.catnip.ee/miisu/clip-maker -- --filename 'Video.mp4'
|
||||||
|
|
|
@ -8,4 +8,12 @@
|
||||||
"-s"
|
"-s"
|
||||||
"-w"
|
"-w"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
makeWrapper
|
||||||
|
];
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
wrapProgram $out/bin/clip-maker --prefix PATH : ${lib.makeBinPath [ pkgs.ffmpeg ]}
|
||||||
|
'';
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@
|
||||||
devShells.default = mkShell rec {
|
devShells.default = mkShell rec {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
go
|
go
|
||||||
|
ffmpeg
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
packages.default = pkgs.callPackage ./build.nix { };
|
packages.default = pkgs.callPackage ./build.nix { };
|
||||||
|
|
20
main.go
20
main.go
|
@ -11,15 +11,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetVideoLength(fileName string) (seconds int, err error) {
|
func GetVideoLength(ffprobeLocation string, fileName string) (seconds int, err error) {
|
||||||
// var path string
|
|
||||||
// path, err = filepath.Abs(fileName)
|
|
||||||
// if err != nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
var out []byte
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -40,30 +34,32 @@ func ProcessFileName(filename string) string {
|
||||||
}
|
}
|
||||||
func main() {
|
func main() {
|
||||||
filename := flag.String("filename", "", "video to make clips of")
|
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")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
if *filename == "" {
|
if *filename == "" {
|
||||||
log.Fatalln("Please insert video to make clips of")
|
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 {
|
if err := os.MkdirAll(*clips_folder, 0777); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
length, err := GetVideoLength(*filename)
|
length, err := GetVideoLength(*ffprobeLocation, *filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for start := 0; start <= length; start += *clip_length {
|
for start := 0; start <= length; start += *clip_length {
|
||||||
fmt.Printf("Creating clip for seconds %d to %d\n", start, 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 {
|
if err != nil {
|
||||||
fmt.Print(string(out))
|
fmt.Print(string(out))
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue