From 20176176145c472f6dba52e0acbd77ccd4ae5522 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Sun, 28 Apr 2024 14:43:18 +0500 Subject: [PATCH 1/2] Added preset option for libx265. Added preset option for h264_nvenc. --- convertor/view/form_items/form.go | 6 +- convertor/view/form_items/h264_nvenc/view.go | 65 ++++++++++++++++++++ convertor/view/form_items/libx265/view.go | 65 ++++++++++++++++++++ encoder/h264_nvenc/encoder.go | 41 +++++++++++- encoder/libx265/encoder.go | 43 ++++++++++++- 5 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 convertor/view/form_items/h264_nvenc/view.go create mode 100644 convertor/view/form_items/libx265/view.go diff --git a/convertor/view/form_items/form.go b/convertor/view/form_items/form.go index 2d5e1e4..c0d1a7d 100644 --- a/convertor/view/form_items/form.go +++ b/convertor/view/form_items/form.go @@ -2,11 +2,15 @@ package form_items import ( "fyne.io/fyne/v2/widget" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view/form_items/h264_nvenc" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view/form_items/libx264" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view/form_items/libx265" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel" ) var Views = map[string]func(encoder encoder.EncoderContract, app kernel.AppContract) []*widget.FormItem{ - "libx264": libx264.View, + "libx264": libx264.View, + "h264_nvenc": h264_nvenc.View, + "libx265": libx265.View, } diff --git a/convertor/view/form_items/h264_nvenc/view.go b/convertor/view/form_items/h264_nvenc/view.go new file mode 100644 index 0000000..81b3c15 --- /dev/null +++ b/convertor/view/form_items/h264_nvenc/view.go @@ -0,0 +1,65 @@ +package h264_nvenc + +import ( + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/widget" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder/h264_nvenc" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel" + "github.com/nicksnyder/go-i18n/v2/i18n" +) + +func View(encoder encoder.EncoderContract, app kernel.AppContract) []*widget.FormItem { + items := []*widget.FormItem{} + + items = append(items, presetParameter(encoder, app)...) + + return items +} + +func presetParameter(encoder encoder.EncoderContract, app kernel.AppContract) []*widget.FormItem { + parameter, err := encoder.GetParameter("preset") + if err != nil { + return nil + } + + presets := map[string]string{} + presetsForSelect := []string{} + presetDefault := "" + + for _, name := range h264_nvenc.Presets { + title := name + presetsForSelect = append(presetsForSelect, name) + presets[title] = name + if name == parameter.Get() { + presetDefault = title + } + } + + elementSelect := widget.NewSelect(presetsForSelect, func(s string) { + if presets[s] == "" { + return + } + parameter.Set(presets[s]) + }) + elementSelect.SetSelected(presetDefault) + elementSelect.Hide() + + checkboxTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "parameterCheckbox"}) + elementCheckbox := widget.NewCheck(checkboxTitle, func(b bool) { + if b == true { + parameter.SetEnable() + elementSelect.Show() + return + } + parameter.SetDisable() + elementSelect.Hide() + }) + + return []*widget.FormItem{ + { + Text: app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "formPreset"}), + Widget: container.NewVBox(elementCheckbox, elementSelect), + }, + } +} diff --git a/convertor/view/form_items/libx265/view.go b/convertor/view/form_items/libx265/view.go new file mode 100644 index 0000000..434defd --- /dev/null +++ b/convertor/view/form_items/libx265/view.go @@ -0,0 +1,65 @@ +package libx265 + +import ( + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/widget" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder/libx265" + "git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel" + "github.com/nicksnyder/go-i18n/v2/i18n" +) + +func View(encoder encoder.EncoderContract, app kernel.AppContract) []*widget.FormItem { + items := []*widget.FormItem{} + + items = append(items, presetParameter(encoder, app)...) + + return items +} + +func presetParameter(encoder encoder.EncoderContract, app kernel.AppContract) []*widget.FormItem { + parameter, err := encoder.GetParameter("preset") + if err != nil { + return nil + } + + presets := map[string]string{} + presetsForSelect := []string{} + presetDefault := "" + + for _, name := range libx265.Presets { + title := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "preset_" + name}) + presetsForSelect = append(presetsForSelect, title) + presets[title] = name + if name == parameter.Get() { + presetDefault = title + } + } + + elementSelect := widget.NewSelect(presetsForSelect, func(s string) { + if presets[s] == "" { + return + } + parameter.Set(presets[s]) + }) + elementSelect.SetSelected(presetDefault) + elementSelect.Hide() + + checkboxTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "parameterCheckbox"}) + elementCheckbox := widget.NewCheck(checkboxTitle, func(b bool) { + if b == true { + parameter.SetEnable() + elementSelect.Show() + return + } + parameter.SetDisable() + elementSelect.Hide() + }) + + return []*widget.FormItem{ + { + Text: app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "formPreset"}), + Widget: container.NewVBox(elementCheckbox, elementSelect), + }, + } +} diff --git a/encoder/h264_nvenc/encoder.go b/encoder/h264_nvenc/encoder.go index b0dcb17..b064975 100644 --- a/encoder/h264_nvenc/encoder.go +++ b/encoder/h264_nvenc/encoder.go @@ -1,13 +1,37 @@ package h264_nvenc import ( + "errors" encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder" ) +var Presets = []string{ + "default", + "slow", + "medium", + "fast", + "hp", + "hq", + "bd", + "ll", + "llhq", + "llhp", + "lossless", + "losslesshp", +} + func NewEncoder() encoder2.EncoderContract { - parameters := map[string]encoder2.ParameterContract{} + parameters := map[string]encoder2.ParameterContract{ + "preset": newParameterPreset(), + } getParams := func(parameters map[string]encoder2.ParameterContract) []string { - return []string{"-c:v", "h264_nvenc"} + params := []string{"-c:v", "h264_nvenc"} + + if parameters["preset"] != nil && parameters["preset"].IsEnabled() { + params = append(params, "-preset", parameters["preset"].Get()) + } + + return params } return encoder2.NewEncoder("h264_nvenc", parameters, getParams) @@ -19,3 +43,16 @@ func NewData() encoder2.EncoderDataContract { fileType := encoder2.FileType(encoder2.Video) return encoder2.NewData(title, formats, fileType, NewEncoder) } + +func newParameterPreset() encoder2.ParameterContract { + setParameter := func(s string) (string, error) { + for _, value := range Presets { + if value == s { + return value, nil + } + } + + return "", errors.New("preset not found") + } + return encoder2.NewParameter("preset", false, "default", setParameter) +} diff --git a/encoder/libx265/encoder.go b/encoder/libx265/encoder.go index 9f5eb27..1d4a1f3 100644 --- a/encoder/libx265/encoder.go +++ b/encoder/libx265/encoder.go @@ -1,11 +1,35 @@ package libx265 -import encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder" +import ( + "errors" + encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder" +) + +var Presets = []string{ + "ultrafast", + "superfast", + "veryfast", + "faster", + "fast", + "medium", + "slow", + "slower", + "veryslow", + "placebo", +} func NewEncoder() encoder2.EncoderContract { - parameters := map[string]encoder2.ParameterContract{} + parameters := map[string]encoder2.ParameterContract{ + "preset": newParameterPreset(), + } getParams := func(parameters map[string]encoder2.ParameterContract) []string { - return []string{"-c:v", "libx265"} + params := []string{"-c:v", "libx265"} + + if parameters["preset"] != nil && parameters["preset"].IsEnabled() { + params = append(params, "-preset", parameters["preset"].Get()) + } + + return params } return encoder2.NewEncoder("libx265", parameters, getParams) @@ -17,3 +41,16 @@ func NewData() encoder2.EncoderDataContract { fileType := encoder2.FileType(encoder2.Video) return encoder2.NewData(title, formats, fileType, NewEncoder) } + +func newParameterPreset() encoder2.ParameterContract { + setParameter := func(s string) (string, error) { + for _, value := range Presets { + if value == s { + return value, nil + } + } + + return "", errors.New("preset not found") + } + return encoder2.NewParameter("preset", false, "medium", setParameter) +} From 9aaee4c1834379ca3ef2b452758e5d193759058a Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Sun, 28 Apr 2024 14:52:18 +0500 Subject: [PATCH 2/2] Changed the version to 0.7.0 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1dc1807..d510f8e 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ func init() { appMetadata := &fyne.AppMetadata{ ID: "net.kor-elf.projects.gui-for-ffmpeg", Name: "GUI for FFmpeg", - Version: "0.6.0", + Version: "0.7.0", Icon: iconResource, }