-
-
Save benny-sun/1cf5e342742a1de01dd028c9c672f265 to your computer and use it in GitHub Desktop.
Convert camcorder .dv files to .mp4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script can be used to convert .dv files downloaded from a minidv camcorder to .mp4 files convenient for storing/uploading | |
# | |
# The files were imported using iMovie HD 6 on an old Snow Leopard Mac Mini | |
# iMovie can be downloaded at: | |
# https://www.macintoshrepository.org/24547-imovie-6-hd-6-5-1 | |
# | |
# Finding the hardware can be the most challenging part. | |
# You need, an old computer with firewire, a firewire cable with appropriate adapters, and a mini dv camcorder with firewire output | |
# | |
# From iMovie, I create a new project, then connected the camcorder. IT can be finicky, but eventually shows up an "import" | |
# button that imports files. | |
# From there, the .dv files are in "projectname.iMovie Project/Media" folder | |
# The ffmpeg conversion was based on http://blog.alanporter.com/2017-04-08/minidv-movies/ | |
# (There seemed to be lot of examples of .dv to mp4 conversion that didn't work. That Alan's was the one "good" one I found.) | |
# To use, go into a directory with dv files to convert and run the script (./convertDvToMp4.sh) | |
# The resultant mp4 with have its attributes and create/change date changed to match the "Date Time Original" field in original file | |
# This makes it accurate for uploading to google photos | |
# | |
# Everything is left in the same directory | |
# *.dv - original dv files | |
# *.mp4 - converted .mp4 files | |
# *_original - mp4 files before exiftool changed the date and time | |
# | |
# Prereeqs: ffmpeg and exiftool installed. For mac: | |
# brew install exiftool; brew install ffmpeg | |
# | |
# Sometimes dates may be missing from some files. View in time order with: | |
# ls -latr | |
# To manually add a timestamp: | |
# exiftool Clip\ 01.mp4 -datetimeoriginal="2007:10:15 08:15:00" | |
# To copy that timestamp to other fields: | |
# exiftool Clip\ 01.mp4 "-mediacreatedate<datetimeoriginal" "-mediamodifydate<datetimeoriginal" "-FileCreateDate<datetimeoriginal" "-createdate<datetimeoriginal" "-modifydate<datetimeoriginal" "-filemodifydate<datetimeoriginal" "-filecreatedate<datetimeoriginal" | |
ffopts="" | |
# FILTERS | |
ffopts="$ffopts -vf yadif" # de-interlacing | |
# VIDEO ENCODING OPTIONS | |
ffopts="$ffopts -vcodec libx264" | |
ffopts="$ffopts -preset medium" # balance encoding speed vs compression ratio | |
ffopts="$ffopts -profile:v main -level 3.0 " # compatibility, see https://trac.ffmpeg.org/wiki/Encode/H.264 | |
ffopts="$ffopts -pix_fmt yuv420p" # pixel format of MiniDV is yuv411, x264 supports yuv420 | |
ffopts="$ffopts -crf 18" # The constant quality setting. Higher value = less quality, smaller file. Lower = better quality, bigger file. Sane values are [18 - 24] | |
ffopts="$ffopts -x264-params ref=4" | |
# AUDIO ENCODING OPTIONS | |
ffopts="$ffopts -acodec aac" | |
ffopts="$ffopts -ac 2 -ar 24000 -ab 80k" # 2 channels, 24k sample rate, 80k bitrate | |
# GENERIC OPTIONS | |
ffopts="$ffopts -movflags faststart" # Run a second pass moving the index (moov atom) to the beginning of the file. | |
OIFS="$IFS" | |
IFS=$'\n' | |
for file in $(ls *.dv) ; do | |
IFS="$OIFS" | |
out=${file%.*}.mp4 | |
echo "$file -- $out" | |
echo ffmpeg -i $file $ffopts $out | |
ffmpeg -i "$file" $ffopts "$out" | |
exiftool -tagsfromfile "$file" "-xmp:datetimeoriginal<datetimeoriginal" "$out" | |
exiftool "$out" "-mediacreatedate<datetimeoriginal" "-mediamodifydate<datetimeoriginal" | |
exiftool "$out" "-FileModifyDate<datetimeoriginal" "-FileCreateDate<datetimeoriginal" "-CreateDate<datetimeoriginal" | |
IFS=$'\n' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment