1
0
mirror of https://github.com/coalaura/ffwebp.git synced 2025-09-08 05:49:54 +00:00
This commit is contained in:
Laura
2025-08-13 04:01:33 +02:00
parent 210ac5a42b
commit ffc5e117ee

View File

@@ -199,6 +199,10 @@ func run(_ context.Context, cmd *cli.Command) error {
}
}
if len(inputs) == 1 {
return processOne(inputs[0], outputs[0], cmd, &common, nil)
}
threads := cmd.Int("threads")
if threads <= 0 {
@@ -207,6 +211,8 @@ func run(_ context.Context, cmd *cli.Command) error {
threads = min(threads, len(inputs))
logx.Printf("using %d threads\n", threads)
type job struct {
i int
}
@@ -219,27 +225,19 @@ func run(_ context.Context, cmd *cli.Command) error {
for w := 0; w < threads; w++ {
go func() {
for j := range jobs {
var logger *bytes.Buffer
if threads > 1 {
logger = bytes.NewBuffer(nil)
}
var logger bytes.Buffer
in := inputs[j.i]
out := outputs[j.i]
local := common
if err := processOne(in, out, cmd, &local, logger); err != nil {
if err := processOne(in, out, cmd, &common, &logger); err != nil {
errs <- fmt.Errorf("%s -> %s: %w", filepath.ToSlash(in), filepath.ToSlash(out), err)
} else {
errs <- nil
}
if threads > 1 {
logx.Print(logger.String())
}
}
}()
}