Video Trim Endpoint
1. Overview
The https://api.revidapi.com/paid/video/trim endpoint is part of the Video API and allows users to trim a video by removing specified portions from the beginning and/or end. It also provides optional encoding settings to control the output video quality.
2. Endpoint
URL Path: https://api.revidapi.com/paid/video/trim
HTTP Method: POST
3. Request
Headers
x-api-key(required): The API key for authentication.
Body Parameters
video_url(required, string): The URL of the video file to be trimmed.start(optional, string): The start time for trimming in the formathh:mm:ssormm:ss.end(optional, string): The end time for trimming in the formathh:mm:ssormm:ss.video_codec(optional, string): The video codec to be used for encoding the output video. Default islibx264.video_preset(optional, string): The video preset to be used for encoding the output video. Default ismedium.video_crf(optional, number): The Constant Rate Factor (CRF) value for video encoding, ranging from 0 to 51. Default is 23.audio_codec(optional, string): The audio codec to be used for encoding the output video. Default isaac.audio_bitrate(optional, string): The audio bitrate to be used for encoding the output video. Default is128k.webhook_url(optional, string): The URL to receive a webhook notification upon completion of the task.id(optional, string): A unique identifier for the request.
The validate_payload directive in the routes file ensures that the request payload adheres to the specified schema, which includes the required and optional parameters, their data types, and any additional constraints.
Example Request
{
"video_url": "https://example.com/video.mp4",
"start": "00:01:00",
"end": "00:03:00",
"video_codec": "libx264",
"video_preset": "faster",
"video_crf": 28,
"audio_codec": "aac",
"audio_bitrate": "128k",
"webhook_url": "https://example.com/webhook",
"id": "unique-request-id"
}
curl -X POST \
https://api.revidapi.com/paid/video/trim \
-H 'x-api-key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"video_url": "https://example.com/video.mp4",
"start": "00:01:00",
"end": "00:03:00",
"video_codec": "libx264",
"video_preset": "faster",
"video_crf": 28,
"audio_codec": "aac",
"audio_bitrate": "128k",
"webhook_url": "https://example.com/webhook",
"id": "unique-request-id"
}'
4. Response
Success Response
The success response follows the general response structure defined in the app.py file. Here's an example:
{
"endpoint": "/v1/video/trim",
"code": 200,
"id": "unique-request-id",
"job_id": "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
"response": "https://example.com/trimmed-video.mp4",
"message": "success",
"pid": 12345,
"queue_id": 6789,
"run_time": 5.234,
"queue_time": 0.123,
"total_time": 5.357,
"queue_length": 0,
"build_number": "1.0.0"
}
Error Responses
- 400 Bad Request: Returned when the request payload is missing or contains invalid parameters.
{
"code": 400,
"message": "Invalid request payload"
}
- 401 Unauthorized: Returned when the
x-api-keyheader is missing or invalid.
{
"code": 401,
"message": "Unauthorized"
}
- 500 Internal Server Error: Returned when an unexpected error occurs during the video trimming process.
{
"code": 500,
"message": "An error occurred during the video trimming process"
}
5. Error Handling
The endpoint handles common errors such as missing or invalid parameters by returning appropriate HTTP status codes and error messages. The validate_payload decorator ensures that the request payload adheres to the specified schema, and any violations will result in a 400 Bad Request error.
The main application context (app.py) includes error handling for the task queue. If the maximum queue length is reached, the endpoint will return a 429 Too Many Requests error with a corresponding message.
6. Usage Notes
- The
startandendparameters are optional, but at least one of them must be provided to perform the trimming operation. - The
video_codec,video_preset,video_crf,audio_codec, andaudio_bitrateparameters are optional and allow users to customize the encoding settings for the output video. - The
webhook_urlparameter is optional and can be used to receive a notification when the task is completed. - The
idparameter is optional and can be used to uniquely identify the request.
7. Common Issues
- Providing an invalid or inaccessible
video_url. - Specifying invalid or unsupported values for the encoding parameters (
video_codec,video_preset,video_crf,audio_codec,audio_bitrate). - Encountering issues with the video trimming process due to unsupported video formats or corrupted files.
8. Best Practices
- Validate the
video_urlparameter to ensure it points to a valid and accessible video file. - Use appropriate encoding settings based on the desired output quality and file size requirements.
- Implement error handling and retry mechanisms for failed requests or network issues.
- Monitor the task queue length and adjust the
MAX_QUEUE_LENGTHvalue accordingly to prevent overloading the system. - Implement rate limiting or throttling mechanisms to prevent abuse or excessive requests.