xfrr / goffmpeg Goto Github PK
View Code? Open in Web Editor NEWPowerful and dev-friendly FFMPEG wrapper written in Go
License: MIT License
Powerful and dev-friendly FFMPEG wrapper written in Go
License: MIT License
Hello!
I don't found any way to pass my own parameters to converter.
Can I pass my own convert string and use lib as output parser?
Thank you!
Getting this error:
Unrecognized option 'print_format'.
Can you give an example to convert mp4 to hls 360p, 480p, 720p and 1080p?
ffmpeg -re -i "https//........../playlist.m3u8" -codec copy -map 0 -f segment -segment_list playlist.m3u8 -segment_list_flags +live -segment_time 10 out%03d.ts
How to convert?
Hi 👋
I'm trying to write a small utility that resizes video files while reporting the progress of the transcoding, so using your package I wrote this snippet that works (i.e. the file transcoding works), but no output is streamed from channel returned by the Transcoder.Output()
method:
package main
import (
"fmt"
"github.com/xfrr/goffmpeg/transcoder"
)
var inputPath = "test.mkv"
var outputPath = "test.res.mkv"
func main() {
trans := new(transcoder.Transcoder)
err := trans.Initialize(inputPath, outputPath)
if err != nil {
panic(err)
}
trans.MediaFile().SetAudioCodec("copy")
trans.MediaFile().SetVideoCodec("libx264")
trans.MediaFile().SetVideoFilter("scale=854:480")
trans.MediaFile().SetCRF(18)
trans.MediaFile().SetPreset("veryslow")
done := trans.Run(true)
for msg := range trans.Output() {
fmt.Println(msg) // <- Nothing printed out here
}
if err = <-done; err != nil {
panic(err)
}
}
I did a bit of digging, and it seems that bufio.Scanner()
gets stuck here (no iteration in the loop).
I'm running ffmpeg 4.2.2 on macOS and Go 1.14.0, let me know if you need more information.
I tried this on Windows 10 and get this result:
C:\ProgramData\chocolatey\bin\ffprobe.exe
C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin\ffprobe.exe
panic: error executing ([-i D:\Users\Gert\Videos\Don Syme - Keynote - F# Code I Love _ Lambda Days 2019-MGLxyyTF3OM.mp4 -print_format json -show_format -show_streams -show_error]) | error: exec: "C:\\ProgramData\\chocolatey\\bin\\ffprobe.exeC:\\ProgramData\\chocolatey\\lib\\ffmpeg\\tools\\ffmpeg\\bin\\ffprobe.exe": file does not exist
Changing the configuration function could help:
ffmpeg := strings.Replace(strings.Split(outFFmpeg.String(), "\n")[0], utils.LineSeparator(), "", -1)
fprobe := strings.Replace(strings.Split(outProbe.String(), "\n")[0], utils.LineSeparator(), "", -1)
But I can't test on Linux or Mac right now.
Was wondering if it would be possible to make audio bitrate an integer, makes more sense and follows the convention of video bitrate being an integer.
In theory, it would be a good idea if they were both uint32, considering bitrates don't dip below 0.
Hi, I'm following the steps at https://brandur.org/fragments/ffmpeg-h265 to allow ffmpeg-converted H.265 videos to be playable on QuickTime. However, I'm still unsure on how to set that properly using this library.
In a batch processing Go script, I decided to use the following examples to convert H.264 videos to H.265.
trans.MediaFile().SetPreset("fast")
trans.MediaFile().SetVideoCodec("libx265")
trans.MediaFile().SetVideoProfile("main")
trans.MediaFile().SetTags(map[string]string{"p": "hvc1"})
trans.MediaFile().SetFrameRate(VIDEO_FRAME_RATE)
trans.MediaFile().SetAudioCodec("aac")
trans.MediaFile().SetAudioRate(AUDIO_SAMPLING_RATE)
In this case, the tag is still not applied properly.
I've also replaced trans.MediaFile().SetTags(map[string]string{"p": "hvc1"})
with others, including:
trans.MediaFile().SetTags(map[string]string{"hvc1": ""})
(same behavior)trans.MediaFile().SetRawOutputArgs([]string{"-tag:v hvc1"})
ffmpeg -y -i videos/orig/58.mp4 -r 30 -ar 44100 -c:v libx265 -profile:v main -c:a aac -preset fast -tag:v hvc1 -hls_list_size 0 videos/h265-aac-mp4/58.mp4
manually works and produces the QuickTime-playable HEVC video.can support user define ffmpeg but not get from path.
func (t *Transcoder) Initialize(inputPath string, outputPath string) error {
var err error
configuration := t.configuration
if len(configuration.FfmpegBin) == 0 || len(configuration.FfprobeBin) == 0 {
configuration, err = ffmpeg.Configure()
if err != nil {
fmt.Println(err)
return err
}
}
}
First, thanks for this library as it's incredibly useful and it was very hard to find simple libraries to wrap around ffmpeg for easy video encoding.
One of the features I need is to be able to know the resolution of a file and make decisions based on that, but I couldn't get it working. (Maybe just using ffprobe)
Is this something you could add? I'm not clear on how to implement it without using Transcoder.Initialize (but that gives me a fault if I don't finish the encode).
Thanks
Ffmpeg can run on so much more than only local files.
Checking if a file exists locally really limits what ffmpeg can do.
Is there a way to also create a thumbnail? That would be awesome
You have duplicated the method ObtainMovFlags.
Fran, parece que te ha ocurrido lo mismo con SetMovFlags.
Creo que somos unos cuantos que estamos usando tu proyecto, y este tipo de cambios nos impiden compilar.
Te recomendaría que hicieras los siguientes cambios en el proyecto:
Gracias
In models/media.go, there appears to be two declarations of SetMovFlags: once on line 260, and again on 352.
Looks like this is a very recent commit to master, so perhaps you are in the midst of things....
Hi 👋,
So I was able to get goffmpeg
to convert a .mov
-> mp4
. Based of the example from the readme. I did a bit of digging into old issues and current ones to try to piece together how to convert the .mp4
I got into HLS
.
Here's what I got:
❯ go run src/converter/main.go
panic: Failed Finish FFMPEG ([-nostats -loglevel 0 -y -i data/test.mp4 -c:v copy -hls_list_size 10 -hls_time 10 -hls_key_info_file data/test.m3u8]) with exit status 1 message
goroutine 1 [running]:
main.convert()
/src/converter/main.go:32 +0x1c8
main.main()
/src/converter/main.go:11 +0x20
exit status 2
From my go code:
package main
import (
"github.com/xfrr/goffmpeg/transcoder"
)
var inputPath = "data/test.mp4"
var outputPath = "data/test.m3u8"
func main() {
convert()
}
func convert() {
trans := new(transcoder.Transcoder)
err := trans.Initialize(inputPath, outputPath)
if err != nil {
panic(err)
}
// Copy video streams
trans.MediaFile().SetVideoCodec("copy")
// Set hls list size
trans.MediaFile().SetHlsListSize(0)
// Set HLS time
trans.MediaFile().SetHlsSegmentDuration(10)
done := trans.Run(false)
if err = <-done; err != nil {
panic(err)
}
}
Any chance you know what I may be doing wrong here?
My video directory path is showing this error \main.go:15:27: syntax error: unexpected :, expecting comma or )
I'm new to ffmpeg but I get an error running the example in the readme. I created the input file, but it errors with:
src/converter/main.go:16:2: err declared but not used
After using err in an control flow check I get this printed out in my terminal:
❯ go run src/converter/main.go
panic: error executing ([-i test.mov -print_format json -show_format -show_streams -show_error]) | error: exit status 1 | message: {
"error": {
"code": -2,
"string": "No such file or directory"
}
}
ffprobe version 4.2.2 Copyright (c) 2007-2019 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.59)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags=-fno-stack-check --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
test.mov: No such file or directory
goroutine 1 [running]:
main.convert()
/Users/kennetpostigo/Projects/specter/go/specter-api/src/converter/main.go:21 +0x335
main.main()
/Users/kennetpostigo/Projects/specter/go/specter-api/src/converter/main.go:13 +0x20
exit status 2
From this:
package main
import (
"fmt"
"github.com/xfrr/goffmpeg/transcoder"
)
var inputPath = "test.mov"
var outputPath = "test.mp4"
func main() {
convert()
}
func convert() {
trans := new(transcoder.Transcoder)
err := trans.Initialize(inputPath, outputPath)
if err != nil {
panic(err)
}
done := trans.Run(true)
progress := trans.Output()
for msg := range progress {
fmt.Println(msg)
}
if err = <-done; err != nil {
panic(err)
}
}
Do you know what I may be doing wrong here?
Would be useful to add multiple output support like explained here: https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs
Thanks!
bin/sh command causing file is invalid having error.. is there any other option to run it in windows operating system
Hi, thank you for this awesome, up to date binding. How can I add a vtag to the transcoder?
The cli option would be -vtag xvid
for example.
Thanks!
Can we make a public method to stop the transcoder? For example, if I am saving an HLS stream to file, I probably want to stop it gracefully before the event ends.
Hi,
Is it possible to read a video while it is transcoding please?
Thank you
I found that this project already supports Go modules. But sadly, the tags doesn't follow Semantic Versioning, which means that all tags of this project will be ignored by Go modules and replaced by pseudo-versions, go get acts weirdly when tags are not in that form. It would be great to have the tagged release be named in the format vX.X.X format so that go mod can read it.
github.com/xfrr/goffmpeg v0.0.0-20200730134436-d910add31983
Else the mod file shows something like github.com/xfrr/goffmpeg v0.0.0-20200730134436-d910add31983
which is not very readable and difficult to upgrade. It’s hard to verify which version is in use. This is not conducive to version control.
So, I propose this project to follow Semantic Versioning in future versions. For example, v1.0.1
, v2.0.0
, v3.1.0-alpha
, v3.1.0-beta.2
etc.
Is there a way to do scaling as described here using this lib?
Failed Finish FFMPEG
If I copy/paste the command it works just fine no problem. No idea why this is failing.
The README lists SetQuality as a Mediasetter however I get undefined error when trying to use it and recursive grep can't find it in the repository.
GOROOT=D:\Go #gosetup
GOPATH=C:\Users\shahi\go #gosetup
D:\Go\bin\go.exe get -t -v github.com/xfrr/goffmpeg/transcoder/... #gosetup
github.com/xfrr/goffmpeg (download)
github.com/xfrr/goffmpeg/models
C:\Users\shahi\go\src\github.com\xfrr\goffmpeg\models\media.go:352:21: (*Mediafile).SetMovFlags redeclared in this block
previous declaration at C:\Users\shahi\go\src\github.com\xfrr\goffmpeg\models\media.go:260:6
C:\Users\shahi\go\src\github.com\xfrr\goffmpeg\models\media.go:1166:21: (*Mediafile).ObtainMovFlags redeclared in this block
previous declaration at C:\Users\shahi\go\src\github.com\xfrr\goffmpeg\models\media.go:776:6
help me
SetInputPath only one input can be set,how to set up multiple input?
here is such a command:
ffmpeg -filter_complex ddagrab=output_idx=1:framerate=5,hwdownload,format=bgra -c:v libx264 -crf 18 output.mp4
It would be great if we could add the pipe protocol to this library, extending its use case in a major way.
I find the new edition had changed the code in ffmpeg/ffmpeg.go.
"ffprobe := strings.Replace(strings.Split(outProbe.String(), "\n")[0], utils.LineSeparator(), "", -1)"
this change make my item appear an error.
the ffprope become "E:\ffmpeg\bin\ffprope.exe\r".
Right now wrapper can create only one HLS stream.
e.g. this command will able create 2 formats in one run:
ffmpeg -y -i sintel_trailer-1080p.mp4 \
-preset slow -g 48 -sc_threshold 0 \
-map 0:0 -map 0:1
-s:v:0 640x360 -c:v:0 libx264 -b:v:0 2000k \
-s:v:1 960x540 -c:v:1 libx264 -b:v:1 365k \
-c:a copy -var_stream_map "v:0,a:0 v:1,a:1" -master_pl_name master.m3u8 -f hls
-hls_time 6 -hls_list_size 0 \
-hls_segment_filename "v%v/fileSequence%d.ts" v%v/prog_index.m3u8
So, suggestion to have "addFormat" method with params such Media model and based on the sequence add params to the command.
Example in php:
$lowBitrate = (new X264)->setKiloBitrate(250);
$midBitrate = (new X264)->setKiloBitrate(500);
$highBitrate = (new X264)->setKiloBitrate(1000);
FFMpeg::fromDisk('videos')
->open('steve_howe.mp4')
->exportForHLS()
->setSegmentLength(10) // optional
->addFormat($lowBitrate)
->addFormat($midBitrate)
->addFormat($highBitrate)
->save('adaptive_steve.m3u8');
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.