top | item 31053274

Show HN: Golang FFmpeg wrapper for simple Video I/O and Webcam Streaming

129 points| crypt0lution | 3 years ago |github.com

32 comments

order
[+] MawKKe|3 years ago|reply
You can instruct ffprobe to output the metadata in JSON (-print_format json), removing the need for manual parsing. Although you already utilize "-print_format compact" - was this a deliberate choice?

Also, you don't have to do manual stdout buffering. Have a look at ReadChapters function in here: https://github.com/MawKKe/audiobook-split-ffmpeg-go/blob/f95... (fyi it's my own repo)

[+] crypt0lution|3 years ago|reply
I originally wanted to use json for parsing, however the unmarshalling would have required a large struct with fields for all the metadata ffprobe outputs. I thought that using "-print_format compact" resulted in a simpler parsing approach. Correct me if I'm wrong there, I'm still relatively new to Go.

Thanks for sharing the link to your project. I'll try to implement the stdout buffering with "bytes" rather than doing it manually.

[+] DoctorOW|3 years ago|reply
A couple years ago I tried making a GIF generator in Go and a decent FFMPEG wrapper is something the Golang community needs.
[+] throwaway894345|3 years ago|reply
I’m not familiar with FFMPEG. How hard would it be to reproduce bits of it in Go natively? Why does everyone need to sub process out to this one library.
[+] sam0x17|3 years ago|reply
Side note the image-rs crate in the Rust ecosystem has no external dependencies and can encode and decode animated gifs and a variety of other image formats, 100% rust https://github.com/image-rs/image. At my startup we use this in a lambda to process user-uploaded images, with great success.
[+] staunch|3 years ago|reply
Nice! Looks like a good start. As some have noted in this thread there are some issues but nothing you can't fix.

I'd recommend running `go vet -a` and `golangci-lint` on it to see some of the current issues:

  $ go vet -a

  $ docker run --rm "--volume=$(pwd):/app" --workdir=/app golangci/golangci-lint:latest golangci-lint run
[+] oefrha|3 years ago|reply
README shows various structs with zero exported fields, and example code working with those unexported fields which don't make sense and won't work unless directly placed in this package. There are other problems like non-idiomatic snake_case naming. I guess this is OP's golang learning project? (To be clear, making mistakes in the beginning is completely fine.)
[+] crypt0lution|3 years ago|reply
That's correct. I like to use go for image processing and wanted to apply some of the algorithms I made to video but did not find a simple way to do so. I set out to make a video I/O module.

I'm currently fixing all the non-idiomatic problems as well as adding some getters for each struct. Thanks for the feedback!

[+] Philip-J-Fry|3 years ago|reply
Yeah, you wouldn't be able to import this into a separate module and use it.
[+] _wp_|3 years ago|reply
There's quite a bit of overhead in execing and piping data from ffmpeg. If performance is a concern, then using the C ffmpeg API is a better bet(see pyav for a good example of this) . Cool project though!
[+] preseinger|3 years ago|reply
This module isn't actually usable, because every error produces a panic.

If a function or method is fallible, it should return `(..., error)`, not panic.

[+] crypt0lution|3 years ago|reply
I'll fix that up when I have some time. Thanks for pointing it out. Most panics come from when something went wrong with the ffmpeg subprocess. I didn't know that there is a way for the user to handle errors coming from this subprocess.
[+] nih0|3 years ago|reply
correct me if im wrong but lowercase struct fields do not get exported right ?
[+] crypt0lution|3 years ago|reply
Made a push adding getters for relevant fields and making field names uppercase in the Options struct. Don't know how long it takes for pkg.dev to update, but the issue should be resolved now.