Sources

Clip Videos

View Markdown

You can use the duration, start, and end props to trim your videos and create clips.

This is super useful for creating previews, clips for social media, or capping your users' uploads to a specific duration.


Clip the first 60 seconds

If you only provide a duration prop, the video will start at the beginning and end at the specified time.

const task = await ittybit.tasks.create({
  kind: 'video',
  url: 'https://ittyb.it/sample.mp4',
  duration: 60,
});

(See SDKs for install and initialization steps.)


Clip a specific section

You can combine duration with the start prop to clip a specific section of the video. This can be useful if every video has an identical intro that you want to skip before starting your preview clip.

const task = await ittybit.tasks.create({
  kind: 'video',
  url: 'https://ittyb.it/sample.mp4',
  start: 12.34,
  duration: 60,
});

Clip the last 60 seconds

If you provide only a start prop, then the video will start at the specified time and end at the end of the video.

So if you wanted to output the last 60 seconds of each video, then you could use the input file's duration prop to calculate the required start value.

const startTime = input.duration - 60;

const task = await ittybit.tasks.create({
  kind: 'video',
  url: 'https://ittyb.it/sample.mp4',
  start: startTime,
});

Set specific start and end times

If you provide both a start and end prop, the video will start at the specified time and end at the specified time.

You might combine this with the output from Intelligence features like Speech or Outline to create a clips based on natural breaks in the content.

const task = await ittybit.tasks.create({
  kind: 'video',
  url: 'https://ittyb.it/sample.mp4',
  start: 12.34,
  end: 56.78,
});

In the example above, it'd be a good idea to use the filename, folder, and ref props to make the clips easily accessible.

const chapters = [
  {
    index: 0,
    start: 12.34,
    end: 56.78,
    text: 'Mr Miyamoto introduces his newest game',
  },
  // ... other chapters
]

const tasks = chapters.map(chapter => ittybit.tasks.create({
  kind: 'video',
  file_id: input.id,
  start: chapter.start,
  end: chapter.end,
  filename: `clip-${chapter.index}.mp4`,
  folder: input.folder,
  ref: chapter.ref,
  metadata: {
    index: chapter.index,
    description: chapter.text,
  },
}));

On this page