package api import ( "context" "os/exec" "path/filepath" "strings" "testing" ) func TestBatchDecoderMatchesSingleDecoderFrameContent(t *testing.T) { f, root := annotationProcessorFixture(t) _ = f source := filepath.Join(root, "left.mp4") cuts := []annotationFrameSlice{{0, 9, filepath.Join(root, "batch-a.mp4")}, {9, 24, filepath.Join(root, "batch-b.mp4")}, {24, 32, filepath.Join(root, "batch-c.mp4")}} if e := writeFrameAccurateSlices(context.Background(), source, cuts); e != nil { t.Fatal(e) } frames := func(path string) string { out, e := exec.Command("ffmpeg", "-v", "error", "-i", path, "-f", "framemd5", "-").Output() if e != nil { t.Fatal(e) } lines := []string{} for _, line := range strings.Split(string(out), "\n") { if line != "" && !strings.HasPrefix(line, "#") { lines = append(lines, line) } } return strings.Join(lines, "\n") } for i, c := range cuts { single := filepath.Join(root, []string{"single-a.mp4", "single-b.mp4", "single-c.mp4"}[i]) if e := writeFrameAccurateSlice(context.Background(), source, single, c.Start, c.End); e != nil { t.Fatal(e) } if frames(single) != frames(c.Output) { t.Fatalf("batch changed decoded frame content for %d", i) } } }