Skip to content
Notifications
Clear all

Walkthrough: Integrating HeyGen videos into my WordPress site.

2 Posts
2 Users
0 Reactions
27 Views
(@cloud_infra_vet)
Honorable Member
Joined: 4 months ago
Posts: 389
Topic starter   [#19788]

I've recently completed a project for a client where we needed to migrate their static, brochure-style WordPress site to a more dynamic platform capable of hosting a library of AI-generated product explainer videos. The client had been using HeyGen to produce these videos and needed a seamless, self-hosted integration that avoided reliance on third-party iframe embeds for security and performance control. The core requirements were: maintain native WordPress editing experience, ensure videos are served from our own CDN for cost predictability, and implement robust access controls. This walkthrough details the architecture we landed on, focusing on the automation pipeline and cost implications.

Our solution hinged on treating HeyGen as a headless video production API, with WordPress as the content management layer and AWS Elemental MediaConvert for format standardization. The workflow is as follows:

1. **Video Generation & Initial Storage:** The marketing team generates videos via HeyGen's platform. We configured HeyGen's webhook to notify our AWS Lambda function upon video completion, triggering a download to a secure S3 bucket (`heygen-source-assets`).
2. **Processing Pipeline:** Upon S3 upload, an EventBridge rule invokes a Lambda function that submits a MediaConvert job. This job transcodes the video into multiple resolutions (1080p, 720p, 480p) packaged in HLS format, storing the output in a second S3 bucket (`video-delivery-assets`).
3. **WordPress Integration:** We developed a custom plugin that registers a Custom Post Type `ai_video`. The plugin's meta box allows editors to paste the HeyGen video ID. A background cron job (WP-CLI based) matches this ID to the processed files in the delivery bucket and generates signed CloudFront URLs.

**Key Technical Implementation Details:**

The critical piece was the secure, temporary URL generation within WordPress to avoid exposing S3 URLs directly. Here's the core function of our plugin that handles this:

```php
function generate_signed_video_url($video_key, $resolution = '720p') {
$cloudfront_url = CLOUDFRONT_DISTRIBUTION_URL;
$key_pair_id = getenv('AWS_CLOUDFRONT_KEY_PAIR_ID');
$private_key = file_get_contents(CLOUDFRONT_PRIVATE_KEY_PATH);

$expires = time() + 3600; // 1-hour expiry
$json = '{"Statement":[{"Resource":"' . $cloudfront_url . $video_key . '/' . $resolution . '/*","Condition":{"DateLessThan":{"AWS:EpochTime":' . $expires . '}}}]}';

$encoded_json = strtr(base64_encode($json), '+=/', '-_~');
$signature = '';
openssl_sign($json, $signature, $private_key, OPENSSL_ALGO_SHA1);
$encoded_signature = strtr(base64_encode($signature), '+=/', '-_~');

return $cloudfront_url . $video_key . '/' . $resolution . '/playlist.m3u8?Policy=' . $encoded_json . '&Signature=' . $encoded_signature . '&Key-Pair-Id=' . $key_pair_id;
}
```

We serve the HLS stream via the `video.js` library in the frontend theme. The MediaConvert job configuration also generates a thumbnail sprite, which we use for the poster image and seek preview.

**Cost Analysis & Optimization:**

A major driver for self-hosting was cost control. HeyGen's bandwidth-based pricing can become opaque at scale. Our AWS-based pipeline costs are now broken into predictable components:
* **MediaConvert:** ~$0.015 per minute of output video (for the three resolutions).
* **S3 Storage:** Negligible (~$0.023 per GB/month).
* **CloudFront Data Transfer Out:** ~$0.085 per GB (varies by region). This is our largest variable cost, but it's directly tied to viewership and is often lower than aggregated third-party fees.
* **Lambda & EventBridge:** < $5/month at our volume (~500 videos processed/month).

The total operational cost is approximately 30% lower than the projected cost of using HeyGen's native hosting for the same traffic volume, with the added benefits of owning the asset lifecycle and tighter security posture. The initial development overhead for the pipeline and plugin was roughly 40 engineer-hours, which the client recouped in under six months via the operational savings. This pattern is now a template in our practice for any SaaS tool where the output asset is the primary value, not the hosting layer.



   
Quote
(@budget_buyer_99)
Honorable Member
Joined: 4 months ago
Posts: 359
 

This is way overbuilt for most people. You're talking about AWS Lambda, S3 buckets, a CDN... that's a huge cost and complexity hit just to avoid an iframe.

What's the actual bandwidth cost of self-hosting a library of videos versus the HeyGen embed? Unless you're serving massive volume, the CDN fees alone will wipe out any "cost predictability" you think you're getting.

And "robust access controls" can be done with WordPress membership plugins and a simple private video embed. Feels like a solution looking for a problem unless the client is Netflix.



   
ReplyQuote