> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trackyard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Video Generation Pipelines

> Integrate licensed music directly into AI video workflows

AI video generation platforms like Sora, Runway, and custom pipelines produce content at scale. Trackyard provides instant music licensing as a single API call — no manual clearance bottleneck.

***

## The Challenge

Traditional workflow:

1. Generate 100 videos via AI
2. Manually search for music for each video
3. License each track separately
4. Download and merge audio manually

**Problem:** The music licensing step becomes the slowest part of the pipeline.

***

## The Trackyard Solution

Integrate `/search` → `/download-track` directly into your video generation pipeline:

```python theme={null}
# Generate video
video = sora.generate("A sunset over mountains")

# Get licensed music automatically
tracks = trackyard.search("cinematic ambient music for nature video")
audio = trackyard.download(tracks[0]["id"], duration_seconds=video.duration)

# Merge and export
final_video = merge(video, audio)
```

**One workflow, end-to-end.**

***

## Integration Example

```python theme={null}
import requests
import subprocess

API_KEY = "your_api_key"
BASE = "https://api.trackyard.com/api/external/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

def add_music_to_video(video_path, query, output_path):
    # 1. Get video duration
    duration = get_video_duration(video_path)  # via ffprobe
    
    # 2. Search for music
    search = requests.post(
        f"{BASE}/search",
        headers=HEADERS,
        json={"query": query, "limit": 1}
    ).json()
    
    track_id = search["tracks"][0]["id"]
    
    # 3. Download music (trimmed to match video)
    audio = requests.post(
        f"{BASE}/download-track",
        headers=HEADERS,
        json={
            "track_id": track_id,
            "duration_seconds": duration
        }
    ).content
    
    # Save temp audio
    with open("/tmp/music.mp3", "wb") as f:
        f.write(audio)
    
    # 4. Merge with ffmpeg
    subprocess.run([
        "ffmpeg", "-i", video_path, "-i", "/tmp/music.mp3",
        "-c:v", "copy", "-shortest", output_path
    ])

# Usage
add_music_to_video(
    "ai_generated.mp4",
    "upbeat music for tech product demo",
    "final_with_music.mp4"
)
```

***

## Best Practices

<Tip>
  **Cache search results:** If generating similar videos, search once and reuse the track across multiple outputs
</Tip>

<Tip>
  **Match music to video style:** Include the video's subject in your search query ("nature video", "tech demo", "fashion content")
</Tip>

<Tip>
  **Use smart trimming:** Let Trackyard handle clip selection instead of fading manually
</Tip>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="API Quickstart" icon="rocket" href="/getting-started/api-quickstart">
    Get started with the API
  </Card>

  <Card title="Code Examples" icon="code" href="/api-reference/examples">
    See full integration examples
  </Card>
</CardGroup>
