Help:Mpeg2dv.sh

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Other languages:
العربية 25% • ‎Deutsch 38% • ‎English 100% • ‎suomi 12% • ‎français 100% • ‎日本語 50% • ‎Lëtzebuergesch 12% • ‎polski 38% • ‎português do Brasil 38% • ‎русский 25%

If your movie editing software does not directly import mpeg files from your digital camera, you might need to convert them to dv in order to import in for example into iMovie.

Instructions[edit]

  1. Save the code to your Desktop; make sure the extension really is .sh, and not .sh.txt.
  2. Place the script in a proper place like /usr/local/bin/mpeg2dv.sh on Mac OS X or for example ~/bin/mpeg2dv.sh on Linux that is in your $PATH environment variable and make the script executable if needed.
  3. Open a terminal (Terminal.app on Mac OS X; it's in the Utilities folder of Applications) and type:
mpeg2dv.sh anMpgFile.mpg anotherMpgFile.mpg

The result should be .dv files in the subfolder in question.

Script[edit]

#!/bin/sh

# This script converts mpeg files from a digital camera 
# into the DV format using the ffmpeg tool.
#
# Eric Kow
# Public domain - do whatever you want with this

FFMPEG_FLAGS="-ac 2 -ar 48000 -hq -s 720x480"
TYPE_1=
TYPE_2='-map 0:1 -map 0:0' 
TYPE_3='-map 0:2 -map 0:1'

try_ffmpeg() {
  IN_FILE=${1}
  OUT_FILE=${2}
  while [ "$#" -gt "2" ]
  do
    TYPE=${3}
    ffmpeg -i "${IN_FILE}" ${TYPE} ${FFMPEG_FLAGS} "${OUT_FILE}" || :
    if [ -s ${OUT_FILE} ]; then
      return 0
    else
      rm ${OUT_FILE}
    fi
    shift
  done
}

# for each file...
while [ "$#" -gt "0" ]
do
  # what file are we working on now?
  in_file=$1
  in_file_uscore=`echo ${in_file} | sed -e 's/ /_/g'`
  out_file_stem=`basename ${in_file_uscore} .mpg`
  out_file=${out_file_stem}.dv
  shift

  try_ffmpeg "${in_file}" "${out_file}"\
    "${TYPE_1}" "${TYPE_2}" "${TYPE_3}"
done