mp3ファイルの編集(分割(split)と結合(concatenate))

March 8, 2011 – 11:15 am

mp3ファイルを編集(分割(split)、結合(concatenate))する方法についてメモしておいた。
radiko などからストリーミングデータをダウンロードしてmp3ファイルに変換したのち、これを編集し自分独自のオーディオアルバムを作成に活用できる。

mp3ファイルの分割: ffmpegを用いて簡単にmp3ファイルを分割することができる。

以下に、Original.mp3ファイルを0秒から300秒までをcut01.mp3に抽出、分割する例を示す:

[root@localhost work]# ffmpeg -i Original.mp3 -ss 0 -t 300 cut01.mp3
FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
  built on Dec  4 2010 15:37:20 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables' --enable-avfilter --enable-avfilter-lavf --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.11. 0 /  0.11. 0
  libpostproc   51. 2. 0 / 51. 2. 0
[mp3 @ 0x8512850]max_analyze_duration reached
[mp3 @ 0x8512850]Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'ORIGINAL.mp3':
  Metadata:
    TSSE            : Lavf52.64.2
  Duration: 02:00:00.02, start: 0.000000, bitrate: 64 kb/s
    Stream #0.0: Audio: mp3, 48000 Hz, 2 channels, s16, 64 kb/s
Output #0, mp3, to 'cut01.mp3':

なお、ffmpegのインストールについては、「radiko の録音・再生方法を検討した」に記している。

mp3ファイルの結合: 複数のmp3ファイルを結合し、大きな単一のmp3ファイルを作成には、オープンソースmp3wrapを用いることができる。

以下に,3つのmp3ファイル、cut01.mp3、cut02.mp3、cut03.mp3を結合し、concat.mp3を作成した例を示す:

[root@localhost audio]# mp3wrap concat.mp3 cut01.mp3 cut02.mp3 cut03.mp3
Mp3Wrap Version 0.5 (2003/Jan/16). See README and COPYING for more!
Written and copyrights by Matteo Trotta - 
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!

  33 %  --> Wrapping cut01.mp3 ... OK
  66 %  --> Wrapping cut02.mp3 ... OK
  100 % --> Wrapping cut03.mp3 ... OK

  Calculating CRC, please wait... OK

concat_MP3WRAP.mp3 has been created successfully!
Use mp3splt to dewrap file; download at http://mp3splt.sourceforge.net!

mp3wrapのダウンロードとインストール: mp3wrapのソースを http://mp3wrap.sourceforge.net/ からダウンロードし、コンパイル、インストールのための一連の手続きについて、以下示す。

mp3wrapのダウンロード:

[root@localhost work]# wget http://prdownloads.sourceforge.net/mp3wrap/mp3wrap-0.5-src.tar.gz?download
--2011-03-07 15:50:22--  http://prdownloads.sourceforge.net/mp3wrap/mp3wrap-0.5-src.tar.gz?download
prdownloads.sourceforge.net をDNSに問いあわせています... 216.34.181.59
prdownloads.sourceforge.net|216.34.181.59|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 301 Moved Permanently
場所: http://downloads.sourceforge.net/project/mp3wrap/mp3wrap/mp3wrap%200.5/mp3wrap-0.5-src.tar.gz?download= [続く]
--2011-03-07 15:50:23--  http://downloads.sourceforge.net/project/mp3wrap/mp3wrap/mp3wrap%200.5/mp3wrap-0.5-src.tar.gz?download=
downloads.sourceforge.net をDNSに問いあわせています... 216.34.181.59
prdownloads.sourceforge.net:80 への接続を再利用します。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: http://jaist.dl.sourceforge.net/project/mp3wrap/mp3wrap/mp3wrap%200.5/mp3wrap-0.5-src.tar.gz [続く]
--2011-03-07 15:50:23--  http://jaist.dl.sourceforge.net/project/mp3wrap/mp3wrap/mp3wrap%200.5/mp3wrap-0.5-src.tar.gz
jaist.dl.sourceforge.net をDNSに問いあわせています... 150.65.7.130, 2001:200:141:feed::feed
jaist.dl.sourceforge.net|150.65.7.130|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 113008 (110K) [application/x-gzip]
`mp3wrap-0.5-src.tar.gz' に保存中

100%[==============================================================>] 113,008     --.-K/s 時間 0.1s    

2011-03-07 15:50:24 (860 KB/s) - `mp3wrap-0.5-src.tar.gz' へ保存完了 [113008/113008]

mp3wrapの解凍とコンパイル、インストール:

[root@localhost work]# tar zxvf mp3wrap-0.5-src.tar.gz

[root@localhost work]# cd mp3wrap-0.5

[root@localhost mp3wrap-0.5]# ls
AUTHORS    Makefile.am  aclocal.m4      configure.ac  doc            mp3wrap.1   wrap.c
COPYING    Makefile.in  autom4te.cache  crc.c         install-sh     mp3wrap.c   wrap.h
ChangeLog  NEWS         config.status   crc.h         missing        mp3wrap.h
INSTALL    README       configure       depcomp       mkinstalldirs  stamp-h.in


[root@localhost mp3wrap-0.5]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets ${MAKE}... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for a BSD-compatible install... /usr/bin/install -c
checking whether byte ordering is bigendian... no
checking for gcc option to accept ANSI C... none needed
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for memset... yes
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdlib.h... (cached) yes
checking for working malloc... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: executing default-1 commands

[root@localhost mp3wrap-0.5]# make
source='mp3wrap.c' object='mp3wrap.o' libtool=no \
        depfile='.deps/mp3wrap.Po' tmpdepfile='.deps/mp3wrap.TPo' \
        depmode=gcc3 /bin/sh ./depcomp \
        gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"mp3wrap\" -DVERSION=\"0.5\" -DHAVE_MEMSET=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1  -I. -I.     -g -O2 -c `test -f mp3wrap.c || echo './'`mp3wrap.c
source='wrap.c' object='wrap.o' libtool=no \
        depfile='.deps/wrap.Po' tmpdepfile='.deps/wrap.TPo' \
        depmode=gcc3 /bin/sh ./depcomp \
        gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"mp3wrap\" -DVERSION=\"0.5\" -DHAVE_MEMSET=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1  -I. -I.     -g -O2 -c `test -f wrap.c || echo './'`wrap.c
wrap.c: In function ‘charat’:
wrap.c:36: 警告: incompatible implicit declaration of built-in function ‘strlen’
wrap.c: In function ‘cindexsize’:
wrap.c:60: 警告: incompatible implicit declaration of built-in function ‘strlen’
wrap.c: In function ‘buildindex’:
wrap.c:70: 警告: incompatible implicit declaration of built-in function ‘strncpy’
wrap.c:70: 警告: incompatible implicit declaration of built-in function ‘strlen’
source='crc.c' object='crc.o' libtool=no \
        depfile='.deps/crc.Po' tmpdepfile='.deps/crc.TPo' \
        depmode=gcc3 /bin/sh ./depcomp \
        gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"mp3wrap\" -DVERSION=\"0.5\" -DHAVE_MEMSET=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1  -I. -I.     -g -O2 -c `test -f crc.c || echo './'`crc.c
gcc  -g -O2   -o mp3wrap  mp3wrap.o wrap.o crc.o  

[root@localhost mp3wrap-0.5]# make install
make[1]: ディレクトリ `/home/work/mp3wrap-0.5' に入ります
/bin/sh ./mkinstalldirs /usr/local/bin
  /usr/bin/install -c mp3wrap /usr/local/bin/mp3wrap
/bin/sh ./mkinstalldirs /usr/local/man/man1
mkdir /usr/local/man
mkdir /usr/local/man/man1
 /usr/bin/install -c -m 644 ./mp3wrap.1 /usr/local/man/man1/mp3wrap.1
make[1]: ディレクトリ `/home/work/mp3wrap-0.5' から出ます


  1. 1 Trackback(s)

  2. Oct 28, 2011: 自宅サーバー構築・覚書きリスト | Yama's Memorandum

Post a Comment