A
A
Alexander2019-10-08 09:22:20
fmpeg
Alexander, 2019-10-08 09:22:20

Ffmpeg (debian) how to properly modify the command for vertical video?

Hello dear experts. Need help with the team.
I already have a ready-made command that converts video on the server when uploaded by the user. And there is even a check for a vertical video so that it automatically flips. But I would also like to do, as they do everywhere now, with a vertical video, blurry edges, instead of a black background. Who knows how to finalize a ready-made team for such needs?
To begin with, I get data about the video, whether it is rotated using the function

function search_array_returnKey($haystack, $needles) {
 	$res = '';
 	// Если пришел массив, то проверяем его
    if ( is_array($needles) ) {
    	// Начинаем обработку цикла
        foreach ($needles as $keyStr => $str) {
            if ( is_array($str) ) {
            // Если есть многомерный массив, то перебираем в цикле
                $pos = strpos_array($haystack, $str);
            } else {
            	// выполняем поиск в ключе
                $pos = strpos($str, $haystack);
            }

            if ($pos !== FALSE) {
            	// Результат есть - записываем и заканчиваем обработку цикла
            	$keyMass = $keyStr;
                break;
            }
        }
    } else {
        $pos = strpos($needles, $haystack);
    }
                    if(isset($keyMass)){return $keyMass;}else{return 0;}

 }
$rotate = search_array_returnKey("rotate", $ret);
    	       if(isset($rotate) && $rotate != '0'){$strRotate = explode(":", $ret[$rotate]);$rotateRES = preg_replace('/\s/', '', $strRotate[1]);$rotateImg = $rotateRES;}

As a result, I wrote the data to a variable and then to the database, so that when converting, I know the position of the video....
# После запроса данных из БД собираю команду
# Подготовим разворот видео, если было запрошено
        if($video['rotate'] == '0' || $video['rotate'] == '360' || $video['rotate'] == ''){$vr = '';}
        if($video['rotate'] == '90'){$vr = '-vf "transpose=1"';} // 90 градусов по часовой
        if($video['rotate'] == '180'){$vr = '-vf "transpose=1,transpose=1"';} // 180 градусов по часовой
        if($video['rotate'] == '270'){$vr = '-vf "transpose=2"';} // 270 градусов по часовой
$cmd = 'ffmpeg -y -i '.$catUpl.'/'.$dirDn.'/noconvert_'.$video['realname'].' -map_metadata -1 -map 0:v:0 -map 0:a:0 -vcodec h264 -pix_fmt yuv420p -vsync 1 -async 1 -color_primaries 1 -color_trc 1 -colorspace 1 -vf scale="\'w=if(gt(a,16/9),640,-2):h=if(gt(a,16/9),-2,360)\'" '.$vr.' -crf 20 -preset medium -profile:v baseline -level 3.0 -maxrate 800k -bufsize 1200k -ac 2 -c:a libfdk_aac -b:a 128k -f mp4 -movflags +faststart '.$catUpl.'/'.$dirDn.'/'.$video['realname'].' 2>&1';
# Запускаю конвертирование
    	exec($cmd,$retRES);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-10-08
@sergiks

Here is the command for this effect:

ffmpeg \
  -i input.mp4 \
  -lavfi '[0:v] scale=ih*16/9:-1, boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];  [bg][0:v]overlay=(W-w)/2:(H-h)/2, crop=h=iw*9/16' \
  -vb 800K \
  output.webm

Example: original video and result .
Adapt to your task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question