Capturing rtmp to m4a on OSX
Computing 2014. 12. 11. 17:17After trying several ways to achieve the mission: libav, rtmpdump, etc. I finally landed on a method that utilizes vlc. Bravo vlc!!!
1. Install VLC
2. Run following command:
/Applications/VLC.app/Contents/MacOS/VLC -I dummy rtmp://ebsandroid.ebs.co.kr/fmradiofamilypc/familypc1m vlc://quit --no-sout-video --sout-audio --no-sout-rtp-sap --no-sout-standard-sap --ttl=1 --sout-keep --sout "#transcode{acodec=s16l,channels=2}:std{access=file,mux=wav,dst=1.wav}" 2> /dev/null
3. Convert resulting wav file to m4a file:
/usr/bin/afconvert -f mp4f -d aac -q 127 1.wav 1.m4a
Why not let vlc directly save output in mp3 format?
Because, the sound quality is not quite good. It left me with no choice but to record using wav format and then convert it to aac format.
#!/bin/bash
ABSPATH_SELF=$(cd $(dirname $0); pwd -P)
if [ $# -ne 2 ];
then
echo "Usage: $0 filename duration(unit:min)"
exit 1
fi
FILENAMEROOT=$1
DURATION=$(($2 * 60))
DATE=$(date +"%Y-%m-%d")
WEEKDAY=$(date +"%A")
if [ "${WEEKDAY}" == "Monday" -o "${WEEKDAY}" == "Tuesday" -o "${WEEKDAY}" == "Wednesday" ];
then
LEVEL="초급"
else
LEVEL="중급"
fi
FILENAME1="${ABSPATH_SELF}/${FILENAMEROOT}-${DATE}.m4a"
FILENAME2="${ABSPATH_SELF}/${FILENAMEROOT}-${DATE}(${WEEKDAY}-${LEVEL}).m4a"
FILENAME3="${ABSPATH_SELF}/${FILENAMEROOT}-${DATE}(${WEEKDAY_KOR}).m4a"
EBS_RADIO_URL="rtmp://ebsandroid.ebs.co.kr/fmradiofamilypc/familypc1m"
TMP_WAVFILE="${FILENAME1}.wav"
/Applications/VLC.app/Contents/MacOS/VLC -I dummy ${EBS_RADIO_URL} vlc://quit --no-sout-video --sout-audio --no-sout-rtp-sap --no-sout-standard-sap --ttl=1 --sout-keep --sout "#transcode{acodec=s16l,channels=2}:std{access=file,mux=wav,dst=${TMP_WAVFILE}}" 2> /dev/null &
VLC_PID=$!
sleep ${DURATION}
kill -TERM ${VLC_PID}
sleep 10
/usr/bin/afconvert -f mp4f -d aac -q 127 ${TMP_WAVFILE} ${FILENAME1}
if [ "${FILENAMEROOT}" == "Chinese" -o "${FILENAMEROOT}" == "Japanese" ];
then
mv ${FILENAME1} ${FILENAME2}
else
mv ${FILENAME1} ${FILENAME3}
fi
rm -f ${TMP_WAVFILE}
EBS streaming rtmp address list
rtmp://ebsandroid.nefficient.com/groundwavefamilypc/familypc1m"; // 지상파HD
rtmp://ebsandroid.nefficient.com/ebsufamilypc/familypc1m"; //EBSu HD
rtmp://ebsandroid.nefficient.com/fmradiofamilypc/familypc1m"; //FM 라디오 SD
rtmp://ebsandroid.nefficient.com/plus1familypc/familypc1m"; //Plus1 SD
rtmp://ebsandroid.nefficient.com/plus2familypc/familypc1m"; //Plus2 SD
rtmp://ebsandroid.nefficient.com/plus3familypc/familypc1m"; //Plus3 SD