This guide will help you connect all the existing infrastructure (ffmpeg, GCS, rclone) with the thumbnail generator service.
- ✅ ffmpeg installed and working
- ✅ Google Cloud SDK (gsutil) configured
- ✅ rclone configured for R2
- ✅ GCP service account with storage access
- ✅ R2 API tokens configured
# Navigate to the thumbnail service
cd yiku-thumbnail
# Install Node.js dependencies
npm install
# Create necessary directories
mkdir -p temp/videos temp/thumbnails credentialsCreate a .env file in the yiku-thumbnail directory:
# Create .env file
nano .envAdd the following content (replace with your actual values):
# Service Configuration
PORT=3000
NODE_ENV=production
# Disk Management
MAX_DISK_USAGE=80
CLEANUP_INTERVAL=300000
# Temp Directories
TEMP_DIR=./temp/videos
THUMBNAIL_DIR=./temp/thumbnails
# Google Cloud Platform Configuration
GOOGLE_APPLICATION_CREDENTIALS=./credentials/gcp-service-account.json
GCP_PROJECT_ID=your-gcp-project-id
# Cloudflare R2 Configuration
R2_ACCOUNT_ID=your-r2-account-id
R2_ACCESS_KEY_ID=your-r2-access-key-id
R2_SECRET_ACCESS_KEY=your-r2-secret-access-key
R2_BUCKET_NAME=your-r2-bucket-name
R2_PUBLIC_URL=https://your-public-domain.com# Copy your existing GCP service account key
cp /path/to/your/gcp-service-account.json credentials/
# Set proper permissions
chmod 600 credentials/gcp-service-account.json# Verify rclone configuration
rclone listremotes
# Should show: r2:# Start in development mode
npm run dev
# Or start in production mode
npm start# Test health endpoint
curl http://localhost:3000/health
# Test status endpoint
curl http://localhost:3000/status
# Test thumbnail generation (replace with real data)
curl -X POST http://localhost:3000/generate \
-H "Content-Type: application/json" \
-d '{
"video_url": "gs://your-bucket/your-video.mp4",
"video_id": "test-video-123"
}'- Method:
POST - URL:
http://localhost:3000/generate(orhttp://thumbnail-generator:3000/generateif using Docker) - Headers:
Content-Type: application/json - Body: JSON
{
"video_url": "{{ $json.video_url }}",
"video_id": "{{ $json.video_id }}"
}- Check
successfield - Use
thumbnailUrlif successful - Handle errors appropriately
- GCP Authentication Failed
# Check if service account key exists
ls -la credentials/gcp-service-account.json
# Test gcloud authentication
gcloud auth activate-service-account --key-file=credentials/gcp-service-account.json
# Test gsutil
gsutil ls gs://your-bucket/- R2 Authentication Failed
# Check rclone configuration
rclone listremotes
# Test R2 connection
rclone lsd r2:
# Test upload to R2
rclone copy test.jpg r2:your-bucket/test.jpg- ffmpeg Not Found
# Check ffmpeg installation
ffmpeg -version
# Install if needed
sudo apt-get update && sudo apt-get install -y ffmpeg- Permission Issues
# Fix file permissions
chmod 600 credentials/gcp-service-account.json
chmod 755 temp/videos temp/thumbnails
# Check service permissions
ls -la temp/# Check service logs
npm run dev
# Look for these key messages:
# ✅ GCP authentication successful
# ✅ R2 authentication successful
# Thumbnail generated successfully: [URL]
# Cleanup completedIf you want to dockerize the service:
# Build the image
docker build -t yiku-thumbnail .
# Run with docker-compose
docker-compose up -d
# Check logs
docker-compose logs -f yiku-thumbnailcurl http://localhost:3000/healthExpected response:
{
"status": "healthy",
"diskUsage": "15%",
"gcpAuth": true,
"r2Auth": true,
"timestamp": "2024-01-01T12:00:00.000Z"
}curl http://localhost:3000/statusExpected response:
{
"diskUsage": "15%",
"tempVideos": 0,
"tempThumbnails": 0,
"gcpAuth": true,
"r2Auth": true,
"timestamp": "2024-01-01T12:00:00.000Z"
}- ✅ Test basic functionality
- 🔄 Configure real credentials
- 🐳 Dockerize for production (optional)
- 🔗 Integrate with n8n workflow
- 📊 Set up monitoring and alerts
If you encounter issues:
- Check the service logs
- Verify all prerequisites are installed
- Test each component individually
- Check the troubleshooting section above