Efetuando cálculo de Aspect Ratio de vídeos em C/C++
Publicado por Mauricio Ferrari em 01/02/2023
[ Hits: 2.475 ]
Blog: https://www.youtube.com/@LinuxDicasPro
// Calculate the Aspect Ratios of given values
function get_aspectRatio(){
var resTd = document.getElementById("msg_status");
resTd.innerHTML = '';
if( (!document.getElementById('aspect_width').value.isNumber()) || (!document.getElementById('aspect_height').value.isNumber()) ){
resTd.innerHTML =
" <div class='alert alert-warning fade in' role='alert'> Invalid width or height entered </div>";
return;
}
var w=parseInt(document.getElementById('aspect_width').value);
var h=parseInt(document.getElementById('aspect_height').value);
if(h == 0 && w == 0){
resTd.innerHTML =
" <div class='alert alert-warning fade in' role='alert'> Please enter valid width and height values! </div>";
return;
}
if(h == 0 && w != 0){
resTd.innerHTML =
" <div class='alert alert-warning fade in' role='alert'> Please enter a valid height value! </div>";
return;
}
if(h!= 0 && w == 0){
resTd.innerHTML =
" <div class='alert alert-warning fade in' role='alert'> Please enter width </div>";
return;
}
if(h == w){
aspectRatio = '1 : 1';
}else{
var mode = null;
if(h>w)
{
dividend = h;
divisor = w;
mode ='portrait';
}
if(w>h){
dividend = w;
divisor = h;
mode = 'landscape';
}
var gcd = -1;
while(gcd == -1){
remainder = dividend%divisor;
if(remainder == 0){
gcd = divisor;
}else{
dividend = divisor;
divisor = remainder;
}
}
var hr = w/gcd;
var vr = h/gcd;
aspectRatio = (hr + ' : ' + vr);
}
$('.screen_mode').text(mode);
$('.final_aspect_ratio').text( aspectRatio );
$('.final_width').text(w);
$('.final_height').text(h);
$('.final_dimensions').text(w + ' × ' + h);
}
QString StatisticsWorker::convertAspectRatio(int x, int y) {
int w = x;
int h = y;
int dividend, divisor;
// Aqui, é definido se o arquivo multimídia é orientado em retrato ou paisagem.
// Se a largura(w) é igual a altura(h) o Aspect Ratio é 1:1 e dispensa detalhes.
if (h == w) {
return "1:1";
} else {
QString mode{};
if (h > w) {
// Orientação em retrato: altura/largura
dividend = h;
divisor = w;
mode = "Portrait";
} else if (w > h) {
// Orientação em paisagem: largura/altura
dividend = w;
divisor = h;
mode = "Landscape";
}
// A string ratio é definida com a orientação definida incluindo o resultado da divisão entre a largura e a altura ou vice-versa.
QString ratio{mode + " " + QString::number(((float)dividend / (float)divisor))};
// Aqui é que vem a calcular. gcd é definido como -1, que será definido um novo valor no loop quando remainder = 0.
uint gcd = -1;
int remainder;
while (gcd == -1) {
// remainder será o valor da sobra da operação.
remainder = dividend % divisor;
if (remainder == 0) {
// gcd será o divisor perfeito para a largura e a altura.
gcd = divisor;
} else {
// A próxima operação sempre será o resultado do divisor pela sobra.
dividend = divisor;
divisor = remainder;
}
}
QString hr = QString::number(w / gcd);
QString vr = QString::number(h / gcd);
return QString::fromLatin1("%1 (%2)").arg(hr + ":" + vr, ratio);
}
}
Transmageddon 1.5 no Slackware Current e no Python 3.9 - É sério!
Letras Bacanas no seu Shell Script sem Figlet
Corrigindo a Falha de Segmentação do VirtualBox 6.1.18 no Slackware Current [RESOLVIDO]
Ocenaudio no Slackware - uma alternativa mais simples ao Audacity
Comando 'cat' Colorido? Conheçam o 'ccat'
C compiler Cannot create executable?
Usando getch() no Linux, modo fácil
Limpando a tela sem NCURSES ou clrsrc() - DOS
CodeBlocks - IDE C++ no Ubuntu 12.04
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Jogar games da Battle.net no Linux com Faugus Launcher
Como fazer a Instalação de aplicativos para acesso remoto ao Linux
Como fazer a instalação do Samba
Como fazer a conversão binária e aplicar as restrições no Linux
Duas Pasta Pessoal Aparecendo no Ubuntu 24.04.3 LTS (19)
Formas seguras de instalar Debian Sid (13)
Malware encontrado em extensões do Firefox. (0)
Fiz uma pergunta no fórum mas não consigo localizar [RESOLVIDO] (21)









