mirror of
https://github.com/IllusionMan1212/ffui.git
synced 2026-10-24 18:12:35 +00:00
Compare commits
3
Commits
46b3ec95bd
...
ce907e1079
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce907e1079
|
||
|
|
b80726c870
|
||
|
|
5edf4f35ad
|
@@ -34,6 +34,7 @@ type model struct {
|
|||||||
SingleFileProgress float64
|
SingleFileProgress float64
|
||||||
TotalProgressBar progress.Model
|
TotalProgressBar progress.Model
|
||||||
TotalProgress float64
|
TotalProgress float64
|
||||||
|
Estimate int
|
||||||
Program *tea.Program
|
Program *tea.Program
|
||||||
Quitting bool
|
Quitting bool
|
||||||
Screen Screen
|
Screen Screen
|
||||||
@@ -186,6 +187,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
totalProgressCmd := m.TotalProgressBar.SetPercent(m.TotalProgress)
|
totalProgressCmd := m.TotalProgressBar.SetPercent(m.TotalProgress)
|
||||||
|
|
||||||
return m, tea.Batch(singleProgressCmd, totalProgressCmd)
|
return m, tea.Batch(singleProgressCmd, totalProgressCmd)
|
||||||
|
case updateEstimate:
|
||||||
|
m.Estimate = msg.estimate
|
||||||
case quitMsg:
|
case quitMsg:
|
||||||
m.Quitting = true
|
m.Quitting = true
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
@@ -265,11 +268,34 @@ func MainScreenView(m model) string {
|
|||||||
m.SingleFileProgressBar.View())
|
m.SingleFileProgressBar.View())
|
||||||
}
|
}
|
||||||
|
|
||||||
view := fmt.Sprintf("\nEncoding \"%s\"...\n%s", m.CurrentFileName, progress)
|
eta := formatEstimate(m.Estimate)
|
||||||
|
|
||||||
|
view := fmt.Sprintf("\nEncoding \"%s\"... ETA: %s\n%s", m.CurrentFileName, eta, progress)
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatEstimate(estimate int) string {
|
||||||
|
if estimate >= 86400 {
|
||||||
|
day := estimate / 86400
|
||||||
|
hour := (estimate % 86400) / 3600
|
||||||
|
min := (estimate % 3600) / 60
|
||||||
|
sec := estimate % 60
|
||||||
|
return fmt.Sprintf("%dd%dh%dm%ds", day, hour, min, sec)
|
||||||
|
} else if estimate >= 3600 {
|
||||||
|
hour := estimate / 3600
|
||||||
|
min := (estimate % 3600) / 60
|
||||||
|
sec := estimate % 60
|
||||||
|
return fmt.Sprintf("%dh%dm%ds", hour, min, sec)
|
||||||
|
} else if estimate >= 60 {
|
||||||
|
min := estimate / 60
|
||||||
|
sec := estimate % 60
|
||||||
|
return fmt.Sprintf("%dm%ds", min, sec)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%ds", estimate)
|
||||||
|
}
|
||||||
|
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
if m.Quitting {
|
if m.Quitting {
|
||||||
if m.DryRun {
|
if m.DryRun {
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ type finishedEncodingVideo struct{}
|
|||||||
type updateProgress struct {
|
type updateProgress struct {
|
||||||
progress float64
|
progress float64
|
||||||
}
|
}
|
||||||
|
type updateEstimate struct {
|
||||||
|
estimate int
|
||||||
|
}
|
||||||
|
|
||||||
type initUi struct {
|
type initUi struct {
|
||||||
fileCount int
|
fileCount int
|
||||||
|
|||||||
@@ -79,11 +79,8 @@ func encode(fullFilePath string, fileName string, teaP *tea.Program, cfg ParsedC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
quotedFilePath := fmt.Sprintf("\"%s\"", fullFilePath)
|
err = ffmpeg.Input(fullFilePath).
|
||||||
quotedNewFilePath := fmt.Sprintf("\"%s\"", newFileFullPath)
|
Output(newFileFullPath, ffmpeg.KwArgs{
|
||||||
|
|
||||||
err = ffmpeg.Input(quotedFilePath).
|
|
||||||
Output(quotedNewFilePath, ffmpeg.KwArgs{
|
|
||||||
"c:v": cfg.VideoEncoder,
|
"c:v": cfg.VideoEncoder,
|
||||||
"crf": cfg.CRF,
|
"crf": cfg.CRF,
|
||||||
"preset": cfg.Preset,
|
"preset": cfg.Preset,
|
||||||
|
|||||||
+17
@@ -42,6 +42,8 @@ func TempSock(totalDuration float64, teaP *tea.Program) string {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
re := regexp.MustCompile(`out_time_ms=(\d+)`)
|
re := regexp.MustCompile(`out_time_ms=(\d+)`)
|
||||||
|
speedRe := regexp.MustCompile(`speed=(\d+\.\d+x)`)
|
||||||
|
|
||||||
fd, err := l.Accept()
|
fd, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("accept error:", err)
|
log.Fatal("accept error:", err)
|
||||||
@@ -49,6 +51,8 @@ func TempSock(totalDuration float64, teaP *tea.Program) string {
|
|||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
data := ""
|
data := ""
|
||||||
progress := ""
|
progress := ""
|
||||||
|
estimate := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_, err := fd.Read(buf)
|
_, err := fd.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -78,6 +82,19 @@ func TempSock(totalDuration float64, teaP *tea.Program) string {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
speedMatch := speedRe.FindString(data)
|
||||||
|
if len(speedMatch) > 0 {
|
||||||
|
trimmedSpeed := strings.TrimSuffix(strings.Split(speedMatch, "=")[1], "x")
|
||||||
|
speed, _ := strconv.ParseFloat(trimmedSpeed, 32)
|
||||||
|
progressFloat, _ := strconv.ParseFloat(progress, 64)
|
||||||
|
remainingDuration := totalDuration - (totalDuration * progressFloat)
|
||||||
|
estimate = int(remainingDuration / speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
teaP.Send(updateEstimate{
|
||||||
|
estimate: estimate,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user