[swscaler] Warning: data is not aligned! This can lead to a speedloss 的解決
相信如果你用了FFmpeg一段時間,對以下的黃色警告肯定不會陌生

這種刺眼的黃色警告(還會影響性能),對一個強迫症患者來說,實在是不能忍!
其實導緻報警的原因很簡單,就是swscaler的縮放的目标尺寸不合适,它想要的大小是 16 的倍數!
隻要簡單的代碼就解決掉這個讨厭的警告:
m_dst_h = (dst_h >> 4) << 4 ;
m_dst_w = (dst_w >> 4) <<4 ;
如果是按比例的話,就是:
float ratio = 1.0f * getSrcWidth()/getSrcHeight();
m_dst_h = (dst_h >> 4) << 4 ;
m_dst_w = (int(ratio * m_dst_h)>>4) <<4 ;
如圖,世界就清淨了
注意以上方法得到的尺寸是不大于原大小的,如果想得到不小于原大小尺寸,那麼就要改為以下方法:
size = (size + 0xf) & ~0xf;
如果想得到2次幂的寬高,且不小于原寬高,那麼改為以下方法:
int tmp = 1;
int w = bitmap.getWidth();
int h = bitmap.getHeight();
while (w > tmp || h > tmp) {
tmp <<= 1;
}
int width = tmp;
int height = tmp;