AVideo-Encoder icon indicating copy to clipboard operation
AVideo-Encoder copied to clipboard

Extract WebM Video

Open akhilleusuggo opened this issue 5 years ago • 39 comments

We need an option like MP4 , where we can opt HD , SD or Low only . On webm right now it's like we have no choice . The encoder will encode them to the 3 resolutions . ( I'm re-transcoding all my videos to webm , saved around 40% disk space ) , but without this option , I can't disable the MP4 encoder .

I hope you can implement it , also on the advanced site option .

akhilleusuggo avatar Oct 06 '20 13:10 akhilleusuggo

Sorry I do not get it.

the HD , SD or Low should also reflect on the webm. is not working that way?

DanielnetoDotCom avatar Oct 06 '20 21:10 DanielnetoDotCom

No... You can not chose to what qualities the webm will be encoded .

Also , when you select to encode WebM , does encode also MP4 , even if the MP4 are disabled ...

Basically does create 6 video files ... _HD ( mp4, webm ) , _SD ( mp4 , webm ) , _Low ( mp4, webm )

akhilleusuggo avatar Oct 06 '20 21:10 akhilleusuggo

@DanielnetoDotCom image

akhilleusuggo avatar Oct 07 '20 15:10 akhilleusuggo

I just released a new encoder (v3.3) and a new streamer (v9.6) that handle separately webm and MP4 files, also the new encoder create the resolutions dynamically just like we do for HLS

DanielnetoDotCom avatar Oct 13 '20 13:10 DanielnetoDotCom

I saw it , and I can't believe it . I'm debugging it on my local server before I git pull . Amazing !

akhilleusuggo avatar Oct 13 '20 13:10 akhilleusuggo

I hope you enjoy!

DanielnetoDotCom avatar Oct 13 '20 13:10 DanielnetoDotCom

send me any bugs related to it you find.

I have my head up today for this new release.

DanielnetoDotCom avatar Oct 13 '20 13:10 DanielnetoDotCom

So , first you should remove the command line with the b:v .

image

Basically you're putting all resolutions to be set to 1MB . We should have something like HLS , where we can control how much bitrate for each resolution . For MP4 it's fine , since we have the crf ( this feature is strict to crf ) . webm does not really work on the same way as libx264 .

But I'll give it a try and fine something where we can rate limit the bitrate .

akhilleusuggo avatar Oct 13 '20 14:10 akhilleusuggo

so just remove -b:v 1M is fine ???

DanielnetoDotCom avatar Oct 13 '20 17:10 DanielnetoDotCom

no , we really need something like HLS ;

$height = self::getResolution($pathFileName);
            $resolutions = array(360, 480, 720, 1080, 1440, 2160);
            $bandwidth = array(600000, 1000000, 2000000, 4000000, 8000000, 12000000);
            //$videoBitrate = array(472, 872, 1372, 2508, 3000, 4000);

akhilleusuggo avatar Oct 13 '20 22:10 akhilleusuggo

Ok,

we have the following formats ...

  1. 2160p: 3840x2160
  2. 1440p: 2560x1440
  3. 1080p: 1920x1080
  4. 720p: 1280x720
  5. 480p: 854x480
  6. 360p: 640x360
  7. 240p: 426x240

what would be the best -b:v value for each of it?

DanielnetoDotCom avatar Oct 13 '20 23:10 DanielnetoDotCom

what would be the best -b:v value for each of it? There's no exact value . For example on my site I upload very often videos 1080p/60fps , is not the same value for 1080/30fps .

I also use Variable framerate option . In case a video is lower then 60 FPS , will not transcode it to 60 FPS . If it's higher then 60 , neither will be transcoded to 60 FPS . I'm using a limiter .

I just need to be able to add a value . The best result quality/bitrate is to bet crf with limiter ( maxrate ) . This way , if the source video does not require higher bitrate , will be low . But if a video want to go for 10mb , will be limited by the maxrate .

Containing the bitrate, only this way we can achieve the best value disk-space/quality .

akhilleusuggo avatar Oct 13 '20 23:10 akhilleusuggo

Ok , I can see you have added some variables that I haven't seen before . But look at the HLS ;

-c:v h264 -vf scale=-2:{$resolution} -r 24 -g 48 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -minrate {$minrate}k -crf 23 -maxrate {$maxrate}k -bufsize {$bufsize}k -c:a aac -b:a {$autioBitrate}k -f hls -hls_time 6 -hls_list_size 0 -hls_key_info_file {$destinationFile}keyinfo {$destinationFile}res{$resolution}/index.m3u8

-minrate {$minrate} , -maxrate {$maxrate}k . How can I add this values to the MP4/WEBM ?

akhilleusuggo avatar Oct 13 '20 23:10 akhilleusuggo

I have to change the code for that,

tell me what would be the best variables/code combination, I will add the variables to replace the code.

DanielnetoDotCom avatar Oct 14 '20 12:10 DanielnetoDotCom

If you gonna change the code , make sure you can add an option for the framerate . Videos of 480p or under should have 30FPS maximum .

On the code , we need something like this that work ; https://github.com/WWBN/AVideo-Encoder/blob/b353fac2a1a51d02f0e0f01bc2fc096007bee0fb/objects/Format.php#L425

foreach ($resolutions as $key => $value) {
                if ($height >= $value) {
                    $resolution = $value;
                    $rate = $bandwidth[$key] / 1000;
                    $minrate = ($rate * 0.5);
                    $maxrate = ($rate * 1.5);
                    $bufsize = ($rate * 2);
                    $autioBitrate = $audioBitrate[$key];

This way , each can adapt it to it's needs. I don't know if possible or not , but an array for $frameRate would be very useful . This way , we can encode ( 240 to 20FPS ) , 360-480 to 30 FPS , 720,1080.... to 60 ( if the source got 60 fps )

akhilleusuggo avatar Oct 14 '20 15:10 akhilleusuggo

Yes, an array is possible, you need to add 7 framerates, one for each resolution

  1. 2160p: 3840x2160
  2. 1440p: 2560x1440
  3. 1080p: 1920x1080
  4. 720p: 1280x720
  5. 480p: 854x480
  6. 360p: 640x360
  7. 240p: 426x240

what will be the best framerate for each of this?

But what I most need your help is to see how the FFMPEG code will look like, currently I have this

HLS

-c:v h264 -vf scale=-2:{$resolution} -r 24 -g 48 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -minrate {$minrate}k -crf 23 -maxrate {$maxrate}k -bufsize {$bufsize}k -c:a aac -b:a {$autioBitrate}k -f hls -hls_time 6 -hls_list_size 0 -hls_key_info_file {$destinationFile}keyinfo {$destinationFile}res{$resolution}/index.m3u8

MP4

-vf scale=-2:{$resolution} -movflags +faststart -preset veryfast -vcodec h264 -acodec aac -strict -2 -b:a {$autioBitrate}k -max_muxing_queue_size 1024 -y {$destinationFile}

WEBM

-vf scale=-2:{$resolution} -movflags +faststart -preset veryfast -f webm -c:v libvpx -b:v 1M -acodec libvorbis -b:a {$autioBitrate}k -y {$destinationFile}

DanielnetoDotCom avatar Oct 14 '20 16:10 DanielnetoDotCom

Something like this :

MP4

-vf scale=-2:{$resolution} -c:v h264 -crf 23 -preset veryfast -r {$frameRate} -minrate {$minrate}k -maxrate {$maxrate}k -bufsize {$bufsize}k -movflags +faststart -c:a aac -strict -2 -b:a {$autioBitrate}k -max_muxing_queue_size 1024 -y {$destinationFile}

The webm doesn't differ so much , just different parameters of the codec .

akhilleusuggo avatar Oct 14 '20 16:10 akhilleusuggo

Team, I really appreciate the tool and the new feature, but is there a way to automatically encode all video as (low) 360p? Thanks!

itpastor avatar Oct 16 '20 22:10 itpastor

@itpastor select all this features , except the ones I have highlighted , clear the cache afterward .

image

akhilleusuggo avatar Oct 16 '20 23:10 akhilleusuggo

Got it. However I don’t have the option for ShowOnlyEncoderAutomaticResolutions. I just installed today, but perhaps my version is older? EE3F6812-28C3-4B00-B0E0-CBD5AA6296A5 1E0683B9-608E-4145-A4B2-6CB54F342E07

itpastor avatar Oct 17 '20 00:10 itpastor

Please use desktop to debug things .

akhilleusuggo avatar Oct 17 '20 02:10 akhilleusuggo

@DanielnetoDotCom Any update ? You asked about an example ;

Yes, an array is possible, you need to add 7 framerates, one for each resolution But what I most need your help is to see how the FFMPEG code will look like, currently I have this

This is how it should like ;

Something like this :

MP4

-vf scale=-2:{$resolution} -c:v h264 -crf 23 -preset veryfast -r {$frameRate} -minrate {$minrate}k -maxrate {$maxrate}k -bufsize {$bufsize}k -movflags +faststart -c:a aac -strict -2 -b:a {$autioBitrate}k -max_muxing_queue_size 1024 -y {$destinationFile}

The webm doesn't differ so much , just different parameters of the codec .

akhilleusuggo avatar Oct 20 '20 13:10 akhilleusuggo

@DanielnetoDotCom I'm still waiting for this . Because this feature will save a lot of disk space and encoding time . Right now I'm re-transcoding them manually with a bash script ...

akhilleusuggo avatar Nov 04 '20 21:11 akhilleusuggo

Hi

what are the valid/good framerates for each of those?

  • 2160p: 3840x2160
  • 1440p: 2560x1440
  • 1080p: 1920x1080
  • 720p: 1280x720
  • 480p: 854x480
  • 360p: 640x360
  • 240p: 426x240

DanielnetoDotCom avatar Nov 09 '20 19:11 DanielnetoDotCom

well , 240p ; 20FPS 360p ; 30FPS 480p; 30FPS 720,1080,1440,2160 ; Native FPS basically ( or skip the -r flag , or give it variable framerate ) .

Would be cool if we could change it , even if from the script .

akhilleusuggo avatar Nov 10 '20 06:11 akhilleusuggo

@DanielnetoDotCom This feature is really getting costly for high quality videos if they're not limited . Can you please add this ? You asked about an example , I gave it . When you got some time , please take a look .

akhilleusuggo avatar Nov 29 '20 16:11 akhilleusuggo

If you add {$framerate} in your configuration it will add a framerate rule

For example: -vf scale=-2:{$resolution} -movflags +faststart -preset veryfast -f webm -c:v libvpx -b:v 1M -acodec libvorbis -b:a {$autioBitrate}k {$framerate} -y {$destinationFile}

DanielnetoDotCom avatar Nov 30 '20 16:11 DanielnetoDotCom

God bless you ! $videoFramerate = array(20, 30, 30, 0, 0, 0); Does the 0 means same as source ?

akhilleusuggo avatar Nov 30 '20 17:11 akhilleusuggo

Yes, if it is 0, it will ignore the -r parameter

so if it is a 240p video the command will be:

-vf scale=-2:{$resolution} -movflags +faststart -preset veryfast -f webm -c:v libvpx -b:v 1M -acodec libvorbis -b:a {$autioBitrate}k -r 20 -y {$destinationFile}

if it is a 720p or greater it will be:

-vf scale=-2:{$resolution} -movflags +faststart -preset veryfast -f webm -c:v libvpx -b:v 1M -acodec libvorbis -b:a {$autioBitrate}k -y {$destinationFile}

Without the -r

DanielnetoDotCom avatar Nov 30 '20 17:11 DanielnetoDotCom

@DanielnetoDotCom I think there's you missed the 240p .

With your array structure , the 20FPS will affect the 360p not the 240p , since the 240p is executed alone .

// create command
            $value = 240;
            $resolution = $value;
            $minrate = 200;
            $maxrate = 450;
            $bufsize = 600;
            $autioBitrate = 128;

            $command = get_ffmpeg().' -i {$pathFileName} ';
            eval("\$command .= \" $code\";");

akhilleusuggo avatar Nov 30 '20 17:11 akhilleusuggo