commit hacked gif-encoder

This commit is contained in:
tinyzimmer
2020-10-05 11:29:16 +03:00
parent ebdff9159c
commit 6c755dd573
3 changed files with 15 additions and 17 deletions

View File

@@ -115,11 +115,20 @@ func encodeGif(mainLoop *gst.MainLoop) error {
// will be a new jpeg image from the pipeline. // will be a new jpeg image from the pipeline.
var frameNum int var frameNum int
appSink.SetCallbacks(&app.SinkCallbacks{ appSink.SetCallbacks(&app.SinkCallbacks{
NewSampleFunc: func(sink *app.Sink) gst.FlowReturn { EOSFunc: func(sink *app.Sink) {
if appSink.IsEOS() { fmt.Println("\nWriting the results of the gif to", outFile)
return gst.FlowEOS file, err := os.Create(outFile)
if err != nil {
fmt.Println("Could not create output file:", err)
return
} }
defer file.Close()
if err := gif.EncodeAll(file, outGif); err != nil {
fmt.Println("Could not encode images to gif format!", err)
}
mainLoop.Quit()
},
NewSampleFunc: func(sink *app.Sink) gst.FlowReturn {
// Increment the frame number counter // Increment the frame number counter
frameNum++ frameNum++
@@ -128,9 +137,6 @@ func encodeGif(mainLoop *gst.MainLoop) error {
// signal the main loop to quit. // signal the main loop to quit.
// This needs to be done from a goroutine to not block the app sink // This needs to be done from a goroutine to not block the app sink
// callback. // callback.
appSink.CallAsync(func() {
pipeline.SendEvent(gst.NewEOSEvent())
})
return gst.FlowEOS return gst.FlowEOS
} }
@@ -142,7 +148,7 @@ func encodeGif(mainLoop *gst.MainLoop) error {
defer sample.Unref() defer sample.Unref()
fmt.Printf("\033[2K\r") fmt.Printf("\033[2K\r")
fmt.Printf("Processing image frame %d/%d\n", frameNum, totalFrames) fmt.Printf("Processing image frame %d/%d", frameNum, totalFrames)
// We can retrieve a reader with the raw bytes of the image directly from the // We can retrieve a reader with the raw bytes of the image directly from the
// sink. // sink.
@@ -212,15 +218,7 @@ func encodeGif(mainLoop *gst.MainLoop) error {
// If no error happened on the pipeline. Write the results of the gif // If no error happened on the pipeline. Write the results of the gif
// to the destination. // to the destination.
if !isError { if !isError {
fmt.Println("Writing the results of the gif to", outFile)
file, err := os.Create(outFile)
if err != nil {
return err
}
defer file.Close()
if err := gif.EncodeAll(file, outGif); err != nil {
return err
}
} }
return pipeline.Destroy() return pipeline.Destroy()

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.