Skip to content

Subtitles track experiment #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/components/SubtitlesTrack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {FC} from 'react';

import {Sequence} from 'remotion';
import {SubtitleTrackRenderDescription} from '../utils/renderDescriptionSchema';

export const SubtitlesTrack: FC<SubtitleTrackRenderDescription> = (track) => {
return (
<Sequence name={track.id}>
{track.assets.map((asset) => {
console.log(asset);
return null; // TODO: Implement this
})}
</Sequence>
);
};
5 changes: 5 additions & 0 deletions src/components/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import {Sequence} from 'remotion';
import {RenderDescription} from '../utils/renderDescriptionSchema';
import {AudioTrack} from './AudioTrack';
import {VideoTrack} from './VideoTrack';
import {SubtitlesTrack} from './SubtitlesTrack';

export const Timeline: FC<RenderDescription> = (renderDescription) => {
return (
<Sequence name="main-timeline">
{renderDescription.timeline.tracks.subtitles.map((subtitleTrack) => (
<SubtitlesTrack {...subtitleTrack} key={subtitleTrack.id} />
))}

{renderDescription.timeline.tracks.video.map((videoTrack) => (
<VideoTrack {...videoTrack} key={videoTrack.id} />
))}
Expand Down
11 changes: 10 additions & 1 deletion src/utils/renderDescriptionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ const AudioTrackSchema = z.object({
assets: z.array(AudioAssetSchema),
});

const SubtitlesTrackSchema = z.object({
id: z.string(),
index: z.number(),
assets: z.array(z.object({})),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assets property in SubtitlesTrackSchema is defined as an array of empty objects. If this is intentional and you plan to allow any properties on these objects, consider using z.object({}).nonstrict() instead of z.object({}) to explicitly allow additional properties.

});
Comment on lines 59 to +66
Copy link

@coderabbitai coderabbitai bot Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SubtitlesTrackSchema currently has an assets property which is an array of empty objects. This might be a placeholder for now, but it's important to define the structure of these objects to ensure data consistency and type safety. Consider creating a SubtitleAssetSchema similar to AudioAssetSchema or VideoAssetSchema that defines the properties of a subtitle asset.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you change that? Make a change proposal

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alfonsograziano, I propose the following changes to define a SubtitleAssetSchema that can be used in the SubtitlesTrackSchema. This will ensure type safety and data consistency for subtitle assets.

+const SubtitleAssetSchema = z.object({
+	id: z.string(),
+	startTime: z.number(),
+	endTime: z.number(),
+	text: z.string(),
+});

const SubtitlesTrackSchema = z.object({
	id: z.string(),
	index: z.number(),
-	assets: z.array(z.object({})),
+	assets: z.array(SubtitleAssetSchema),
});

In this proposal, each subtitle asset has an id, startTime, endTime, and text. The startTime and endTime represent the time range during which the subtitle should be displayed, and text is the actual subtitle text. Please adjust these fields as necessary to match your application's requirements.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you implement that and do a commit to the repo?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alfonsograziano, I'm an AI developed by OpenAI and currently, I don't have the capability to directly commit changes to a repository. However, you can use the proposed changes in your local environment and commit them yourself. Here's how you can do it:

  1. Open the renderDescriptionSchema.ts file in your code editor.
  2. Add the SubtitleAssetSchema definition:
const SubtitleAssetSchema = z.object({
	id: z.string(),
	startTime: z.number(),
	endTime: z.number(),
	text: z.string(),
});
  1. Update the assets property in SubtitlesTrackSchema to use SubtitleAssetSchema:
const SubtitlesTrackSchema = z.object({
	id: z.string(),
	index: z.number(),
	assets: z.array(SubtitleAssetSchema),
});
  1. Save the changes.
  2. Commit the changes with a descriptive message, for example: "Define SubtitleAssetSchema and use it in SubtitlesTrackSchema".
  3. Push the commit to your repository.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.


const TimelineSchema = z.object({
tracks: z.object({
video: z.array(VideoTrackSchema),
audio: z.array(AudioTrackSchema),
subtitles: z.array(z.object({}).nonstrict()),
subtitles: z.array(SubtitlesTrackSchema),
}),
});

Expand All @@ -81,6 +87,9 @@ export type RenderDescription = z.infer<typeof MainSchema>;

export type AudioTrackRenderDescription = z.infer<typeof AudioTrackSchema>;
export type VideoTrackRenderDescription = z.infer<typeof VideoTrackSchema>;
export type SubtitleTrackRenderDescription = z.infer<
typeof SubtitlesTrackSchema
>;

export type TextAssetSchemaRenderDescription = z.infer<typeof TextAssetSchema>;
export type AssetSchemaRenderDescription = z.infer<typeof AssetSchema>;
Expand Down