Media Styles

Media Styles

This note explains the usage of the stream, image, and video functions in Larupload.

The stream function is used to create an HTTP Live Streaming (HLS) stream, which is a video streaming protocol that breaks the video into smaller segments and delivers them over HTTP. The image and video functions are used to manipulate images and videos, respectively.

When you want to create an HLS stream for a video, you can use the stream function available in the Attachment class of the attachments method within their model. This function takes some arguments that specify the stream's resolution, bitrate, and other properties.

On the other hand, if you want to manipulate images or videos, you should use the image and video functions, respectively. These functions provide a set of options for resizing, cropping, and modifying the image or video.

Image Style

IndexNameTypeRequiredDefaultDescription
1

name

string

style name. examples: thumbnail, small, ...

2

width

?int

null

width of the manipulated image

3

height

?int

null

height of the manipulated image

4

mode

LaruploadMediaStyle

AUTO

this argument specifies how Larupload should manipulate the uploaded image and can take on any of the following values: FIT, AUTO, SCALE_WIDTH, SCALE_HEIGHT, CROP

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;

class Media extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            Attachment::make('file')
                ->image('thumbnail', 250, 250, LaruploadMediaStyle::CROP)
                ->image('landscape', 1100, 1100, LaruploadMediaStyle::AUTO)
        ];
    }
}

Video Style

IndexNameTypeRequiredDefaultDescription
1

name

string

style name. examples: thumbnail, small, ...

2

width

?int

null

width of the manipulated video

3

height

?int

null

height of the manipulated video

4

mode

LaruploadMediaStyle

SCALE_HEIGHT

this argument specifies how Larupload should manipulate the uploaded video and can take on any of the following values: FIT, AUTO, SCALE_WIDTH, SCALE_HEIGHT, CROP

5

format

X264

new X264

by default, the encoding format for video is X264. However, users can specify additional options for this format, including adjusting the kilobitrate for both audio and video. This allows for more precise configuration and optimization of the user's encoding preferences.

6

padding

bool

false

If set to true, padding will be applied to the video using a black color in order to fit the given dimensions.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;

class Media extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            Attachment::make('file')
                ->video('thumbnail', 250, 250, LaruploadMediaStyle::CROP)
                ->video('landscape', 1100, 1100, LaruploadMediaStyle::AUTO)
        ];
    }
}

Stream Style

IndexNameTypeRequiredDefaultDescription
1

name

string

label for stream quality. highly recommended to use string labels like 720p

2

width

int

3

height

int

4

format

X264

by default, the encoding format for video is X264. However, users can specify additional options for this format, including adjusting the kilobitrate for both audio and video. This allows for more precise configuration and optimization of the user's encoding preferences.

5

padding

bool

false

If set to true, padding will be applied to the video using a black color in order to fit the given dimensions.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use FFMpeg\Format\Video\X264;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;

class Media extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            Attachment::make('file')
                ->stream(
                    name: '480p',
                    width: 640,
                    height: 480,
                    format: (new X264)
                        ->setKiloBitrate(1000)
                        ->setAudioKiloBitrate(32)
                )
                ->stream(
                    name: '720p',
                    width: 1280,
                    height:  720,
                    format: (new X264)
                        ->setKiloBitrate(3000)
                        ->setAudioKiloBitrate(64)
                )
        ];
    }
}

Last updated