Video Upload and Transcoding Implementation for Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1 servicesAll 2065 services
Video Upload and Transcoding Implementation for Website
Complex
from 1 week to 3 months
FAQ
Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Video Upload and Transcoding Implementation

Video upload requires separate pipeline: file is received on server or directly to cloud, then transcoded into multiple qualities (360p, 720p, 1080p) and formats (MP4/H.264, WebM/VP9). Transcoding is CPU-intensive operation, executed in background.

Pipeline architecture

[Client] → [Presigned S3 Upload] → [S3: original/]
         ↓
[S3 Event → SQS/Lambda] → [Transcoding Worker (FFmpeg)]
         ↓
[S3: processed/{quality}/] → [CDN CloudFront]
         ↓
[Update DB: video.status = ready, paths = {...}]
         ↓
[WebSocket/Webhook → Client notification]

Step 1: Presigned Upload to S3

class VideoController extends Controller
{
    public function initiateUpload(Request $request): JsonResponse
    {
        $request->validate([
            'filename'     => 'required|string|max:255',
            'content_type' => 'required|in:video/mp4,video/webm,video/quicktime,video/x-msvideo',
            'size'         => 'required|integer|max:5368709120',  // 5 GB
        ]);

        $key = sprintf(
            'original/%d/%s/%s',
            auth()->id(),
            now()->format('Y/m'),
            Str::uuid() . '.' . pathinfo($request->filename, PATHINFO_EXTENSION)
        );

        $s3 = app('aws')->createClient('s3');
        $command = $s3->getCommand('PutObject', [
            'Bucket'      => config('filesystems.disks.s3.bucket'),
            'Key'         => $key,
            'ContentType' => $request->content_type,
        ]);

        $presigned = $s3->createPresignedRequest($command, '+2 hours');

        $video = Video::create([
            'user_id'       => auth()->id(),
            'original_key'  => $key,
            'original_name' => $request->filename,
            'status'        => 'pending',
            'size'          => $request->size,
        ]);

        return response()->json([
            'video_id'   => $video->id,
            'upload_url' => (string) $presigned->getUri(),
            'key'        => $key,
        ]);
    }

    public function confirmUpload(Request $request, Video $video): JsonResponse
    {
        $this->authorize('update', $video);

        $video->update(['status' => 'uploaded']);
        TranscodeVideoJob::dispatch($video);

        return response()->json(['status' => 'processing']);
    }
}

Step 2: Transcoding with FFmpeg

class TranscodeVideoJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public int $timeout = 7200;  // 2 hours
    public int $tries = 2;

    const QUALITIES = [
        '360p'  => ['width' => 640,  'height' => 360,  'bitrate' => '800k',  'audiorate' => '96k'],
        '720p'  => ['width' => 1280, 'height' => 720,  'bitrate' => '2500k', 'audiorate' => '128k'],
        '1080p' => ['width' => 1920, 'height' => 1080, 'bitrate' => '5000k', 'audiorate' => '192k'],
    ];

    public function __construct(private Video $video) {}

    public function handle(): void
    {
        $this->video->update(['status' => 'transcoding']);
        $inputUrl = Storage::disk('s3')->temporaryUrl($this->video->original_key, now()->addHour());
        $paths = [];

        foreach (self::QUALITIES as $quality => $params) {
            $outputKey = sprintf('processed/%d/%s/%s.mp4', $this->video->user_id, $this->video->id, $quality);
            $outputPath = sys_get_temp_dir() . "/{$this->video->id}_{$quality}.mp4";
            $scale = "scale={$params['width']}:{$params['height']}:force_original_aspect_ratio=decrease,pad={$params['width']}:{$params['height']}:(ow-iw)/2:(oh-ih)/2";

            $command = [
                'ffmpeg', '-y', '-i', $inputUrl,
                '-vf', $scale,
                '-c:v', 'libx264',
                '-preset', 'medium',
                '-crf', '23',
                '-maxrate', $params['bitrate'],
                '-bufsize', (int)($params['bitrate']) * 2 . 'k',
                '-c:a', 'aac',
                '-b:a', $params['audiorate'],
                '-movflags', '+faststart',
                $outputPath,
            ];

            $process = new \Symfony\Component\Process\Process($command);
            $process->setTimeout(3600);
            $process->run();

            if (!$process->isSuccessful()) {
                throw new \RuntimeException("FFmpeg failed for {$quality}");
            }

            Storage::disk('s3')->putFileAs(dirname($outputKey), new \Illuminate\Http\File($outputPath), basename($outputKey));
            $paths[$quality] = $outputKey;
            unlink($outputPath);
        }

        $this->video->update([
            'status'        => 'ready',
            'paths'         => $paths,
        ]);

        $this->video->user->notify(new VideoReadyNotification($this->video));
    }

    public function failed(\Throwable $e): void
    {
        $this->video->update(['status' => 'failed', 'error' => $e->getMessage()]);
    }
}

AWS MediaConvert for large volumes

For large video volumes, use managed service:

import boto3

def transcode_with_mediaconvert(input_key: str, output_prefix: str) -> str:
    client = boto3.client('mediaconvert', region_name='eu-west-1')
    job = client.create_job(
        Role='arn:aws:iam::123456789:role/MediaConvertRole',
        Settings={...}
    )
    return job['Job']['Id']

Transcoding progress

Route::get('/videos/{video}/status', function (Video $video) {
    return response()->json([
        'status'   => $video->status,
        'progress' => $video->transcoding_progress,
        'paths'    => $video->status === 'ready' ? $video->paths : null,
    ]);
});

Implementation timeline

Task Timeline
Presigned upload + FFmpeg queue 4–5 days
Thumbnail generation + metadata +1–2 days
AWS MediaConvert integration 2–3 days
HLS adaptive streaming +3–4 days