giffer

Create .gif images from sites like youtube.com
Log | Files | Refs | LICENSE

commit 8b556d15a6f24894ccc586fd17e2600e0deae84c
parent 6fa7cf6583645da70740ef160dbf12e68360d089
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Wed,  7 Nov 2018 12:02:55 +1300

[~] Moved FPS to method instead of struct field.

The FPS to use is Video dependant and therefore should be specified
as a method parameter.

Diffstat:
Mcmd/cli/main.go | 3+--
Mffmpeg.go | 9++++-----
2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/cmd/cli/main.go b/cmd/cli/main.go @@ -47,10 +47,9 @@ func main() { } ffmpeg := giffer.FFMpeg{ Dir: "./tmp/ffmpeg", - FPS: fps, LeaveMess: true, } - frames, err := ffmpeg.Extract(videofile, start, end) + frames, err := ffmpeg.Extract(videofile, start, end, fps) if err != nil { log.Fatalf("extracting frames: %v", err) } diff --git a/ffmpeg.go b/ffmpeg.go @@ -15,12 +15,11 @@ import ( // FFMpeg wraps the ffmpeg binary. type FFMpeg struct { Dir string - FPS float64 LeaveMess bool } // Extract the frames between start and end from the video file. -func (f FFMpeg) Extract(video string, start, end float64) ([]image.Image, error) { +func (f FFMpeg) Extract(video string, start, end, fps float64) ([]image.Image, error) { os.RemoveAll(f.Dir) if !f.LeaveMess { defer os.RemoveAll(f.Dir) @@ -33,13 +32,13 @@ func (f FFMpeg) Extract(video string, start, end float64) ([]image.Image, error) if err != nil { return nil, errors.Wrap(err, "cutting video file") } - if f.FPS == 0 { - f.FPS = 24.0 + if fps == 0 { + fps = 24.4 } // ffmpeg -i file.mp4 -r 1/1 $filename%03d.jpg if err := f.run( "-i", cut, - "-vf", fmt.Sprintf("fps=%2f", f.FPS), + "-vf", fmt.Sprintf("fps=%2f", fps), filepath.Join(f.Dir, "frames", "$frame%03d.jpg"), ); err != nil { return nil, errors.Wrap(err, "extracting frames")