diff --git a/examples/gif-encoder/main.go b/examples/gif-encoder/main.go index 9d0ca31..15c5955 100644 --- a/examples/gif-encoder/main.go +++ b/examples/gif-encoder/main.go @@ -115,11 +115,20 @@ func encodeGif(mainLoop *gst.MainLoop) error { // will be a new jpeg image from the pipeline. var frameNum int appSink.SetCallbacks(&app.SinkCallbacks{ - NewSampleFunc: func(sink *app.Sink) gst.FlowReturn { - if appSink.IsEOS() { - return gst.FlowEOS + EOSFunc: func(sink *app.Sink) { + fmt.Println("\nWriting the results of the gif to", outFile) + 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 frameNum++ @@ -128,9 +137,6 @@ func encodeGif(mainLoop *gst.MainLoop) error { // signal the main loop to quit. // This needs to be done from a goroutine to not block the app sink // callback. - appSink.CallAsync(func() { - pipeline.SendEvent(gst.NewEOSEvent()) - }) return gst.FlowEOS } @@ -142,7 +148,7 @@ func encodeGif(mainLoop *gst.MainLoop) error { defer sample.Unref() 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 // sink. @@ -212,15 +218,7 @@ func encodeGif(mainLoop *gst.MainLoop) error { // If no error happened on the pipeline. Write the results of the gif // to the destination. 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() diff --git a/file_example_MP4_480_1_5MG.gif b/file_example_MP4_480_1_5MG.gif new file mode 100644 index 0000000..be04ef4 Binary files /dev/null and b/file_example_MP4_480_1_5MG.gif differ diff --git a/file_example_MP4_480_1_5MG.mp4 b/file_example_MP4_480_1_5MG.mp4 new file mode 100644 index 0000000..b11552f Binary files /dev/null and b/file_example_MP4_480_1_5MG.mp4 differ