임베디드 | 라즈베리파이 | ARM | 리눅스 | Qt | 딥러닝

라즈베리파이에서 ffmpeg 를 이용하여 

안드로이드 녹음파일인 amr 을 mp3로 변환하려고 한다.


라즈베리파이에서 ffmpeg를 이용하려면

ffmpeg 를 설치해야하는데

설치 방법은


1. 남이 미리 컴파일한 것을 사용하여 ffmpeg 명령어를 사용하거나

2. 라즈베리파이내에서 컴파일하여 사용하던가

3. 크로스컴파일을 이용한 후 ffmpeg 을 복사해서 사용하면된다.




남이 미리 컴파일 한것을 사용하여 ffmpeg 명령어 사용하고 싶을경우

여기 링크를 남겨둔다

https://fattylewis.com/latest-ffmpeg-compiled-for-rasbian/


안타깝게도 위 링크는 ffmpeg 명령어는 되나. mp3 로의 변환은 지원안한다.





ffmpeg 명령어

 ffmpeg -i ../rectest.amr -c:v libmp3lame   -b:a 24k output.mp3

ffmpeg -i x.amr output.mp3

ffmpeg -i audio.aac -acodec libmp3lame -ac 2 -ab 160 audio.mp3


mp3 코덱 사용하기위한 설치 옵션

https://trac.ffmpeg.org/wiki/How%20to%20quickly%20compile%20FFmpeg%20with%20mp3,%20aac%2B%20and%20x264

1.  libfdk-aac 설치 

https://trac.ffmpeg.org/wiki/CompilationGuide/Quick/libfdk-aac

2. libavcodec 설치 ->

sudo apt-get install libavcodec-extra-*

3.  libmp3lame-dev 설치

sudo apt-get install libmp3lame-dev

4. 

# ./configure --enable-gpl --enable-libx264 --enable-libmp3lame --enable-nonfree --enable-libfdk-aac
# make
# make install

그리고 위와 같이 ffmpeg 를 다시 make 해주면된다.


중간에

컴파일 에러가 나타났는데

libavfilter/libavfilter.a: error adding symbols: File in wrong for

이러한 에러가 나타나면

make clean 해주고

다시 make 하면 잘 된다




크로스컴파일 명령어는

./configure --enable-cross-compile --cross-prefix=${CCPREFIX} --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-libmp3lame --extra-ldflags=-L/home/ko/rasp/ffmpeg/lame-3.99/libmp3lame/.libs --extra-cflags=-I/home/ko/rasp/ffmpeg/lame-3.99/include

./configure --enable-cross-compile --cross-prefix=${CCPREFIX} --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-libmp3lame --extra-ldflags=-L/home/ko/rasp/ffmpeg/lame-3.99/libmp3lame/.libs --extra-cflags=-I/home/ko/rasp/ffmpeg/lame-3.99/libmp3lame/.libs 



./configure --enable-cross-compile --cross-prefix=
${CCPREFIX} --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-libmp3lame --host-ldflags=-L/home/ko/rasp/ffmpeg/lame-3.99/libmp3lame/.libs



lame 설정시 --enable-nonfree 지워야 한다고함

./configure --enable-cross-compile --cross-prefix=${CCPREFIX} --arch=armel --target-os=linux //안됨

./configure --host=arm-linux --enable-static




크로스컴파일 설명

https://gist.github.com/daz/0fecfb80dca969c0a3b4

http://www.jeffreythompson.org/blog/2014/11/13/installing-ffmpeg-for-raspberry-pi/

https://trac.ffmpeg.org/wiki/CompilationGuide/RaspberryPi



mp3 코덱이 제대로 설치되었나 확인

ffmpeg -codecs | grep mp3


fmpeg version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers

  built on Mar 31 2013 13:58:10 with gcc 4.6.3

  EA    libmp3lame      libmp3lame MP3 (MPEG audio layer 3)

 D A D  mp3             MP3 (MPEG audio layer 3)

 D A D  mp3adu          ADU (Application Data Unit) MP3 (MPEG audio layer 3)

 D A D  mp3adufloat     ADU (Application Data Unit) MP3 (MPEG audio layer 3)

 D A D  mp3float        MP3 (MPEG audio layer 3)

 D A D  mp3on4          MP3onMP4

 D A D  mp3on4float     MP3onMP4

이렇게 설치되어있어야 한다




설정 lime 설치시 크로스 컴파일 설정

https://gist.github.com/vtajzich/7577876

./configure  --host=arm-unknown-linux-gnueabi


sudo ldconfig

by using ldconfig to configure the dynamic linker run-time bindings:

https://retroresolution.com/2016/05/31/compiling-software-from-source-code-on-the-raspberry-pi-the-ffmpeg-suite/



시스템 체크

locate lame/lame.h


config.log 애서 lame 확인 "check_lib lame"


find -name 'libmp3lame*'

nm /home/ko/rasp/ffmpeg/lame-3.99/libmp3lame/.libs/libmp3lame.so | grep set_VBR_quality



tar -zxvf lame-3.99.5.tar.gz 

cd lame-3.99.5

./configure

make

sudo make install

locate libmp3lame.a   //어디있나 확인 

--extra-ldflags=-L/usr/local/lib




https://www.bitpi.co/2015/08/19/how-to-compile-ffmpeg-on-a-raspberry-pi/

http://owenashurst.com/?p=242