Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Enable reading metadata #12

Merged
merged 2 commits into from
Nov 3, 2020
Merged

Enable reading metadata #12

merged 2 commits into from
Nov 3, 2020

Conversation

Borloxos
Copy link

I currently have the need to read the metadata of an input file, as supplied by ffprobe, e.g. to transcode to different output sizes, depending on the input size of a file.

As this is currently not possible with this library, I tried to implement the changes necessary for that.
The changes include

  • Creating interfaces for Metadata, Format, Streams, Tags and Disposition, that contain all the necessary getters
  • Moving the Metadata type definitions in package ffmpeg into their own file, together with implementations of the necessary getters
  • Exporting the function Transcoder.getMetadata() and making it available inside the Transcoder interface
    • Along with this, changing some types and calls in ffmpeg/ffmpeg.go

I've tested reading the metadata with the following code snippet, that demonstrates the changes capabilities:

transcoder := ffmpeg.
	New(ffmpegConfig).
	Input(transcoderRequest.Filename)

metadata, err := transcoder.GetMetadata()
errorHandler.HandleError(err, "component", "transcode", "function", "transcode", "action", "transcoder.GetMetadata")
fmt.Printf("Duration: %s\nFilename: %s\nFormat: %s\nProbeScore: %d\n\n", metadata.GetFormat().GetDuration(), metadata.GetFormat().GetFilename(), metadata.GetFormat().GetFormatLongName(), metadata.GetFormat().GetProbeScore())

for _, element := range metadata.GetStreams() {
	fmt.Printf("Codec-Name: %s\nHeight: %d\n\n", element.GetCodecName(), element.GetHeight())
}

This PR should not break any existing behaviour. If there are any problems with it, I'll be happy to fix them.

…s, adds interfaces and exports Transcoder.GetMetadata
@denisonfire
Copy link

Very useful feature. Looking forward it will be merged soon.

@xfrr xfrr merged commit 2c44ff9 into floostack:master Nov 3, 2020
@xfrr
Copy link
Collaborator

xfrr commented Nov 3, 2020

Very helpful, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants