Efetuando cálculo de Aspect Ratio de vídeos em C/C++
Publicado por Mauricio Ferrari em 01/02/2023
[ Hits: 2.101 ]
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); } }
Instalando o UMPlayer no Deepin 20
Evitando Propagandas e Sites Golpistas no Google Chrome
PhotoGIMP 2020 - Transforme seu GIMP 2.10 no Photoshop
Letras Bacanas no seu Shell Script sem Figlet
printf("Criando Delay em Linguagem C de forma SIMPLES");
gcc: fatal error: cannot execute 'cc1plus': execvp: [...] - Como resolver no Linux Mint 20
FL-Av - Interface gráfica para ClamAV
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Solução rápida para o problema do Network Manager conectar mas não navegar
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
Controle do PS5 no Linux Mint funciona? (4)
Qual driver da NVIDIA instalar? (2)
Como instalar o KDE3 em Distros Atuais ou Quase (5)