weee
This commit is contained in:
@@ -77,7 +77,11 @@ func (s *Store) ExtractEmbedded(ctx context.Context, mediaPath string, streamInd
|
||||
"-map", fmt.Sprintf("0:%d", streamIndex),
|
||||
"-frames:v", "1",
|
||||
"-c:v", "copy",
|
||||
"--", tmp.Name(),
|
||||
// Temporary files deliberately have a neutral .img suffix. Tell
|
||||
// ffmpeg which muxer to use instead of asking it to infer one from
|
||||
// that suffix. ffmpeg does not accept `--` as an end-of-options
|
||||
// marker, so including it here made every embedded-art request fail.
|
||||
"-f", "image2", tmp.Name(),
|
||||
)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
os.Remove(tmp.Name())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package coverart
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/jpeg"
|
||||
@@ -9,6 +10,33 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExtractEmbeddedSuppliesExplicitOutputFormat(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
argsPath := filepath.Join(dir, "args")
|
||||
fakeFFmpeg := filepath.Join(dir, "ffmpeg")
|
||||
script := "#!/bin/sh\nprintf '%s\\n' \"$@\" > \"$ARGS_PATH\"\n"
|
||||
if err := os.WriteFile(fakeFFmpeg, []byte(script), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("ARGS_PATH", argsPath)
|
||||
|
||||
store := New(dir, fakeFFmpeg)
|
||||
path, err := store.ExtractEmbedded(context.Background(), filepath.Join(dir, "song.mp3"), 2)
|
||||
if err != nil {
|
||||
t.Fatalf("ExtractEmbedded: %v", err)
|
||||
}
|
||||
defer os.Remove(path)
|
||||
|
||||
args, err := os.ReadFile(argsPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := string(args)
|
||||
if got != "-y\n-v\nerror\n-i\n"+filepath.Join(dir, "song.mp3")+"\n-map\n0:2\n-frames:v\n1\n-c:v\ncopy\n-f\nimage2\n"+path+"\n" {
|
||||
t.Fatalf("unexpected ffmpeg arguments:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func writeTestJPEG(t *testing.T, path string, w, h int) {
|
||||
t.Helper()
|
||||
img := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
|
||||
Reference in New Issue
Block a user