2019年9月24日 星期二

[Ubuntu] 將 MOV 轉檔成 MP4 並且縮小檔案

這篇寫得很詳細
https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg

(BR)使用以下方法修改 bitrate
ffmpeg -i $infile -b $bitrate -strict -2 $newoutfile 

(CR) 使用以下方法改變恆定速率因子(Constant Rate Factor)
ffmpeg -i $infile -vcodec libx264 -crf 23 -strict -2 $outfile 

(SZ) 使用以下方法更改 screen-size(例如,將其更改為像素大小的一半)
ffmpeg -i $infile -vf "scale=iw/2:ih/2" -strict -2 $outfile 

(BL) 使用以下命令將 H.264 配置文件更改為"baseline"
ffmpeg -i $infile -profile:v baseline -strict -2 $outfile 

(DF) 使用預設的 ffmpeg 處理
ffmpeg -i $infile $outfile 

 結論:
(SZ) 方法無疑是最快的方法
(BR) 方法將 1080p 樣本的大小增加了一倍以上
(CR) 方法花費了 53 分鐘來轉換 21 分鐘的影片

2019年9月15日 星期日

[Python] 修復 numpy 爛掉

今天要載入 numpy 突然發現爛掉了。
$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 17, in 
    from . import multiarray
  File "/usr/local/lib/python3.5/dist-packages/numpy/core/multiarray.py", line 14, in 
    from . import overrides
  File "/usr/local/lib/python3.5/dist-packages/numpy/core/overrides.py", line 7, in 
    from numpy.core._multiarray_umath import (
ImportError: /usr/local/lib/python3.5/dist-packages/numpy/core/_multiarray_umath.cpython-35m-arm-linux-gnueabihf.so: undefined symbol: cblas_sgemm

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.5/dist-packages/numpy/__init__.py", line 142, in 
    from . import core
  File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 47, in 
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.5 from "/usr/bin/python3",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.2" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: /usr/local/lib/python3.5/dist-packages/numpy/core/_multiarray_umath.cpython-35m-arm-linux-gnueabihf.so: undefined symbol: cblas_sgemm

爬文了一下,單移除好像不行,不管是 pip3 uninstall 或是 apt-get remove 都沒有用。還是要使用 rm -rf 大法。
sudo rm -rf /usr/local/lib/python3.5/dist-packages/numpy
再重新安裝
sudo apt-get install python3-numpy
我的 numpy 又回來了,不過版本比較舊(1.12.1)
python3 -c 'import numpy; print(numpy.__version__)'

不過如果要裝 tensorflow-1.13.1,看起來這樣做比較穩。
sudo apt-get update
sudo apt-get install -y python3-dev python3-setuptools python3-numpy libblas-dev liblapack-dev libatlas-base-dev gfortran
sudo apt-get install -y python3-scipy

wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.13.1/tensorflow-1.13.1-cp35-none-linux_armv7l.whl
sudo pip3 install tensorflow-1.13.1-cp35-none-linux_armv7l.whl

sudo pip3 install h5py==2.8.0
sudo pip3 install keras 

可是預設 tensorflow-1.13.1 會搭配 numpy-1.17.2,這樣執行時會出現討厭的訊息。
Using TensorFlow backend.
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
  return f(*args, **kwds)
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)
根據這篇,還是要移掉 numpy 後再重新安裝舊一點的版本就可以了。
sudo pip3 uninstall numpy
sudo pip3 install numpy==1.16

2019年9月8日 星期日