cinema

package module
v0.0.0-...-ca271f2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 9 Imported by: 3

README

cinema : a lightweight video editing library for Go

alt text

Overview GoDoc

cinema is a simple video editing library based on ffmpeg. It supports trimming, resizing, cropping and more. Use it to create videos directly or let it generate command lines that use ffmpeg for you.

Installation

You must have FFMPEG installed on your machine! Make sure ffmpeg and ffprobe are available from the command line on your machine. To install cinema run:

go get github.com/jtguibas/cinema

Example Usage

func main() {
	downloadTestVideo("example.mp4")

	video, err := cinema.Load("example.mp4")
	check(err)

	video.Trim(10*time.Second, 20*time.Second) // trim video from 10 to 20 seconds
	video.SetStart(1 * time.Second)            // trim first second of the video
	video.SetEnd(9 * time.Second)              // keep only up to 9 seconds
	video.SetSize(400, 300)                    // resize video to 400x300
	video.Crop(0, 0, 200, 200)                 // crop rectangle top-left (0,0) with size 200x200
	video.SetSize(400, 400)                    // resize cropped 200x200 video to a 400x400
	video.SetFPS(48)                           // set the output framerate to 48 frames per second
	video.Render("test_output.mov")            // note format conversion by file extension

	// you can also generate the command line instead of applying it directly
	fmt.Println("FFMPEG Command", video.CommandLine("test_output.mov"))
}

TODO

  • add concatenation support
  • improve godoc documentation
  • add cropping support
  • expand to audio
  • test ubuntu support
  • implement fps support
  • implement bitrate support

Feel free to open pull requests!

Acknowledgments

  • Big thanks to gonutz for contributing to this project!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Video

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

Video contains information about a video file and all the operations that need to be applied to it. Call Load to initialize a Video from file. Call the transformation functions to generate the desired output. Then call Render to generate the final output video file.

func Load

func Load(path string) (*Video, error)

Load gives you a Video that can be operated on. Load does not open the file or load it into memory. Apply operations to the Video and call Render to generate the output video file.

func (*Video) Bitrate

func (v *Video) Bitrate() int

Get the set bitrate of the current video struct

func (*Video) CommandLine

func (v *Video) CommandLine(output string) []string

CommandLine returns the command line that will be used to convert the Video if you were to call Render.

func (*Video) Crop

func (v *Video) Crop(x, y, width, height int)

Crop makes the output video a sub-rectangle of the input video. (0,0) is the top-left of the video, x goes right, y goes down.

func (*Video) Duration

func (v *Video) Duration() time.Duration

Duration returns the duration of the original input video. It does not account for any trim operation (Trim, SetStart, SetEnd). To get the current trimmed duration use

v.End() - v.Start()

func (*Video) End

func (v *Video) End() time.Duration

End returns the end of the video.

func (*Video) FPS

func (v *Video) FPS() int

Get the set fps of the current video struct

func (*Video) Filepath

func (v *Video) Filepath() string

Filepath returns the path of the input video.

func (*Video) Height

func (v *Video) Height() int

Height returns the width of the video in pixels.

func (*Video) Mute

func (v *Video) Mute()

Mute mutes the video

func (*Video) Render

func (v *Video) Render(output string) error

Render applies all operations to the Video and creates an output video file of the given name. This method won't return anything on stdout / stderr. If you need to read ffmpeg's outputs, use RenderWithStreams

func (*Video) RenderWithStreams

func (v *Video) RenderWithStreams(output string, os io.Writer, es io.Writer) error

RenderWithStreams applies all operations to the Video and creates an output video file of the given name. By specifying an output stream and an error stream, you can read ffmpeg's stdout and stderr.

func (*Video) SetBitrate

func (v *Video) SetBitrate(bitrate int)

SetBitrate sets the bitrate of the output video.

func (*Video) SetEnd

func (v *Video) SetEnd(end time.Duration)

SetEnd sets the end time of the output video. It is always relative to the original input video.

func (*Video) SetFPS

func (v *Video) SetFPS(fps int)

SetFPS sets the framerate (frames per second) of the output video.

func (*Video) SetSize

func (v *Video) SetSize(width int, height int)

SetSize sets the width and height of the output video.

func (*Video) SetStart

func (v *Video) SetStart(start time.Duration)

SetStart sets the start time of the output video. It is always relative to the original input video.

func (*Video) Start

func (v *Video) Start() time.Duration

Start returns the start of the video .

func (*Video) Trim

func (v *Video) Trim(start, end time.Duration)

Trim sets the start and end time of the output video. It is always relative to the original input video. start must be less than or equal to end or nothing will change.

func (*Video) Width

func (v *Video) Width() int

Width returns the width of the video in pixels.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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