gmf icon indicating copy to clipboard operation
gmf copied to clipboard

Seek and extract jpeg

Open peterbe opened this issue 10 years ago • 2 comments

One thing I learned with using ffmpeg on the command line is that the absolutely fastest way to extract JPEGs from a video is to do something like this:

ffmpeg -ss 00:00:01 -i tests-sample.mp4 -vframes 1 ./tmp2/01.jpg
ffmpeg -ss 00:00:02 -i tests-sample.mp4 -vframes 1 ./tmp2/02.jpg
ffmpeg -ss 00:00:03 -i tests-sample.mp4 -vframes 1 ./tmp2/03.jpg
...

I modified the video-to-jpeg-p.go example so that it only generates 14 thumbnails (from a ~14 second video) (using 10 workers). So both your example script and my little bash script produces 14 JPEGs.

Benchmarking these, it's clear that the bash script version is faster.

Would it be possible to do the same in gmf? Like, opening a input context and seeking it to a certain number of seconds, then do something like dstFrame.EncodeNewPacket(cc).

peterbe avatar Dec 28 '14 19:12 peterbe

The video-to-jpeg-p.go example does some extra work, such as colorspace conversion (because of jpeg2000 codec) of every frame, while your bash example doesn't and uses simple mjpeg with very low quality (by default) applying only for first one.

About your question — yes, it's possible, use SeekFrameAt method, e.g.:


        inputCtx := assert(NewInputCtx(srcFileName)).(*FmtCtx)
        defer inputCtx.CloseInputAndRelease()

        inputCtx.SeekFrameAt(3, 0) // frame on 3rd second in stream 0

3d0c avatar Dec 29 '14 12:12 3d0c

Thanks for the tip with SeekFrameAt. I'll try to figure out how to use it. I'm a newbie at Go. What I want to do is find out the duration so that the number of frames is pretty much constant independent of length.

Anyway, regarding the quality of using the ffmpeg -ss HH:MM:SS ... command, it's as good as your example that uses JPEG2000. jpegm-gmf (the video-to-jpegm.go output)

jpeg-ffmpeg (the output from my bash script)

And I can't add an image to GitHub of a JPEG2000 image but if I export it to JPEG it has the same quality as the one from my bash script.

peterbe avatar Dec 30 '14 18:12 peterbe