4 ms·
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
by MawKKe 5y ago
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/f95ff190b6c09ab656817326c9101f0d0e403866/ffprobe.go#L79 https://github.com/MawKKe/audiobook-split-ffmpeg-go/blob/f95... (fyi it's my own repo)
- crypt0lution 5y agoI 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.
- kyrra 5y agoYou could do non-strict parsing and would be fine. You can also parse it directly into an untyped map. https://golangbyexample.com/json-to-map-golang/ https://golangbyexample.com/json-to-map-golang/
- oefrha 5y agoYou don’t need fields for everything that’s printed, you only need to specify fields of interest, the rest are automatically discarded. You can also use alternative json parsers like fastjson that are more dynamic instead of upfront.