Tutorials · 4 min read

Clip your videos

How to create a video clip with api.video

Clipping is an easy way to capture short segments of on-demand videos or recorded live streams. Learn how to upload a smaller clip from a video using the api.video Python client.

Erikka Innes

January 20, 2022

Sometimes you just want to upload a smaller piece of a video you have, but you don't want to take the time to edit it with FFMPEG or FinalCut Pro. If you just need a shorter clip and you know the start and end timecode, you can use api.video's clip feature. Today we'll walk through how to upload a clip from a video you have on your computer and how to take a clip from an online, publicly available mp4 link or a video you have stored with api.video.

# Pre-requisites

For this tutorial, you will need:

Installation

Install api.video's Python client with pip install api.video

Code sample for uploading a clip from a video on your computer

Our code sample today is this:

python

Video clip code walkthrough

What we'll be doing is a normal video upload. If you're new to uploads, with api.video it's a two step process. First you create a video container with all your metadata, and in this case, you'll also include the information needed to clip your video. Then you retrieve the video ID and use that to upload your video into the container. In this case, you will upload just the video clip into the container. When you're done, you'll have a new, shortened clip to display.

  1. First initialize the client and VideoApi and connect.

`client = apivideo.AuthenticatedApiClient("your API key here")

client.connect()

videos_api = VideosApi(client)`

  1. Prepare the video payload with metadata that you'll use as the container.

video_create_payload = { "title": "My sample clip from a new source", "description": "test", "clip": { "start_timecode": "1", "end_timecode": "2", }, }

  1. Send a request with your payload to create the new video container, and retrieve the video ID.

` response = videos_api.create(video_create_payload) print("Video Container", response)

video_id = response["video_id"] `

  1. Now it's time to upload your video. Open your video file in binary to get it ready to send, then send a request to upload it.

` file = open("test_vid45.mp4", "rb") video_response = videos_api.upload(video_id, file)

print("Uploaded Video", video_response)`

You can check your dashboard to see that you've successfully uploaded a short video clip!

Upload a clip from a link or video source

To take a clip from an online .mp4 link or a video source you have with api.video is easier than the process we just walked through. All you need to do is create a video and the clip will be created for you. If you use a link, make sure it's a .mp4 link. You can't, for example, grab a YouTube link and get a clip from that.

If you're uploading a clip from an online .mp4 source, you specify the complete link, as a string for the source parameter. And if you're uploading a clip from a video you have stored with api.video, you can specify the video ID for the video you want to grab a clip from.

In the example, I've put an .mp4 link in for the source. You don't need to do the second step that we did in the earlier walkthrough. Everything is handled with one call to the api.video API.

python

Conclusion

Video clipping is great in situations where you wanted to grab one or more clips from a longer video, or you just wanted to edit a bit of content off the front and end of your video clip. Now, it's possible to do with the api.video API. Find all the information in our Docs (in the "Body params" section) or ask questions in our Community. Happy building!

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.

Affordable

Volume discounts and usage-based pricing to ensure you don’t exceed your budget.