Help:Mpeg2dv.sh

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
This page is a translated version of a page Help:Mpeg2dv.sh and the translation is 100% complete. Changes to the translation template, respectively the source language can be submitted through Help:Mpeg2dv.sh and have to be approved by a translation administrator.

Si votre logiciel de montage vidéo n'importe pas directement les fichiers mpeg depuis votre appareil photo numérique, vous pourriez avoir besoin de les convertir au format dv pour les importer par exemple dans iMovie.

Instructions

  1. Enregistrez le code ci-dessous sur votre Bureau ; assurez-vous que l'extension est bien .sh et non .sh.txt.
  2. Placez le script au bon endroit par exemple /usr/local/bin/mpeg2dv.sh sous Mac OS X ou ~/bin/mpeg2dv.sh sous Linux qui se trouve dans votre variable d'environnement $PATH et rendez le script exécutable si nécessaire.
  3. Ouvrez un terminal (Terminal.app sous Mac OS X ; c'est dans le répertoire Utilitaires des Applications) et tapez :
mpeg2dv.sh anMpgFile.mpg anotherMpgFile.mpg

Le résultat devrait être un ensemble de fichiers .dv dans le sous répertoire en question.

Script

#!/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