mirror of
https://github.com/IllusionMan1212/ffui.git
synced 2026-10-24 18:12:35 +00:00
Compare commits
2
Commits
206a62ee76
...
4f22b5252c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f22b5252c
|
||
|
|
5e74d10409
|
@@ -1,4 +1,4 @@
|
|||||||
- [ ] query ffmpeg binary for available encoders and list the ones we know
|
- [x] query ffmpeg binary for available encoders and list the ones we know
|
||||||
- [ ] when passing in a directory, list all video files in that directory and have the user choose which ones they want encoded
|
- [ ] when passing in a directory, list all video files in that directory and have the user choose which ones they want encoded
|
||||||
- This will of course have a select all checkbox for quickly encoding all the files in a dir.
|
- This will of course have a select all checkbox for quickly encoding all the files in a dir.
|
||||||
- [ ] calculate total progress based on file sizes instead of counts of files for a more accurate progress percentage.
|
- [ ] calculate total progress based on file sizes instead of counts of files for a more accurate progress percentage.
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ var checkmark = lipgloss.NewStyle().Foreground(lipgloss.Color("#22FF33")).Render
|
|||||||
var x = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF2233")).Render("✖️")
|
var x = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF2233")).Render("✖️")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Cfg Screen = iota
|
None Screen = iota
|
||||||
|
Files
|
||||||
|
Cfg
|
||||||
Main
|
Main
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,13 +57,26 @@ func initialModel(fileInfo os.FileInfo, absolutePath string) *model {
|
|||||||
s.Spinner = spinner.Dot
|
s.Spinner = spinner.Dot
|
||||||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
||||||
|
|
||||||
codecs, err := exec.Command("ffmpeg", "-encoders").Output()
|
codecsStr, err := exec.Command("ffmpeg", "-encoders").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: parse the codecs and get the one we care about.
|
codecs := strings.Split(strings.Split(string(codecsStr), " ------\n")[1], "\n")
|
||||||
log.Println(strings.Split(strings.Split(string(codecs), " ------\n")[1], "\n"))
|
|
||||||
|
for i, codec := range codecs {
|
||||||
|
if codec == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
codecs[i] = strings.Fields(codec)[1]
|
||||||
|
|
||||||
|
// hardcoded indexes are never bad YEP :)))
|
||||||
|
if contains(SupportedVideoEncoders, codecs[i]) {
|
||||||
|
Configs[2].Opts = append(Configs[2].Opts, codecs[i])
|
||||||
|
} else if contains(SupportedAudioEncoders, codecs[i]) {
|
||||||
|
Configs[3].Opts = append(Configs[3].Opts, codecs[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &model{
|
return &model{
|
||||||
IsDirectory: fileInfo.IsDir(),
|
IsDirectory: fileInfo.IsDir(),
|
||||||
@@ -93,7 +108,7 @@ func (m model) updateConfigFocusedOptions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
return tea.Batch(m.Spinner.Tick, initCfg)
|
return tea.Batch(m.Spinner.Tick, m.statFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
@@ -104,9 +119,30 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.ErrQuitMessage = msg.msg
|
m.ErrQuitMessage = msg.msg
|
||||||
m.ErrQuit = true
|
m.ErrQuit = true
|
||||||
return m, m.cleanUp
|
return m, m.cleanUp
|
||||||
|
case filesStatMsg:
|
||||||
|
m.FileCount = msg.fileCount
|
||||||
|
m.Files = msg.files
|
||||||
|
|
||||||
|
if len(m.Files) == 1 {
|
||||||
|
m.Screen = Cfg
|
||||||
|
} else if len(m.Files) > 1 {
|
||||||
|
m.Screen = Files
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m.Screen {
|
switch m.Screen {
|
||||||
|
case Files:
|
||||||
|
// TODO: navigate files and select them and stuff
|
||||||
|
switch msg := msg.(type) {
|
||||||
|
case tea.KeyMsg:
|
||||||
|
key := msg.String()
|
||||||
|
switch key {
|
||||||
|
case "ctrl+c", "esc":
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
}
|
||||||
case Cfg:
|
case Cfg:
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
@@ -165,7 +201,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case parsedCfgMsg:
|
case parsedCfgMsg:
|
||||||
m.Screen = Main
|
m.Screen = Main
|
||||||
m.ParsedConfig = msg.parsedConfig
|
m.ParsedConfig = msg.parsedConfig
|
||||||
return m, tea.Batch(m.Spinner.Tick, m.statFile)
|
return m, tea.Batch(m.Spinner.Tick, startEncoding)
|
||||||
}
|
}
|
||||||
case Main:
|
case Main:
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
@@ -181,10 +217,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
case initUi:
|
case encodingStartedMsg:
|
||||||
m.FileCount = msg.fileCount
|
|
||||||
m.Files = msg.files
|
|
||||||
|
|
||||||
if m.DryRun {
|
if m.DryRun {
|
||||||
return m, gracefullyQuit
|
return m, gracefullyQuit
|
||||||
}
|
}
|
||||||
@@ -261,6 +294,19 @@ func parseConfig(cfg []Config) ParsedConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FilesScreenView(m model) string {
|
||||||
|
view := ""
|
||||||
|
|
||||||
|
// TODO: Create a nice view where we can select different videos and then select the encoding options and start
|
||||||
|
// encoding.
|
||||||
|
for _, file := range m.Files {
|
||||||
|
view += filepath.Base(file)
|
||||||
|
view += "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
func CfgScreenView(m model) string {
|
func CfgScreenView(m model) string {
|
||||||
view := ""
|
view := ""
|
||||||
|
|
||||||
@@ -380,6 +426,8 @@ func (m model) View() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch m.Screen {
|
switch m.Screen {
|
||||||
|
case Files:
|
||||||
|
return FilesScreenView(m)
|
||||||
case Cfg:
|
case Cfg:
|
||||||
return CfgScreenView(m)
|
return CfgScreenView(m)
|
||||||
case Main:
|
case Main:
|
||||||
|
|||||||
@@ -25,24 +25,24 @@ type ffmpegProcessStart struct {
|
|||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
type initUi struct {
|
type filesStatMsg struct {
|
||||||
fileCount int
|
fileCount int
|
||||||
files []string
|
files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *model) statFile() tea.Msg {
|
func (m *model) statFiles() tea.Msg {
|
||||||
if m.IsDirectory {
|
if m.IsDirectory {
|
||||||
entries, _ := os.ReadDir(m.Path)
|
entries, _ := os.ReadDir(m.Path)
|
||||||
|
|
||||||
sort.Sort(DirEntrySlice(entries))
|
sort.Sort(DirEntrySlice(entries))
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
fullFilePath := filepath.Join(m.Path, entry.Name())
|
if entry.IsDir() || !entry.Type().IsRegular() {
|
||||||
|
|
||||||
if entry.IsDir() {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fullFilePath := filepath.Join(m.Path, entry.Name())
|
||||||
|
|
||||||
mType, err := mimetype.DetectFile(fullFilePath)
|
mType, err := mimetype.DetectFile(fullFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -55,17 +55,27 @@ func (m *model) statFile() tea.Msg {
|
|||||||
m.FileCount++
|
m.FileCount++
|
||||||
m.Files = append(m.Files, fullFilePath)
|
m.Files = append(m.Files, fullFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(m.Files) == 0 {
|
||||||
|
return errQuitMsg{"Chosen directory has no video files"}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
m.FileCount = 1
|
m.FileCount = 1
|
||||||
m.Files = append(m.Files, m.Path)
|
m.Files = append(m.Files, m.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return initUi{
|
return filesStatMsg{
|
||||||
fileCount: m.FileCount,
|
fileCount: m.FileCount,
|
||||||
files: m.Files,
|
files: m.Files,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type encodingStartedMsg struct{}
|
||||||
|
|
||||||
|
func startEncoding() tea.Msg {
|
||||||
|
return encodingStartedMsg{}
|
||||||
|
}
|
||||||
|
|
||||||
type encodeVideoMsg struct{}
|
type encodeVideoMsg struct{}
|
||||||
|
|
||||||
func encodeVideo() tea.Msg {
|
func encodeVideo() tea.Msg {
|
||||||
@@ -78,12 +88,6 @@ func gracefullyQuit() tea.Msg {
|
|||||||
return quitMsg{}
|
return quitMsg{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type initCfgMsg struct{}
|
|
||||||
|
|
||||||
func initCfg() tea.Msg {
|
|
||||||
return initCfgMsg{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type parsedCfgMsg struct {
|
type parsedCfgMsg struct {
|
||||||
parsedConfig ParsedConfig
|
parsedConfig ParsedConfig
|
||||||
dryRun bool
|
dryRun bool
|
||||||
@@ -117,6 +121,10 @@ type errQuitMsg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *model) cleanUp() tea.Msg {
|
func (m *model) cleanUp() tea.Msg {
|
||||||
|
if len(m.Files) == 0 {
|
||||||
|
return tea.Quit()
|
||||||
|
}
|
||||||
|
|
||||||
fullFilePath := m.Files[len(m.Files)-1]
|
fullFilePath := m.Files[len(m.Files)-1]
|
||||||
fileName := filepath.Base(fullFilePath)
|
fileName := filepath.Base(fullFilePath)
|
||||||
|
|
||||||
@@ -124,7 +132,7 @@ func (m *model) cleanUp() tea.Msg {
|
|||||||
extensionIndex := strings.LastIndex(fileName, ".")
|
extensionIndex := strings.LastIndex(fileName, ".")
|
||||||
newFileName := fileName[:extensionIndex]
|
newFileName := fileName[:extensionIndex]
|
||||||
extension := fileName[extensionIndex:]
|
extension := fileName[extensionIndex:]
|
||||||
newFileFullPath := filepath.Join(parentDir, newFileName+fmt.Sprintf(" [%s] [%s]", m.ParsedConfig.VideoEncoder, m.ParsedConfig.AudioEncoder)+extension)
|
newFileFullPath := filepath.Join(parentDir, newFileName+fmt.Sprintf("_[%s]_[%s]", m.ParsedConfig.VideoEncoder, m.ParsedConfig.AudioEncoder)+extension)
|
||||||
|
|
||||||
os.Remove(newFileFullPath)
|
os.Remove(newFileFullPath)
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,25 @@ package main
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
var SupportedVideoEncoders = []string{
|
||||||
|
"libx264",
|
||||||
|
"libx265",
|
||||||
|
"libvpx-vp9",
|
||||||
|
"librav1e",
|
||||||
|
"libsvtav1",
|
||||||
|
}
|
||||||
|
|
||||||
|
var SupportedAudioEncoders = []string{
|
||||||
|
"aac",
|
||||||
|
"libopus",
|
||||||
|
"libvorbis",
|
||||||
|
}
|
||||||
|
|
||||||
var Configs = []Config{
|
var Configs = []Config{
|
||||||
{Name: "Delete old video(s)?", Opts: []string{"No", "Yes"}, FocusedOption: 1},
|
{Name: "Delete old video(s)?", Opts: []string{"No", "Yes"}, FocusedOption: 1},
|
||||||
{Name: "What should we do about encoded videos?", Opts: []string{"Skip", "Delete and encode again"}},
|
{Name: "What should we do about encoded videos?", Opts: []string{"Skip", "Delete and encode again"}},
|
||||||
{Name: "Video Encoder", Opts: []string{"copy", "libx264", "libx265", "libvpx-vp9", "librav1e", "libsvtav1"}},
|
{Name: "Video Encoder", Opts: []string{"copy"}},
|
||||||
{Name: "Audio Encoder", Opts: []string{"None", "copy", "aac", "libopus"}, FocusedOption: 1},
|
{Name: "Audio Encoder", Opts: []string{"None", "copy"}, FocusedOption: 1},
|
||||||
{Name: "Preset", Opts: []string{"ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"}, FocusedOption: 4},
|
{Name: "Preset", Opts: []string{"ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"}, FocusedOption: 4},
|
||||||
{Name: "Constant Rate Factor (CRF)", Opts: []string{"10", "15", "20", "25", "30", "35", "40", "45", "50"}, FocusedOption: 4},
|
{Name: "Constant Rate Factor (CRF)", Opts: []string{"10", "15", "20", "25", "30", "35", "40", "45", "50"}, FocusedOption: 4},
|
||||||
}
|
}
|
||||||
@@ -54,6 +68,16 @@ cfgloop:
|
|||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contains[T comparable](slice []T, elem T) bool {
|
||||||
|
for _, e := range slice {
|
||||||
|
if e == elem {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func getVisibleConfigs(cfgs []Config) []Config {
|
func getVisibleConfigs(cfgs []Config) []Config {
|
||||||
parsed := parseConfig(cfgs)
|
parsed := parseConfig(cfgs)
|
||||||
|
|
||||||
|
|||||||
@@ -92,9 +92,7 @@ func buildFFmpegCmdArgs(fullFilePath string, outFullFilePath string, cfg ParsedC
|
|||||||
args = append(args, cfg.AudioEncoder)
|
args = append(args, cfg.AudioEncoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range additionalArgs {
|
args = append(args, additionalArgs...)
|
||||||
args = append(args, arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output file
|
// Output file
|
||||||
args = append(args, outFullFilePath)
|
args = append(args, outFullFilePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user