mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
* Refactor transcode generation * Move phash generation into separate package * Refactor image thumbnail generation * Move JSONTime to separate package * Ffmpeg refactoring * Refactor live transcoding * Refactor scene marker preview generation * Refactor preview generation * Refactor screenshot generation * Refactor sprite generation * Change ffmpeg.IsStreamable to return error * Move frame rate calculation into ffmpeg * Refactor file locking * Refactor title set during scan * Add missing lockmanager instance * Return error instead of logging in MatchContainer
43 lines
999 B
Go
43 lines
999 B
Go
package ffmpeg
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// Generate runs ffmpeg with the given args and waits for it to finish.
|
|
// Returns an error if the command fails. If the command fails, the return
|
|
// value will be of type *exec.ExitError.
|
|
func (f FFMpeg) Generate(ctx context.Context, args Args) error {
|
|
cmd := f.Command(ctx, args)
|
|
|
|
var stderr bytes.Buffer
|
|
cmd.Stderr = &stderr
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
return fmt.Errorf("error starting command: %w", err)
|
|
}
|
|
|
|
if err := cmd.Wait(); err != nil {
|
|
var exitErr *exec.ExitError
|
|
if errors.As(err, &exitErr) {
|
|
exitErr.Stderr = stderr.Bytes()
|
|
err = exitErr
|
|
}
|
|
return fmt.Errorf("error running ffmpeg command <%s>: %w", strings.Join(args, " "), err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GenerateOutput runs ffmpeg with the given args and returns it standard output.
|
|
func (f FFMpeg) GenerateOutput(ctx context.Context, args []string) ([]byte, error) {
|
|
cmd := f.Command(ctx, args)
|
|
|
|
return cmd.Output()
|
|
}
|