[태그:] wav

  • wav를 mp3로 변환

    ffmpeg을 사용하여 간단한 스크립트를 작성했다. 다 좋은데 ffmpeg을 반복하면 stdin로 무엇을 받아들인다. 파일을 제대로 못 읽는다. -nostdin 옵션과 </dev/null을 주었는데 무엇때문인지 모르겠으나 잘 된다.

    #!/bin/bash
    
    echo "wav 파일을 mp3로 변환하는 스크립트"
    echo "파일 이름은 그대로 유지"
    echo "확장자를 mp3로 변경"
    
    echo "인자로 filelist를 입력"
    
    
    cat $1 |\
    	while read CMD;
    		do
    			echo $CMD;
    			
    			directory=$(dirname "$CMD");
    			filename=$(basename -s ".wav" "$CMD"); 
    			fileindex=$(echo $filename | cut -d ' ' -f1);
    			number=$(echo $filename | cut -d' ' -f2);
    			#echo $directory;
    			#echo $filename;
    			#echo $number;
    			#echo $directory"/"$fileindex$number".mp3";
    			ffmpeg -nostdin -y -i "$CMD" $directory"/"$fileindex$number".mp3"; < /dev/null;
    
    		done
    

    아래 사이트 참조했다.

    https://stackoverflow.com/questions/21634088/execute-ffmpeg-command-in-a-loop
    https://stackoverflow.com/questions/6121091/get-file-directory-path-from-file-path/6121114
    https://askubuntu.com/questions/919788/convert-mp3-file-to-wav-using-the-command-line
    http://bahndal.egloos.com/595136