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

  

  

height not divisible by 2的更多相关文章

  1. ffmpeg按比例缩放--"width / height not divisible by 2" 解决方法

    最近在处理视频的时候,有这么一个需求 如果视频的分辨率宽度大于960的话,就把宽度设为960,而高度按其比例进行缩放 如果视频的分辨率高度大于540的话,就把高度设为540,而宽度按其比例进行缩放 之 ...

  2. # [libx264 @ 00000275eb57fec0] height not divisible by 2 (520x325)

    # [libx264 @ 00000275eb57fec0] height not divisible by 2 (520x325)

  3. ffmpeg基本功能使用

    任务描述:由给定图像序列合成 24fps 视频 方案一 直接对图像进行操作,适用于图像名比较规范且默认即为所需顺序 ffmpeg -f image2 -i ./images_crop_%d.png - ...

  4. ffmpeg入门篇-滤镜的基本使用

    转发自白狼栈:查看原文 滤镜 什么是滤镜?百度百科介绍说"滤镜主要是用来实现图像的各种特殊效果......". 我们最早在ffmpeg是如何转码的一文中了解过滤镜,来回顾下当时的转 ...

  5. ffmpeg细节整理记录

    ffmpeg细节整理记录 1.-vcodec.-code:v.-c:v ffmpeg的官方文档 -vcodec 是 -code:v 别名. -vcodec codec (output) Set the ...

  6. [PyData] 03 - Data Representation

    Ref: http://blog.csdn.net/u013534498/article/details/51399035 如何在Python中实现这五类强大的概率分布 考虑下在mgrid上画二维概率 ...

  7. H5 canvas的 width、height 与style中宽高的区别

    Canvas 的width height属性 1.当使用width height属性时,显示正常不会被拉伸:如下 <canvas id="mycanvas" width=&q ...

  8. height:100% 布局

    常常会碰到需要填满整个浏览器,并且自适应高度的需求.首先肯定会想到给容器设定height:100%,但是会没有效果.原因是body没有高度,所以百分比无法生效. 解决方案:给html,body,标签都 ...

  9. 页面width与height使用百分比来划分不起作用解决办法--记录六

    有时候你写 <div style="width:80%;height:100%;border:1px solid red"></div> <div s ...

随机推荐

  1. TCP的链接过程

    ** TCP 三次握手 四次挥手** 客户端 服务器端 交互的模式 ---> 应答模式* 应答模式 ---> 客户端发起请求 服务器端回应请求** 客户端先去发起请求 ---> 查看 ...

  2. eclipse之版本代号

  3. Python:用户自定义异常

    实际开发中,有时候系统提供的异常类型不能满足开发的需求.这时候你可以通过创建一个新的异常类来拥有自己的异常.异常类继承自 Exception 类,可以直接继承,或者间接继承. 1.自定义异常类型 #1 ...

  4. Python中的列表(3)

    我们创建的列表元素的顺序是无法预测的,因为我们无法控制用户提供数据的顺序. 为了组织列表中的元素,所以Python帮我们提供一些方法用来排序列表中的元素. 1.方法 sort() 可以对列表永久性排序 ...

  5. 配置Django+mysql+pydev(x64)

    mysqldb需要安装64位的(http://ishare.iask.sina.com.cn/f/21839771.html),否则出现 import _mysql ImportError: DLL ...

  6. 【ZJOI2017 Round1练习&UVA1057】D6T1 Routing(DP,SPFA)

    题意:给你一个有向图, 并指定起点和终点. 问要从起点走向终点, 再从终点走向起点, 最少需要走过多少不同的节点. 对于 100%的数据, 有 N<=100, M<=min(1000,N* ...

  7. Linux下汇编语言学习笔记41 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  8. Query on a string

    You have two strings SS and TT in all capitals. Now an efficient program is required to maintain a o ...

  9. Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

    在操作hibernate数据库时,调用saveOrUpdate方法进行更新保存对象时, (1)ID为null时执行SAVE,但是前端jsp通过<input type="hidden&q ...

  10. 根据身份证号,取得行政区划的Javascript实现

    原文:http://www.cnblogs.com/baibaluo/archive/2011/06/03/2071255.html#2585076 项目里需要一个根据身份证号,取得发证地行政区划的的 ...