やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

libavのインストール

ffmpegでなく。

ソースコード(失敗)

ダウンロード

$ wget https://libav.org/releases/libav-12.1.tar.xz
--2017-08-05 10:57:32--  https://libav.org/releases/libav-12.1.tar.xz
libav.org (libav.org) をDNSに問いあわせています... 5.148.163.142, 2a02:418:f022::1:0
libav.org (libav.org)|5.148.163.142|:443 に接続しています... 接続しました。
エラー: libav.org の証明書(発行者: `/C=US/O=Let\'s Encrypt/CN=Let\'s Encrypt Authority X3')の検証に失敗しました:
  発行された証明書は失効しています。
libav.org に安全の確認をしないで接続するには、`--no-check-certificate' を使ってください。
$ wget https://libav.org/releases/libav-12.1.tar.xz --no-check-certificate
--2017-08-05 10:57:48--  https://libav.org/releases/libav-12.1.tar.xz
libav.org (libav.org) をDNSに問いあわせています... 5.148.163.142, 2a02:418:f022::1:0
libav.org (libav.org)|5.148.163.142|:443 に接続しています... 接続しました。
警告: libav.org の証明書(発行者: `/C=US/O=Let\'s Encrypt/CN=Let\'s Encrypt Authority X3')の検証に失敗しました:
  発行された証明書は失効しています。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 5267292 (5.0M) [application/x-xz]
`libav-12.1.tar.xz' に保存中

100%[======================================>] 5,267,292    102KB/s   時間 31s  

2017-08-05 10:58:20 (165 KB/s) - `libav-12.1.tar.xz' へ保存完了 [5267292/5267292]

解凍

tar -xvf libav-12.tar.xz 

コンパイル

コマンドやオプションなど詳細がわからず……。

Synaptic(成功)

どれをインストールしていいかわからず。とりあえず適当に-devのを選択。

  • libavutil-dev
  • libavdevice-dev
  • libavfilter-dev
  • libavresample-dev

上記をインストール指定した。他はそれの依存関係にあたるものらしく、勝手に指定してくれた。

libavcodec54 (バージョン 6:9.18-0ubuntu0.14.04.1) はバージョン 6:9.20-0ubuntu0.14.04.1 にアップグレードされます
libavformat54 (バージョン 6:9.18-0ubuntu0.14.04.1) はバージョン 6:9.20-0ubuntu0.14.04.1 にアップグレードされます
libavutil52 (バージョン 6:9.18-0ubuntu0.14.04.1) はバージョン 6:9.20-0ubuntu0.14.04.1 にアップグレードされます
libavcodec-dev (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavdevice-dev (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavdevice53 (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavfilter-dev (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavfilter3 (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavformat-dev (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavresample-dev (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavresample1 (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます
libavutil-dev (バージョン 6:9.20-0ubuntu0.14.04.1) がインストールされます

f:id:ytyaru:20170805112813p:plainf:id:ytyaru:20170805112818p:plainf:id:ytyaru:20170805112822p:plainf:id:ytyaru:20170805112826p:plainf:id:ytyaru:20170805112829p:plain

libav-tools

CUIツールと思われる。avconvコマンド。不要かもしれないが、ついでにインストールした。

$ avconv
avconv version 9.20-6:9.20-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Dec  7 2016 21:27:42 with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
Hyper fast Audio and Video encoder
usage: avconv [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man avconv'

ヘルプ

$ avconv -h
avconv version 9.20-6:9.20-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Dec  7 2016 21:27:42 with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
Hyper fast Audio and Video encoder
usage: avconv [options] [[infile options] -i infile]... {[outfile options] outfile}...

Getting help:
    -h      -- print basic options
    -h long -- print more options
    -h full -- print all options (including all format and codec specific options, very long)
    See man avconv for detailed description of the options.

Print help / information / capabilities:
-L                  show license
-h topic            show help
-? topic            show help
-help topic         show help
--help topic        show help
-version            show version
-formats            show available formats
-codecs             show available codecs
-decoders           show available decoders
-encoders           show available encoders
-bsfs               show available bit stream filters
-protocols          show available protocols
-filters            show available filters
-pix_fmts           show available pixel formats
-sample_fmts        show available audio sample formats

Global options (affect whole program instead of just one file:
-loglevel loglevel  set libav* logging level
-v loglevel         set libav* logging level
-y                  overwrite output files
-stats              print progress report during encoding
-vol volume         change audio volume (256=normal)

Per-file main options:
-f fmt              force format
-c codec            codec name
-codec codec        codec name
-pre preset         preset name
-map_metadata outfile[,metadata]:infile[,metadata]  set metadata information of outfile from infile
-t duration         record or transcode "duration" seconds of audio/video
-fs limit_size      set the limit file size in bytes
-ss time_off        set the start time offset
-metadata string=string  add metadata
-target type        specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...)
-frames number      set the number of frames to record
-filter filter_list  set stream filterchain

Video options:
-vframes number     set the number of video frames to record
-r rate             set frame rate (Hz value, fraction or abbreviation)
-s size             set frame size (WxH or abbreviation)
-aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-vn                 disable video
-vcodec codec       force video codec ('copy' to copy stream)
-pass n             select the pass number (1 or 2)
-vf filter list     video filters

Audio options:
-aframes number     set the number of audio frames to record
-aq quality         set audio quality (codec-specific)
-ar rate            set audio sampling rate (in Hz)
-ac channels        set number of audio channels
-an                 disable audio
-acodec codec       force audio codec ('copy' to copy stream)
-vol volume         change audio volume (256=normal)
-af filter list     audio filters

Subtitle options:
-sn                 disable subtitle
-scodec codec       force subtitle codec ('copy' to copy stream)
-stag fourcc/tag    force subtitle tag/fourcc

変換してみた

CMajor.wavは32.0kB。

コマンド ファイルサイズ 説明
avconv -i CMajor.wav -c:a alac CMajor.m4a 17.9kB 生成できず
avconv -i CMajor.wav CMajor.mp3 2.3kB 音質が残念
avconv -i CMajor.wav CMajor.ogg 11.9kB
avconv -i CMajor.wav CMajor.flac 20.0kB

音質、ライセンス、デコード負荷を考えると、flacが最善か。

https://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwia6vvIjL_VAhUJjLwKHVUsB68QFggvMAE&url=http%3A%2F%2Fplaza.rakuten.co.jp%2Fohachige%2Fdiary%2F201307060000%2F&usg=AFQjCNFCMRz3NtNrauor2i71ohYqT4Q_JA

細かい調整をすれば結果は変わるのかもしれない。

MP3

http://d.hatena.ne.jp/m-kawato/20130114/1358155410

$ avconv -i CMajor.wav -c:a libmp3lame -b:a 16k CMajor16.mp3
$ avconv -i CMajor.wav -c:a libmp3lame -b:a 32k CMajor32.mp3
$ avconv -i CMajor.wav -c:a libmp3lame -b:a 64k CMajor64.mp3
$ avconv -i CMajor.wav -c:a libmp3lame -b:a 128k CMajor128.mp3
$ avconv -i CMajor.wav -c:a libmp3lame -b:a 196k CMajor196.mp3
bps FileSize(kB) 備考
16 4.5 音質が悪くなった
32 9.0
64 17.9
128 18.5
196 18.8

32kbpsが良さそう。

所感

とりあえず音声ファイルの変換はできるようになった。このくらい標準装備でできるようにして欲しい。

各コーデック別に引数を調べるのが大変そう。