mutablelogic / go-media

go media services
https://pkg.go.dev/github.com/mutablelogic/go-media
Apache License 2.0
26 stars 2 forks source link

Extracting frames from a specific offset using go-media API #37

Open itallix opened 1 month ago

itallix commented 1 month ago

Hi,

I need to extract frames from a video starting at a specific offset. In the command line, this is typically done using the ss parameter in ffmpeg, e. g.: ffmpeg -ss 333300ms ... I am wondering if there is an easy way to achieve this using the go-media API available in pkg, or if this functionality is only accessible using the bindings from the sys package?

If possible, could you provide any sample code or guidance on how to implement this using go-media?

Thank you for your assistance!

djthorpe commented 1 month ago

Hi Vitalii

Sure the example you want is this one: https://github.com/mutablelogic/go-media/blob/main/cmd/examples/decode/main.go

The decode method returns a frame from the media file and that has a method Ts() which returns the current timestamp in seconds so you can ignore frames up to that point.

It would be more efficient to add a Seek() method to the media file but I didn't implement that yet.

Let me know if you have any other questions

itallix commented 1 month ago

Hi Vitalii Sure the example you want is this one: https://github.com/mutablelogic/go-media/blob/main/cmd/examples/decode/main.go The decode method returns a frame from the media file and that has a method Ts() which returns the current timestamp in seconds so you can ignore frames up to that point. It would be more efficient to add a Seek() method to the media file but I didn't implement that yet. Let me know if you have any other questions

@djthorpe thank you for your response.

I reviewed the sample you highlighted, but it's not going to work efficiently for my use case, where I need to capture sets of frames with a specific offset in batches (e.g., from frame N to N + 200, skipping every X frames).

I will likely reuse your bindings for now. Do you have any plans to support ffmpeg7?

djthorpe commented 1 month ago

Hi not sure the ffmoeg7 API is tons different so it may work. If there are significant differences when you try let me know. When I have some time I can create a seek method for file-based media that objects. In the meantime there might be a packet-based decode function (or I can easily add it) which allows you to skip forward quickly, but otherwise there should be enough sample code in the repo to allow you to use the bindings directly.

Let me know how it goes!