add example reading frame with ss

This commit is contained in:
Stephane Tombeur
2024-01-23 14:25:37 +01:00
parent 6649d14c4a
commit 62cabaf0c4
4 changed files with 33 additions and 0 deletions

View File

@@ -30,6 +30,18 @@ func TestExampleReadFrameAsJpeg(t *testing.T) {
}
}
func TestExampleReadTimePositionAsJpeg(t *testing.T) {
reader := ExampleReadTimePositionAsJpeg("./sample_data/in1.mp4", 4)
img, err := imaging.Decode(reader)
if err != nil {
t.Fatal(err)
}
err = imaging.Save(img, "./sample_data/out2.jpeg")
if err != nil {
t.Fatal(err)
}
}
func TestExampleShowProgress(t *testing.T) {
ExampleShowProgress("./sample_data/in1.mp4", "./sample_data/out2.mp4")
}

View File

@@ -0,0 +1,21 @@
package examples
import (
"bytes"
"io"
"os"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
func ExampleReadTimePositionAsJpeg(inFileName string, seconds int) io.Reader {
buf := bytes.NewBuffer(nil)
err := ffmpeg.Input(inFileName, ffmpeg.KwArgs{"ss": seconds}).
Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
WithOutput(buf, os.Stdout).
Run()
if err != nil {
panic(err)
}
return buf
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB