A Java Spring Boot web application that generates Sora videos using Azure OpenAI API. This application provides a user-friendly web interface for creating AI-generated videos with configurable video specifications including resolution and duration.
- 🎥 Video Generation: Create videos using Azure OpenAI's Sora model
- ⚙️ Configurable Specifications: Choose from 9 supported resolutions and duration (1-20 seconds)
- 🔧 Smart Validation: Automatic restrictions for resolution-specific limitations (e.g., 1920x1080 max 10 seconds)
- 🖥️ Web Interface: Modern, responsive UI built with Bootstrap and Thymeleaf
- ⚡ Reactive Architecture: Built with Spring WebFlux for optimal performance with 100MB buffer for large video downloads
- 🔒 Secure: Uses Azure managed identity for authentication in production
- 📊 Monitoring: Includes health checks and logging for production deployment
- 🚀 Container Ready: Dockerized for easy deployment to Azure Container Apps
- 💰 Cost Estimation: Real-time cost preview and detailed cost breakdown with warnings
The Sora Video Generator includes a comprehensive cost estimation system that provides users with transparent pricing information before and after video generation.
- Dynamic Updates: Cost estimates update automatically as you change resolution and duration settings
- Interactive Feedback: See cost changes in real-time on the main form
- Pre-Generation Awareness: Know the cost before submitting your video generation request
The cost estimator is based on Azure OpenAI Sora per-second pricing as of June 2025:
| Resolution / Aspect | Cost per Second |
|---|---|
| 480 Square (480x480) | $0.15 |
| 480p (480x854, 854x480) | $0.20 |
| 720 Square (720x720) | $0.30 |
| 720p (720x1280, 1280x720) | $0.45 - $0.50* |
| 1080 Square (1080x1080) | $0.60 - $0.75* |
| 1080p (1080x1920, 1920x1080) | $1.30 - $1.85* |
Variable Pricing: Some resolutions have cost ranges based on duration tiers (1-5s, 6-10s, 11-15s, 16-20s). The application uses average pricing for estimates.
| Resolution | Duration | Estimated Cost |
|---|---|---|
| 480x480 | 5 seconds | $0.75 |
| 720x720 | 10 seconds | $3.00 |
| 1080x1080 | 10 seconds | $6.75 (avg) |
| 1080x1920 | 5 seconds | $8.13 (avg) |
| 1920x1080 | 10 seconds | $15.75 (avg) |
After submitting a video generation request, users receive:
-
Detailed Cost Information
- Total estimated cost for the specific video
- Per-second breakdown showing calculation method
- Resolution and duration specifications
-
Cost Warnings
- Alerts for high-cost configurations (>$8.00)
- Notifications for very expensive requests (>$15.00)
- Critical alerts for extremely expensive requests (>$25.00)
- Recommendations for cost optimization
-
Transparent Billing Information
- Clear notes about when charges occur
- Information about potential cost variations
- Links to current Azure pricing documentation
The application includes a dedicated CostEstimationService that:
- Calculates costs based on current pricing models
- Provides detailed breakdown strings for user display
- Generates appropriate warnings for expensive configurations
- Supports future pricing model updates
// Real-time cost calculation
public BigDecimal calculateCost(int width, int height, int duration)
// Detailed cost breakdown for display
public String generateCostBreakdown(VideoRequest request, BigDecimal cost)
// Cost warnings for expensive requests
public String generateCostWarning(BigDecimal cost)- Start Small: Begin with shorter durations (3-5 seconds) and lower resolutions to minimize costs
- Choose Appropriate Resolution:
- Use 480x480 ($0.15/sec) for testing and prototyping
- Use 720x720 ($0.30/sec) for good quality at moderate cost
- Reserve 1080p ($1.30-$1.85/sec) for final production videos
- Preview Costs: Always check the cost estimate - 1080p videos can cost $6.50-$37+ depending on duration
- Duration Management: Even 10 seconds at 1080p costs $13-$18.50
- Batch Processing: Plan multiple shorter videos rather than one long expensive video
Important: Cost estimates are based on Azure OpenAI Sora pricing as of June 2025 and reflect the most current per-second pricing structure. Actual costs may vary based on:
- Azure region selection
- Subscription type and discounts
- Current Azure AI Studio pricing
- Promotional pricing or credits
Always verify current pricing through the Azure portal before generating expensive videos.
- Backend: Java 17 + Spring Boot 3.5.0
- Frontend: Thymeleaf templates with Bootstrap 5
- HTTP Client: Spring WebFlux for reactive API calls
- Deployment: Azure Container Apps with Container Registry
- Monitoring: Spring Boot Actuator with Azure Log Analytics
- Java 17 or later
- Maven 3.6 or later
- Azure OpenAI API access with Sora model, once deployed you can get the instance target URI, but you must remove the "/openai/v1/video/generations/jobs?api-version=preview"
- Azure CLI (for deployment)
- Azure Developer CLI (recommended)
-
Clone the repository
git clone <repository-url> cd sora-video-generator
-
Set up environment variables
cp .env.example .env # Edit .env with your Azure OpenAI credentials, make sure to use the base URL and not the entire SORA instance URL. Remove everything after the main FQDN eg: "/openai/v1/video/generations/jobs?api-version=preview" must be removed from both strings in your .env and your azd environment variables -
Configure application properties Update
src/main/resources/application.propertieswith your Azure OpenAI endpoint and API key:azure.openai.endpoint=https://your-openai-resource.cognitiveservices.azure.com. Make sure to use the base URL and not the entire SORA instance URL. Remove everything after the main FQDN eg: "/openai/v1/video/generations/jobs?api-version=preview" must be removed from both strings in your .env files and your azd environment variables azure.openai.api-key=your_api_key_here
-
Run the application
./mvnw spring-boot:run
-
Access the application Open your browser and go to
http://localhost:8080
-
Build the JAR file
./mvnw clean package
-
Build Docker image
docker build -t sora-video-generator .
This application is designed to be deployed to Azure Container Apps using Azure Developer CLI.
-
Install Azure Developer CLI
# Windows (PowerShell) winget install Microsoft.AzureDeveloperCLI # macOS brew tap azure/azd && brew install azd # Linux curl -fsSL https://aka.ms/install-azd.sh | bash
-
Initialize the project
azd init
-
Set environment variables
azd env set AZURE_OPENAI_ENDPOINT "https://your-resource.cognitiveservices.azure.com" Make sure to use the base URL and not the entire SORA instance URL. Remove everything after the main FQDN eg: "/openai/v1/video/generations/jobs?api-version=preview" must be removed from both strings in your .env files and your azd environment variables azd env set AZURE_OPENAI_API_KEY "your_api_key_here"
-
Deploy to Azure
azd up
-
Create Azure resources
az group create --name rg-sora-video --location eastus az deployment group create --resource-group rg-sora-video --template-file infra/main.bicep --parameters @infra/main.parameters.json
-
Build and push container image
az acr build --registry <your-acr-name> --image sora-video-generator:latest .
-
Update container app
az containerapp update --name <your-container-app> --resource-group rg-sora-video --image <your-acr-name>.azurecr.io/sora-video-generator:latest
| Variable | Description | Default |
|---|---|---|
AZURE_OPENAI_ENDPOINT |
Azure OpenAI service endpoint | Required |
AZURE_OPENAI_API_KEY |
Azure OpenAI API key | Required |
AZURE_OPENAI_API_VERSION |
API version | preview |
SERVER_PORT |
Application port | 8080 |
SPRING_PROFILES_ACTIVE |
Spring profile | dev |
The application supports configurable parameters for video generation:
- 480x480 (Square - Small)
- 480x854 (Portrait)
- 854x480 (Landscape)
- 720x720 (Square - HD)
- 720x1280 (Portrait - HD)
- 1280x720 (Landscape - HD)
- 1080x1080 (Square - Full HD) - Default
- 1080x1920 (Portrait - Full HD)
- 1920x1080 (Landscape - Full HD) - Limited to 10 seconds max
- Standard Resolutions: 1-20 seconds
- 1920x1080 Resolution: 1-10 seconds (API limitation)
- Default: 5 seconds
- Variants: 1 (fixed)
- Model: Sora (latest)
- Access the web interface at your deployed URL or
http://localhost:8080 - Enter a prompt describing the video you want to generate
- Select resolution from the dropdown (9 options available)
- Set duration between 1-20 seconds (or 1-10 for 1920x1080)
- Review cost estimate displayed in real-time as you adjust settings
- Click "Generate Video" to start the process and see detailed cost breakdown
- Check the status of your video generation job
- Download the video once generation is complete
- Monitor Real-Time Costs: Watch the cost estimate update as you change settings - 1080p can quickly become expensive
- Cost Warnings: Pay attention to warnings for expensive configurations (>$8.00, >$15.00, >$25.00)
- Resolution Impact: Higher resolutions have dramatically higher costs (480p: $0.15/sec vs 1080p: $1.30-$1.85/sec)
- Duration Impact: Every second matters - a 20-second 1080p video can cost $26-$37
- Billing Information: You're only charged for successful video generation
- Square formats (480x480, 720x720, 1080x1080): Best for social media posts
- Portrait formats (480x854, 720x1280, 1080x1920): Ideal for mobile content and stories
- Landscape formats (854x480, 1280x720, 1920x1080): Perfect for traditional video content
- Duration recommendations: Start with shorter durations (5-10 seconds) for better quality
- 1920x1080 limitation: Maximum 10 seconds due to API restrictions
GET /- Main video generation formPOST /generate- Submit video generation requestGET /status/{jobId}- View job status pageGET /api/status/{jobId}- Get job status (JSON)GET /actuator/health- Health check endpoint
The application includes comprehensive monitoring:
- Health Checks:
/actuator/healthendpoint - Readiness Probe:
/actuator/health/readiness - Liveness Probe:
/actuator/health/liveness - Logging: Configured for Azure Log Analytics
- Environment variables for sensitive configuration
- CORS policy configured for web interface
- Container runs as non-root user
- Azure managed identity for production authentication
src/
├── main/
│ ├── java/com/example/soravideogenerator/
│ │ ├── SoraVideoGeneratorApplication.java
│ │ ├── config/
│ │ │ └── AzureOpenAIConfig.java
│ │ ├── controller/
│ │ │ └── VideoController.java
│ │ ├── model/
│ │ │ ├── VideoRequest.java
│ │ │ ├── VideoResponse.java
│ │ │ ├── SoraApiRequest.java
│ │ │ └── SoraApiResponse.java
│ │ └── service/
│ │ ├── SoraVideoService.java
│ │ └── CostEstimationService.java
│ └── resources/
│ ├── application.properties
│ └── templates/
│ ├── index.html
│ ├── result.html
│ ├── status.html
│ └── error.html
├── test/
└── ...
- VideoController: Handles web requests and form submissions with configurable video specifications and cost estimation
- SoraVideoService: Manages video generation API calls with user-selected parameters
- CostEstimationService: Calculates costs, generates breakdowns, and provides cost warnings for video generation requests
- AzureOpenAIConfig: Configuration for Azure OpenAI WebClient with 100MB buffer for large video downloads
- Model Classes: Request/response DTOs with validation for resolution-duration combinations
- Custom Validation: Enforces API restrictions (e.g., 1920x1080 max 10 seconds)
-
Azure OpenAI API Key Issues
- Verify your API key is correct
- Check endpoint URL format
- Ensure your subscription has access to Sora model
-
Container App Deployment Issues
- Check container registry permissions
- Verify managed identity configuration
- Review application logs in Azure portal
-
Video Generation Timeouts
- Video generation can take 2-5 minutes
- Check job status regularly
- Ensure adequate timeout settings
-
Video Download Buffer Errors
- Application configured with 100MB buffer for large video files
- If encountering buffer limit issues, videos may be too large
- Try shorter durations or lower resolutions
-
Resolution-Duration Restrictions
- 1920x1080 resolution limited to maximum 10 seconds
- Frontend automatically enforces these restrictions
- Backend validation prevents invalid combinations
View application logs:
# Azure Developer CLI
azd logs
# Azure CLI
az containerapp logs show --name <app-name> --resource-group <rg-name>This repository includes a comprehensive CI/CD pipeline using GitHub Actions. To set it up:
-
Create Azure Service Principal
az ad sp create-for-rbac --name "sora-video-generator-sp" --role contributor \ --scopes /subscriptions/<subscription-id> --sdk-auth
-
Configure GitHub Secrets Go to your repository Settings > Secrets and variables > Actions, and add:
AZURE_CREDENTIALS: Output from the service principal creationAZURE_ENV_NAME: Your azd environment name (from.azurefolder)AZURE_LOCATION: Azure region (e.g.,eastus)AZURE_SUBSCRIPTION_ID: Your Azure subscription IDAZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint URLAZURE_OPENAI_API_KEY: Your Azure OpenAI API keyAZURE_CLIENT_ID: Service principal client IDAZURE_CLIENT_SECRET: Service principal client secretAZURE_TENANT_ID: Your Azure tenant ID
-
Pipeline Features
- Automated Testing: Runs unit tests on every push/PR
- Security Scanning: OWASP dependency check and CodeQL analysis
- Build & Deploy: Automatically deploys to Azure on main branch
- Docker Integration: Builds and pushes to Azure Container Registry
-
Triggering Deployments
- Push to
mainbranch triggers automatic deployment - Pull requests run tests and security scans
- Manual deployment via GitHub Actions UI
- Push to
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License. See the LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review Azure OpenAI documentation
- Open an issue in the repository