quasarstream / PHP-FFmpeg-video-streaming

📼 Package media content for online streaming(DASH and HLS) using FFmpeg
https://www.quasarstream.com/op/php/ffmpeg-streaming?u=php-ff
MIT License
514 stars 117 forks source link

wana help to reduce file size #43

Closed naroogheh closed 4 years ago

naroogheh commented 4 years ago

Is your feature request related to a problem? Please describe. no Describe the solution you'd like hi , at first thank you for share your code i have problem with size of files that converted to DRM (.ts files ), i mean , for example , file that used to stream have 10MB size , after generating .ts files , key ,... generated file have 22 MB file size , is it natural ? (it is 2x grather than none stream file ) if it is not natural , how can i use other option to reduce this files size ? Additional context this is code that i used to generate file

$save_to = 'C:\xampp\htdocs\hls\key'; //A URL (or a path) to access the key on your website $url = 'http://localhost/hls/key'; //$r_360p = (new Representation)->setKiloBitrate(276)->setResize(640, 360); //$r_480p = (new Representation)->setKiloBitrate(750)->setResize(854, 480); //$r_720p = (new Representation)->setKiloBitrate(2048)->setResize(1280, 720); $format = new Streaming\Format\X264(); $format->on('progress', function ($video, $format, $percentage){ echo sprintf("\r Transcoding... (%s%%)[%s%s]", $percentage, str_repeat('#', $percentage), str_repeat('-', (100 - $percentage))); }); //var_dump($video->hls()->getHlsListSize()); $video->hls() ->encryption($save_to, $url) ->setFormat($format) ->x264() ->autoGenerateRepresentations([]) ->save(base_path.'/files/test2.m3u8');

thank you again for you help

finagin commented 4 years ago

If source file in 720p then output ts files is sum of 720p + 480p + 360p = 720 + 840 = 1560 720 / 1560 ≈ 10 / 22

aminyazdanpanah commented 4 years ago

The size of your stream content depends on various factors(e.g. how many representations your stream does have, the value of the bitrate for each stream, format of the video, and so on).

If you want to compress content files, you can change the value of the bitrate. Also, you can change the format of video. For instance, you can use the HEVC codec which is a great library for data compression(You can also use VP9 that is only utilized for DASH packaging).

NOTE: You cannot use the HEVC codec for HLS packaging in the MpegTS format but it can be utilized in fragmented Mp4. See HLS docs for more information.

naroogheh commented 4 years ago

If source file in 720p then output ts files is sum of 720p + 480p + 360p = 720 + 840 = 1560 720 / 1560 ≈ 10 / 22

i used autoGenerateRepresentations() , so i think this generate one format only ... its correct ?

finagin commented 4 years ago

i used autoGenerateRepresentations() , so i think this generate one format only ... its correct ?

If you use empty list of sizes or don't use this parameter, by default use this list:

// src/AutoReps.php

    /**
     * regular video's heights
     *
     * @var array side_values
     */
    private $sides = [144, 240, 360, 480, 720, 1080, 1440, 2160];
naroogheh commented 4 years ago
AutoReps

thank you , could you help me to write a simple code to special size only ? please this is is sample that i used to proccess :

$video->hls() ->encryption($save_to, $url) ->setFormat($format) ->x264() ->autoGenerateRepresentations([]) ->save(base_path.'/files/test2.m3u8');

finagin commented 4 years ago

->autoGenerateRepresentations([])

Set here one of sizes like ->autoGenerateRepresentations([720])