[태그:] ffmpeg

  • 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
  • ffmpeg으로 VOB를 MP4로 인코딩하기

    아래 사이트에서 참조.
    https://www.internalpointers.com/post/convert-vob-files-mkv-ffmpeg

    ffmpeg \
      -analyzeduration 100M -probesize 100M \
      -i output.vob \
      -map 0:1 -map 0:3 -map 0:4 -map 0:5 -map 0:6 \
      -metadata:s:a:0 language=ita -metadata:s:a:0 title="Italian stereo" \
      -metadata:s:a:1 language=eng -metadata:s:a:1 title="English stereo" \
      -metadata:s:s:0 language=ita -metadata:s:s:0 title="Italian" \
      -metadata:s:s:1 language=eng -metadata:s:s:1 title="English" \
      -codec:v libx264 -crf 21 \
      -codec:a libmp3lame -qscale:a 2 \
      -codec:s copy \
      output.mkv

    Let me dissect it:

    • -analyzeduration 100M -probesize 100M — keep this one so that FFmpeg is able to find hidden streams;
    • -i output.vob — the input file;
    • -map 0:1 -map 0:3 -map 0:4 -map 0:5 -map 0:6 — here I’m mapping the streams, namely I’m telling FFmpeg to keep Stream 0:1, Stream 0:3, Stream 0:4, Stream 0:5, Stream 0:6 and put them in the output file in that specific order;
    • -metadata[…] — this is used to give streams a title and other additional information, specifically to audio tracks (s:a:0 and s:a:1 where a stands for audio) and subtitles (s:s:0 and s:s:1 where s stands for subtitles);
    • -codec:v libx264 -crf 21 — defines the video codec in use and the constant rate factor (crf), namely the quality level. This method allows the encoder to keep a constant quality level, regardless the output file size: 0 is lossless, 23 is default, and 51 is worst possible. The sane range is between 18 and 28;
    • -codec:a libmp3lame -qscale:a 2 — defines the audio codec in use and the quality level: 0-3 will produce transparent results, 4 (default) should be close to perceptual transparency, 6-9 produces an “acceptable” quality. Using numbers from 0 to 9 means that the audio track will be encoded in variable bitrate (vbr) mode: smaller files, better quality;
    • -codec:s copy — s stands for subtitles: copy them as they are;
      output.mkv — the output file.

    Bonus point: if your machine supports it, add the flag -threads N to enable multi-threading and give the encoding a boost. Replace N with the number of your CPU cores.