├── LICENSE ├── README.md ├── data ├── FlipBook.gif ├── IronManCut1.mp4 ├── OriginalVid.gif └── flipBook_Test.avi └── src ├── VideoProcessing.go └── makeCartoon.go /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Vishal Rao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoFlip 2 | 3 | Convert videos into Flip-Book like versions of themselves. The gocv library is used for all the processing. 4 | Save your video in ```./data``` folder and run the following command. 5 | 6 | ``` 7 | go run *.go 8 | ``` 9 | 10 | ### Original Video 11 | 12 | 13 | ### Resulting Video 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /data/FlipBook.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kadle11/GoFlip/7e2ed9fc9167559afa26b54c6c77347493ce1bac/data/FlipBook.gif -------------------------------------------------------------------------------- /data/IronManCut1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kadle11/GoFlip/7e2ed9fc9167559afa26b54c6c77347493ce1bac/data/IronManCut1.mp4 -------------------------------------------------------------------------------- /data/OriginalVid.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kadle11/GoFlip/7e2ed9fc9167559afa26b54c6c77347493ce1bac/data/OriginalVid.gif -------------------------------------------------------------------------------- /data/flipBook_Test.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kadle11/GoFlip/7e2ed9fc9167559afa26b54c6c77347493ce1bac/data/flipBook_Test.avi -------------------------------------------------------------------------------- /src/VideoProcessing.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "gocv.io/x/gocv" 7 | ) 8 | 9 | func getVideoFrames(srcPath string) ([]gocv.Mat, int, int) { 10 | 11 | /*Initialization*/ 12 | srcVideo, err := gocv.OpenVideoCapture(srcPath) 13 | var allFrames []gocv.Mat 14 | if err != nil { 15 | log.Panic("Error opening Video File: %v\n", srcVideo) 16 | return allFrames, 0, 0 17 | } 18 | defer srcVideo.Close() 19 | 20 | /*Get Dimensions*/ 21 | frameWidth := int(srcVideo.Get(gocv.VideoCaptureFrameWidth)) 22 | frameHeight := int(srcVideo.Get(gocv.VideoCaptureFrameHeight)) 23 | 24 | /*Sample Frames*/ 25 | SamplingRate := 5 26 | frame := gocv.NewMat() 27 | x := 0 28 | for { 29 | if ok := srcVideo.Read(&frame); !ok { 30 | log.Println("Cannot Read Video: ", srcPath) 31 | break 32 | } 33 | 34 | if frame.Empty() { 35 | log.Println("No Image Found") 36 | break 37 | } 38 | if x % SamplingRate == 0 { 39 | allFrames = append(allFrames, frame) 40 | frame = gocv.NewMat() 41 | } 42 | x++ 43 | } 44 | log.Println(x, "Frames Sampled") 45 | return allFrames, frameWidth, frameHeight 46 | } 47 | 48 | func makeFlipBook(allFrames []gocv.Mat, frameWidth int, frameHeight int, fps float64, dstPath string) { 49 | 50 | 51 | flipBook, err := gocv.VideoWriterFile(dstPath, "X264", fps, frameWidth, frameHeight, true) 52 | if err != nil { 53 | log.Panic("Can not open video writer") 54 | return 55 | } 56 | defer flipBook.Close() 57 | 58 | for i:=0; i