GOFFMPEG

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

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

Go to latest
Published: Sep 11, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

README

Go FFmpeg Wrapper Library

This is a simple Go wrapper library for FFmpeg that provides an easy way to perform common video and audio transcoding tasks using FFmpeg's features.

Features

  • Transcode video from one format to another.
  • Remove audio from a input video file.
  • Extract audio from a input video file.
  • Extract video clip from a input video file.
  • Extract audio clip from a input file.
  • Concatenate multiple video files into a single video.

Installation

Before using this library, ensure that you have FFmpeg installed on your system.

# Install FFmpeg on Ubuntu
sudo apt-get install ffmpeg

# Install FFmpeg on macOS using Homebrew
brew install ffmpeg

# To use this library in your Go project, you can install it via go get:
go get -u github.com/LinuxSploit/GOFFMPEG/

Usage

package main

import (
	"fmt"
	"log"

	"github.com/LinuxSploit/GOFFMPEG"
)

func main() {
	// Initialize the FFmpeg wrapper with the path to the FFmpeg executable.
	ffmpeg := GOFFMPEG.NewFFmpeg("/path/to/ffmpeg")

	// +
	// Example: Transcode a video
	outputPath, err := ffmpeg.TranscodeVideo("/home/linuxsploit/demo1.mp4", ".mkv")
	if err != nil {
		fmt.Println("Error transcoding video:", err)
	}
	log.Println(outputPath)

	// +
	// Example: Remove Audio from video, Extract only video
	outputPath, err = ffmpeg.ExtractVideo("/home/linuxsploit/demo.mp4", ".mp4", false)
	if err != nil {
		fmt.Println("Error extracting audio:", err)
	}
	log.Println(outputPath)

	// +
	// Example: Extract audio from a video
	outputPath, err = ffmpeg.ExtractAudio("/home/linuxsploit/demo.mp4", ".mp3", false)
	if err != nil {
		fmt.Println("Error extracting audio:", err)
	}
	log.Println(outputPath)

	// +
	// Example: Extract Video Clip of 20 seconds to 70 seconds timestamp from a input video
	outputPath, err = ffmpeg.ExtractVideoClip("/home/linuxsploit/demo.mp4", ".mp4", 20, 70, false, false)
	if err != nil {
		fmt.Println("Error extracting audio:", err)
	}
	log.Println(outputPath)

	// +
	// Example: Extract Audio Clip of 20 seconds to 70 seconds timestamp from a input video
	outputPath, err = ffmpeg.ExtractAudioClip("/home/linuxsploit/demo.mp4", ".mp3", 20, 70, false)
	if err != nil {
		fmt.Println("Error extracting audio:", err)
	}
	log.Println(outputPath)

	// +
	// Example: Concatenate multiple videos, input videos should have same resolution
	outputPath, err = ffmpeg.ConcatVideos(
		[]string{
			"/home/linuxsploit/demo1.mp4",
			"/home/linuxsploit/demo2.mp4",
			"/home/linuxsploit/demo3.mp4",
		},
		".mkv",
	)
	if err != nil {
		fmt.Println("Error Concatenating videos:", err)
	}
	log.Println(outputPath)
}

License:

This FFmpeg wrapper library is open-source and distributed under the GPL-3.0 License. See the LICENSE file for details.

Contribution:

Contributions are welcome! Please feel free to open issues or submit pull requests to enhance this library.

Disclaimer:

This library is a basic wrapper for FFmpeg and may not cover all FFmpeg features and options. It is intended for common use cases and can be extended to support additional functionality.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FFMPEG_TempDir string
)

Functions

This section is empty.

Types

type FFmpeg

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

FFmpeg represents the FFmpeg wrapper.

func NewFFmpeg

func NewFFmpeg(ffmpegPath string) *FFmpeg

NewFFmpeg creates a new FFmpeg instance with the specified path.

func (FFmpeg) ConcatVideos

func (f FFmpeg) ConcatVideos(inputPaths []string, OutPutFormatExtension string) (string, error)

ConcatVideos concatenates multiple video files into a single video. []string videos should have same resolution. Example: ConcatVideos(

	[]string{
		"/home/linuxsploit/demo1.mp4",
		"/home/linuxsploit/demo2.mp4",
		"/home/linuxsploit/demo3.mp4",
	},
	".mkv",
)

func (FFmpeg) ExtractAudio

func (f FFmpeg) ExtractAudio(inputPath, OutPutFormatExtension string, copyAudioCodec bool) (string, error)

ExtractAudio extracts audio stream from a video file with the specified output format extension and audio codec options. It takes the input video file path, output file path with the desired extension (e.g., ".mp3", ".ogg"), and a boolean flag to control audio codec copying. It returns the path to the extracted audio file and any encountered errors. example: outputVideoPath,err := ExtractAudio("/home/linuxsploit/demo.mp4",".mp3",false)

func (FFmpeg) ExtractAudioClip

func (f FFmpeg) ExtractAudioClip(inputPath, OutPutFormatExtension string, startSec, endSec float64, copyAudioCodec bool) (string, error)

ExtractAudioClip extracts an audio clip from a specified time range in a video file. It takes the input video file path, start time in seconds, end time in seconds, and boolean flags to control video and audio options. It returns the path to the extracted audio clip file and any encountered errors. example: ExtractAudioClip("/home/linuxsploit/demo.mp4", ".mp3", 25, 50, false)

func (FFmpeg) ExtractVideo

func (f FFmpeg) ExtractVideo(inputPath, OutPutFormatExtension string, copyVideoCodec bool) (string, error)

ExtractVideo extracts video stream from a video file with the specified output format extension and video codec options. It takes the input video file path, output file path with the desired extension (e.g., ".mp4", ".avi"), and a boolean flag to control video codec copying. It returns the path to the extracted video file and any encountered errors. Example: outputVideoPath, err := ExtractVideo("/home/linuxsploit/demo.mp4", ".mp4", false)

func (FFmpeg) ExtractVideoClip

func (f FFmpeg) ExtractVideoClip(inputPath, OutPutFormatExtension string, startSec, endSec float64, copyVideoCodec, disableAudio bool) (string, error)

ExtractVideoClip extracts a video clip from a specified time range in a video file. It takes the input video file path, start time in seconds, end time in seconds, and boolean flags to control video and audio options. It returns the path to the extracted video clip file and any encountered errors. example: ExtractVideoClip("/home/linuxsploit/demo.mp4", ".mp4", 25, 50, false, false)

func (FFmpeg) Run

func (f FFmpeg) Run(args []string) error

func (FFmpeg) TranscodeVideo

func (f FFmpeg) TranscodeVideo(inputPath, OutPutFormatExtension string) (string, error)

TranscodeVideo transcodes a video file to a different format. example: outputVideoPath,err := TranscodeVideo("/home/linuxsploit/demo.mp4", ".mkv)

Jump to

Keyboard shortcuts

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