moviego

package module
v0.0.0-...-948ef43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 9 Imported by: 0

README

📽 MovieGo - Video Editing in Golang

MovieGo is a Golang library for video editing. The library is designed for fast processing of routine tasks related to video editing. The main core of the project is the ffmpeg-go package, which simplifies working with the ffmpeg library.

⬇️ Instalation

go get github.com/mowshon/moviego

🎥 Resize video in Golang

Currently there are three methods in the package that help you resize the video:

  • ResizeByWidth( new width )
  • ResizeByHeight( new height )
  • Resize( new width, new height )
package main

import (
    "github.com/mowshon/moviego"
)

func main() {
    first, _ := moviego.Load("forest.mp4")

    first.ResizeByWidth(500).Output("resized-by-width.mp4").Run()
    first.ResizeByWidth(150).Output("resized-by-height.mp4").Run()
    first.Resize(1000, 500).Output("resized.mp4").Run()
}

These commands in ffmpeg:

ffmpeg -i forest.mp4 -vf scale=500:210 resized-by-width.mp4 -y
ffmpeg -i forest.mp4 -vf scale=150:62 resized-by-height.mp4 -y
ffmpeg -i forest.mp4 -vf scale=1000:500 resized.mp4 -y

🎥 Cut video in Golang

The Video structure has a SubClip method which can trim the video by specifying the beginning and end of the video segment.

package main

import (
    "github.com/mowshon/moviego"
    "log"
)

func main() {
    first, _ := moviego.Load("forest.mp4")

    // Cut video from second 3 to second 5.
    err := first.SubClip(3, 5).Output("final.mp4").Run()
    if err != nil {
        log.Fatal(err)
    }
}

🎥 Combine multiple videos into one in Golang

Having several videos you can combine them into one. You can apply different effects to video clips from a slice at the same time.

func main() {
    first, _ := moviego.Load("forest.mp4")
    second, _ := moviego.Load("sky.mp4")

    // Combine multiple videos into one.
    finalVideo, err := moviego.Concat([]moviego.Video{
        first,
        second,
        first.SubClip(1, 3),
        second.SubClip(5.3, 10.5),
        first.FadeIn(0, 5).FadeOut(5),
    })

    if err != nil {
        log.Fatal(err)
    }

    renderErr := finalVideo.Output("final.mp4").Run()
    if err != nil {
        log.Fatal(renderErr)
    }
}

🎥 Add a fade-in or fade-out transition for Video and Audio

Here we have 4 methods for working with Fade effects. Two for video and two for audio tracks from the video.

  • .FadeIn(start, duration) - The video fade-in from the beginning (the screen is black) to the specified time interval.
  • .FadeOut(seconds before the end) - Fading video into a completely black screen. You need to specify in seconds from the end of the video when to start fading.
  • .AudioFadeIn(start, duration) - If you want the audio track to be completely muted at the beginning, you can specify the beginning at 0.5 seconds.
  • .AudioFadeOut(seconds before the end) - The audio track will fade out at the end depending on the specified interval in seconds to the end of the video.
func main() {
    first, _ := moviego.Load("forest.mp4")

    // Add fade-in and fade-out
    first.FadeIn(0, 3).FadeOut(5).Output("fade-in-with-fade-out.mp4").Run()

    // Cut video and add Fade-in
    first.SubClip(5.20, 10).FadeIn(0, 3).Output("cut-fade-in.mp4").Run()

    // Mute the sound for the first 0.5 seconds and then
    // turn the sound on with the fade in.
    first.AudioFadeIn(0.5, 4).Output("audio-fade-in.mp4").Run()

    // Add video fade-out with audio fade-out.
    first.FadeOut(5).AudioFadeOut(5).Output("fade-out.mp4").Run()
}

🖼️ Screenshot - Saving a Frame of Video Clip in Golang

You can make a screenshot by specifying the desired time from the video in seconds.

func main() {
    first, _ := moviego.Load("forest.mp4")

    // A simple screenshot from the video.
    first.Screenshot(5, "simple-screen.png")

    // Take a screenshot after applying the effects.
    first.FadeIn(0, 3).FadeOut(5).Screenshot(0.4, "screen.png")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InArray

func InArray[T Ordered](needle T, haystack []T) bool

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M) []K

Types

type Ordered

type Ordered interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64 | string
}

type Output

type Output struct {
	// contains filtered or unexported fields
}

func (Output) Run

func (OutputProcess Output) Run() error

type Video

type Video struct {
	// contains filtered or unexported fields
}

func Concat

func Concat(videos []Video, tempFolder string) (Video, error)

func Load

func Load(fileName string) (Video, error)

func (Video) AudioFadeIn

func (V Video) AudioFadeIn(start, duration float64) Video

func (Video) AudioFadeOut

func (V Video) AudioFadeOut(duration float64) Video

func (Video) Duration

func (V Video) Duration() float64

func (Video) FadeIn

func (V Video) FadeIn(start, duration float64) Video

func (Video) FadeOut

func (V Video) FadeOut(duration float64) Video

func (Video) GetFilename

func (V Video) GetFilename() string

func (Video) Output

func (V Video) Output(OutputFilename string) Output

func (Video) Resize

func (V Video) Resize(width, height int64) Video

func (Video) ResizeByHeight

func (V Video) ResizeByHeight(requiredHeight int64) Video

func (Video) ResizeByWidth

func (V Video) ResizeByWidth(requiredWidth int64) Video

func (Video) Screenshot

func (V Video) Screenshot(timeInSeconds float64, outputFilename string) (string, error)

func (Video) SubClip

func (V Video) SubClip(start, end float64) Video

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL