Larupload
  • 🏁Getting Started
    • Introduction
    • Installation
    • Laravel Nova integration
    • Support Us
    • License
  • 🚀Basic Usage
    • Database Preparation
    • Model Preparation
    • Upload
  • ⚙️Advanced Usage
    • Concepts
    • Configuration
      • Disk
      • Local Disk
      • Mode
      • SecureIds
      • With Meta
      • Camel Case Response
      • Hide Table Columns
      • Naming Method
      • Lang
      • Image Processing Library
      • Generate Cover
      • Cover Style
      • Dominant Color
      • Dominant Color Quality
      • Keep Old Files
      • Preserve Files
      • Store Original File Name
      • Optimize Image
      • FFMpeg
        • FFMpeg Binaries
        • FFMpeg Threads
        • FFMpeg Capture Frame
        • FFMpeg Queue
        • FFMpeg Max Queue Number
        • FFMpeg Timeout
        • FFMPEG Log Channel
    • Attachment
      • Disk
      • With Meta
      • Naming Method
      • Lang
      • Image Processing Library
      • Generate Cover
      • Cover Style
      • Dominant Color
      • Dominant Color Quality
      • Keep Old Files
      • Preserve Files
      • Store Original File Name
      • SecureIds Method
      • Optimize Image
      • Media Styles
      • Complete Example
    • Migrations
      • Heavy Columns
      • Light Columns
      • Add Original File Name to Existing Tables
  • Upload
  • Delete
  • Cover
    • Upload Cover
    • Update Cover
    • Delete Cover
  • Download
    • Generate Download Link
      • Generate URL for particular style
      • Generate URL for all styles
    • Generate Download Response
  • Meta
  • Get Attachments
  • API Resources
  • Image Optimization
  • SecureIds
  • Queue FFMpeg Processes
    • Job Completion Event
    • FFMpeg Queue Relationships
  • 🧱Standalone Uploader
    • Introduction
    • Upload
    • Delete
    • Cover
      • Update Cover
      • Delete Cover
    • Customization
  • ⚪OTHER
    • Migration
Powered by GitBook
On this page
  • Media Styles
  • Image Style
  • Audio Style
  • Video Style
  • Stream Style
Edit on GitHub
  1. Advanced Usage
  2. Attachment

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

Index
Name
Type
Required
Default
Description
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)
        ];
    }
}

Audio Style

Index
Name
Type
Required
Default
Description
1

name

string

–

style name. examples: hq, lq, ...

2

format

Mp3|Aac|Wav|Flac

Mp3

the format of the converted audio file

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;
use FFMpeg\Format\Audio\Wav;

class Media extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            Attachment::make('file')
                ->audio('hq', new Wav())
        ];
    }
}

Video Style

Index
Name
Type
Required
Default
Description
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 | WebM | Ogg | Mp3 | Aac | Wav | Flac

new X264

by default, the encoding format for video is X264. However, users can specify additional video/audioformats and options, 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;
use FFMpeg\Format\Audio\Mp3;


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)
                ->video(name: 'mp3', format: new Mp3)
        ];
    }
}

Stream Style

Index
Name
Type
Required
Default
Description
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)
                )
        ];
    }
}

PreviousOptimize ImageNextComplete Example

Last updated 4 months ago

⚙️