132 lines
3.4 KiB
Markdown

# Video Watermark API Usage Guide
## Overview
The Video Watermark API allows you to add watermarks to video files asynchronously. The process involves two steps:
1. Submit a watermark job and receive a token
2. Use the token to check the job status and get the result
## Base URL
```
https://animator-gg-api.ca2324.servep2p.com:8443
```
## Step 1: Submit a Video Watermark Job
**Request:**
```bash
curl -X POST "https://animator-gg-api.ca2324.servep2p.com:8443/api/script" \
-H "Content-Type: application/json" \
-d '{
"scriptPath": "/tmp/api_scripts/video_add_watermark.sh",
"args": [
"https://example.com/input.mp4",
"https://example.com/watermark.png",
"30",
"30"
]
}'
```
**Parameters:**
- `scriptPath`: Must be video_add_watermark.sh
- `args`: Array containing:
- Input video URL (required)
- Watermark image URL (required)
- X position in pixels (required)
- Y position in pixels (required)
- Width for watermark resize (optional, 0 for no resize)
- Height for watermark resize (optional, 0 for no resize)
**Response:**
```json
{
"token": "550e8400-e29b-41d4-a716-446655440000"
}
```
## Step 2: Check Job Status and Get Result
**Request:**
```bash
curl -X GET "https://animator-gg-api.ca2324.servep2p.com:8443/api/script?token=550e8400-e29b-41d4-a716-446655440000"
```
**Response:**
```json
{
"status": "completed",
"result": {
"success": true,
"stdout": "{\n \"input_video_url\": \"https://example.com/input.mp4\",\n \"watermark_png_url\": \"https://example.com/watermark.png\", \n \"pos_x\": 30,\n \"pos_y\": 30,\n \"size_w\": 0,\n \"size_h\": 0,\n \"output_file_name\": \"/var/www/html/watermarked_videos/bcc55e77-f1b4-472c-8a1b-0f3c852bd73a.mp4\",\n \"output_file_url\": \"https://example.com/watermarked_videos/bcc55e77-f1b4-472c-8a1b-0f3c852bd73a.mp4\"\n}",
"stderr": "..."
},
"timestamp": 1743991194237
}
```
When the job is complete, the `stdout` field will contain a JSON string with the output video URL. You'll need to parse this string to get the actual URL.
## Example: Complete Process
1. **Submit the job:**
```bash
TOKEN=$(curl -s -X POST "https://animator-gg-api.ca2324.servep2p.com:8443/api/script" \
-H "Content-Type: application/json" \
-d '{
"scriptPath": "/tmp/api_scripts/video_add_watermark.sh",
"args": [
"https://ca2324.ddns.net:8443/jerry/_seed847064922.mp4",
"https://ca2324.ddns.net:8443/jerry/0a97d84a70fec3991cf05ee99ceb6469.png",
"30",
"30"
]
}' | jq -r '.token')
echo "Job submitted with token: $TOKEN"
```
2. **Check status until complete:**
```bash
while true; do
RESULT=$(curl -s -X GET "https://animator-gg-api.ca2324.servep2p.com:8443/api/script?token=$TOKEN")
STATUS=$(echo $RESULT | jq -r '.status')
echo "Status: $STATUS"
if [ "$STATUS" = "completed" ] || [ "$STATUS" = "failed" ]; then
break
fi
sleep 2
done
# Extract the watermarked video URL
if [ "$STATUS" = "completed" ]; then
OUTPUT_JSON=$(echo $RESULT | jq -r '.result.stdout')
OUTPUT_URL=$(echo $OUTPUT_JSON | jq -r '.output_file_url')
echo "Watermarked video URL: $OUTPUT_URL"
fi
```
## Status Codes
- `pending`: Job is waiting in the queue
- `running`: Job is currently processing
- `completed`: Job finished successfully
- `failed`: Job failed to complete
## Notes
- Results are stored for 24 hours after completion
- Processing large videos may take several minutes
- The API is rate-limited to 2 concurrent jobs