Repository navigation
fix(engine): passthrough keeps frame count and accepts films whose audio outlasts the picture #6920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8725c8e
fix(engine): passthrough output follows the page frames and holds a s…
miguel-heygen 88f065c
test(engine): a film whose audio outlasts its video still qualifies f…
miguel-heygen 15294c6
test(engine): passthrough encodes one output frame per page frame whe…
miguel-heygen 5294ff7
test(engine): end the ffprobe options before the file in the passthro…
miguel-heygen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
| import { mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { toFps } from "@hyperframes/core"; | ||
| import { buildVideoLayerInput } from "./videoFrameExtractor.js"; | ||
| import { spawnStreamingEncoder } from "./streamingEncoder.js"; | ||
|
|
||
| const HAS_FFMPEG = spawnSync("ffmpeg", ["-version"]).status === 0; | ||
|
|
||
| describe.skipIf(!HAS_FFMPEG)( | ||
| "buildVideoLayerInput on a film whose audio outlasts its video", | ||
| () => { | ||
| let dir = ""; | ||
| let film = ""; | ||
| beforeAll(() => { | ||
| dir = mkdtempSync(join(tmpdir(), "video-layer-input-")); | ||
| film = join(dir, "film.mp4"); | ||
| const made = spawnSync("ffmpeg", [ | ||
| ...["-f", "lavfi", "-i", "testsrc=d=2:s=64x64:r=30"], | ||
| ...["-f", "lavfi", "-i", "sine=d=2.4"], | ||
| ...["-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-y", film], | ||
| ]); | ||
| expect(made.status).toBe(0); | ||
| }); | ||
| afterAll(() => rmSync(dir, { recursive: true, force: true })); | ||
|
|
||
| it("accepts it, holds the last frame and leaves the output length to the page frames", async () => { | ||
| const layer = await buildVideoLayerInput(film, 0, 2.4, toFps(30), { width: 64, height: 64 }); | ||
| expect(layer).toBeDefined(); | ||
| expect(layer?.inputArgs).not.toContain("-t"); | ||
| expect(layer?.filters.at(-1)).toMatch(/^tpad=stop_mode=clone:stop_duration=/); | ||
| }); | ||
| it("encodes exactly one output frame per page frame when the video is shorter", async () => { | ||
| const pageFrames = 74; | ||
| const framesDir = join(dir, "page"); | ||
| spawnSync("mkdir", ["-p", framesDir]); | ||
| const drew = spawnSync("ffmpeg", [ | ||
| ...["-f", "lavfi", "-i", `color=c=red@0.5:s=64x64:r=30,format=rgba`], | ||
| ...["-frames:v", String(pageFrames), "-y", join(framesDir, "p%03d.png")], | ||
| ]); | ||
| expect(drew.status).toBe(0); | ||
| const layer = await buildVideoLayerInput(film, 0, 2.4387, toFps(30), { | ||
| width: 64, | ||
| height: 64, | ||
| }); | ||
| expect(layer).toBeDefined(); | ||
| const out = join(dir, "out.mp4"); | ||
| const encoder = await spawnStreamingEncoder(out, { | ||
| fps: toFps(30), | ||
| width: 64, | ||
| height: 64, | ||
| codec: "h264", | ||
| imageFormat: "png", | ||
| videoLayer: layer, | ||
| }); | ||
| for (const name of readdirSync(framesDir).sort()) { | ||
| expect(await encoder.writeFrame(readFileSync(join(framesDir, name)))).toBe(true); | ||
| } | ||
| await encoder.close(); | ||
| const counted = spawnSync("ffprobe", [ | ||
| ...["-v", "error", "-count_frames", "-select_streams", "v:0"], | ||
| ...["-show_entries", "stream=nb_read_frames", "-of", "csv=p=0", "--", out], | ||
| ]); | ||
| expect(Number(counted.stdout.toString().trim())).toBe(pageFrames); | ||
| }); | ||
| }, | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.