Skip to content

Commit

Permalink
@remotion/renderer: New attempt for better BT.709 color space conve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
JonnyBurger committed May 11, 2024
1 parent 0d231ec commit acc84f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
Binary file added packages/example/frameroriginal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/example/public/blue.mp4
Binary file not shown.
32 changes: 4 additions & 28 deletions packages/example/src/Framer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Audio, random, Sequence, staticFile, useCurrentFrame} from 'remotion';
import {AbsoluteFill, OffthreadVideo, random, staticFile} from 'remotion';

export function selectColor(color: string, frame: number): number {
return Math.floor((random(`${color}-${frame}`) * 255) % 255);
Expand All @@ -7,33 +7,9 @@ export function selectColor(color: string, frame: number): number {
export const Framer: React.FC<{
playbackRate?: number;
}> = ({playbackRate}) => {

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / SSR integration

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Lambda integration

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Build Node 16 on ubuntu-latest

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Linting + Formatting

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Build Node 16 on windows-latest

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Build Node 16 on macos-latest

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Build Node 16 on macos-14

'playbackRate' is declared but its value is never read.

Check failure on line 9 in packages/example/src/Framer/index.tsx

View workflow job for this annotation

GitHub Actions / Build Node 20.5 on ubuntu-latest

'playbackRate' is declared but its value is never read.
const frame = useCurrentFrame();

const red = selectColor('red', frame);
const green = selectColor('green', frame);
const blue = selectColor('blue', frame);

return (
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
background: 'white',
flex: 1,
borderTop: `100px solid rgb(${red}, ${green}, ${blue})`,
paddingBottom: 100,
}}
>
<h1 style={{fontSize: 120}}>{frame} 😁</h1>
<Sequence from={30}>
<Audio
startFrom={60}
volume={(f) => (Math.sin(f / 4) + 1) / 2}
playbackRate={playbackRate ?? 1}
src={staticFile('chirp.wav')}
/>
</Sequence>
</div>
<AbsoluteFill style={{backgroundColor: '#00BDF2'}}>
<OffthreadVideo style={{height: 400}} src={staticFile('blue.mp4')} />
</AbsoluteFill>
);
};
22 changes: 17 additions & 5 deletions packages/renderer/rust/scalable_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::usize;

use ffmpeg_next::{
color,
format::Pixel,
ffi::sws_getCoefficients,
format::{self, Pixel},
frame::{self, Video},
software::scaling::{Context, Flags},
software::scaling::{ColorSpace, Context, Flags},
};

use crate::{
Expand Down Expand Up @@ -204,15 +205,26 @@ pub fn scale_and_make_bitmap(
native_frame.scaled_width,
native_frame.scaled_height,
// FFmpeg also uses BICUBIC by default when extracting a frame
Flags::BICUBIC,
Flags::BILINEAR,
)?;

_print_verbose(&format!(
"Scaling from {}x{} to {}x{} colorspace: {:?} range: {:?}",
native_frame.original_width,
native_frame.original_height,
native_frame.scaled_width,
native_frame.scaled_height,
native_frame.colorspace,
native_frame.src_range,
))?;

scaler.set_colorspace_details(
native_frame.colorspace,
native_frame.src_range,
color::Range::JPEG,
0,
0,
0,
1 << 16,
1 << 16,
)?;

let mut data: Vec<*const u8> = Vec::with_capacity(planes.len());
Expand Down

0 comments on commit acc84f6

Please sign in to comment.