zoukankan      html  css  js  c++  java
  • height not divisible by 2

    height not divisible by 2

    h.264 - FFMPEG (libx264) "height not divisible by 2" - Stack Overflow  https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2

    After playing around with this a bit, I think I've answered my own question. Here is the solution in case anyone else runs into a similar issue... I had to add the below argument to the command:

    -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
    

    Command:

    ffmpeg -r 24 -i frame_%05d.jpg -vcodec libx264 -y -an video.mp4 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
    

    Basically, .h264 needs even dimensions so this filter will:

    1. Divide the original height and width by 2
    2. Round it down to the nearest pixel
    3. Multiply it by 2 again, thus making it an even number

    尺寸调整为不大于的最小偶数

    from PIL import Image
    
    f = 'my.jpg'
    mid_icon = Image.open(f)
    h, w = mid_icon.height, mid_icon.width
    h, w = int(h / 2) * 2, int(w / 2) * 2
    mid_icon = mid_icon.resize((w, h), Image.ANTIALIAS)
    mid_icon.save(f)
    
    from PIL import Image
    
    
    def img_to_floor_even(f):
        try:
            fo = Image.open(f)
            w, h = fo.width, fo.height
            w_, h_ = int(w / 2) * 2, int(h / 2) * 2
            if (w, h) != (w_, h):
                fo = fo.resize((w_, h_), Image.ANTIALIAS)
                fo.save(f)
        except Exception as e:
            print(e)
            # log
    

      

      

      

  • 相关阅读:
    Python 正则表达式简单了解
    scrapy 框架简单 爬取 4K高清 壁纸
    解决验证注解随机问题
    @ConfigurationProperties
    ConstraintValidator自定义注解
    通过日志解读Spring-Mybatis执行顺序
    Spring整合mybatis配置文件
    设计模式——代理模式
    Mybatis框架配置
    设计模式——单例模式
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9052019.html
Copyright © 2011-2022 走看看