Intro
I own a JVC Everio GZ-MG37U, which is one, if not, the first camcorder to feature an internal hard disk drive for media storage. There are pros and cons to being an early adopter, but a definite con with this purchase was that this camcorder produced a non-popular file video file container format: MOD.
There is an in depth explanation with some issues with MOD files in this article. My biggest grievance (beside lack of software support) is that for some reason the MOD files produced by my camcorder were at least 3 times larger than they needed to be due to creating the video file with overzealous quality attributes (despite having a modest quality setting set on the camcorder). Anyways, enough touting the problems of MOD and onto replacing it!
Finding MOD Files
One way to convert MOD files into another more popular format is to use software that recognizes the file format and then merely export them one by one. I did this for some time on my Windows XP machine with JVC’s Power Director software. But working with a 10 year old machine is aggravating to say the least. Also, I had no idea how MOD files I even had lying around. So I opened up terminal (cmd + space and then type: “Terminal” and then press Enter) and ran this command:
find /Volumes/My\ Drobo/ -type f -name "*.MOD" 2> /dev/null
Let me break this down for those of you that don’t understand what this does:
find is a command that searches your files/folders (you can think of this as a terminal version of spotlight, but much more powerful)
/Volumes/My\ Drobo/ this is the path to the directory that I want to search inside of, merely dragging a directory from a Finder window into the Terminal window will auto populate the directory’s path.
-type f is a flag that tells the find command that it is only looking for files (not directories)
– name “*.MOD” tells the find command that we want it to print out all files that have the .MOD extension
2> /dev/null squelches any output from the find command that is an error. If you omit this from the command you may see a lot of permission denied errors like so (which will muddy up our results):
find: ./.DocumentRevisions-V100: Permission denied find: ./.Spotlight-V100/Store-V2/1C4A0428-9131-4DE2-9D43-E8F74294AB76/Cache: Permission denied find: ./.Spotlight-V100/Store-V2/1C4A0428-9131-4DE2-9D43-E8F74294AB76/journals.corespotlight: Permission denied find: ./.Trashes: Permission denied
After running the command you will see something like this if the find command found anything matching your search criteria:
$find /Volumes/My\ Drobo/ -type f -name "*.MOD" 2> /dev/null /Volumes/My Drobo//Archives/College/BAND/Songs/Ideas/MOV010.MOD /Volumes/My Drobo//Jams/ZK/2-26-13/ZK 2-26-13 Pt 1.MOD /Volumes/My Drobo//Jams/ZK/2-26-13/ZK 2-26-13 Pt 2.MOD /Volumes/My Drobo//Jams/ZK/3-1-13/ZK 3-1-13 Pt 1.MOD /Volumes/My Drobo//Jams/ZK/3-1-13/ZK 3-1-13 Pt 2.MOD /Volumes/My Drobo//Jams/ZK/3-1-13/ZK 3-1-13 Pt 3.MOD /Volumes/My Drobo//Jams/ZK/3-3-13/ZK 3-3-13 Pt1.MOD /Volumes/My Drobo//Jams/ZK/3-3-13/ZK 3-3-13 Pt2.MOD /Volumes/My Drobo//Jams/ZK/3-3-13/ZK 3-3-13 Pt3.MOD
That is a decent amount of files… too many to warrant me having to manually convert them.
Automation
Considering I am the good kind of lazy — the kind that prefers to make his computer do the work — I wrote the following script:
#!/bin/bash | |
# This script recurses through the file heirarchy, converting .MOD video files into .mp4 files with ffmpeg. | |
# usage: cd into the directory that you want to perform this script, then run "./convert.sh ." | |
MODext=MOD | |
MP4ext=mp4 | |
# walk through a directory recusively, | |
recurse_dir() { | |
for i in "$1"/*; do | |
if [ -d "$i" ]; then | |
echo -e "searching dir: $i...\n" | |
recurse_dir "$i" | |
elif [ -f "$i" ]; then | |
if [[ ${i: -4} == ".MOD" ]]; then | |
dest=${i%.$MODext}.$MP4ext | |
echo -e "\nconverting file: $i..." | |
# feel free to tweak ffmpeg parameters below according to your needs | |
`ffmpeg -i "$i" -vcodec mpeg4 -b:v 2800k -acodec aac -ab 384k -ar 48000 "$dest" -n -nostdin` | |
RC=$? # get the return code from ffmpeg | |
if [ "${RC}" -ne "0" ]; then | |
# Do something to handle the error. | |
echo -e "ERROR code from ffmpeg: $RC\n" | |
else | |
# Everything was ok. | |
echo -e "removing file: $i...\n" | |
rm "$i" | |
fi | |
fi | |
fi | |
done | |
} | |
# try get path from param | |
path="" | |
if [ -d "$1" ]; then | |
path=$1; | |
else | |
path="/tmp" | |
fi | |
echo -e "base path: $path" | |
recurse_dir $path |
WARNING: This script will remove your MOD files after creating an mpg4 copy. If you don’t want this to happen merely place a ‘#’ at the left of rm "$i"
(line 28) before running the script.
Before running you will need to ensure that you have ffmpeg installed on your machine. You can do that by merely typing ffmpeg into terminal., which should get you:
$ ffmpeg ffmpeg version 3.1.4 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda libavutil 55. 28.100 / 55. 28.100 libavcodec 57. 48.101 / 57. 48.101 libavformat 57. 41.100 / 57. 41.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 47.100 / 6. 47.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100 libpostproc 54. 0.100 / 54. 0.100 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... Use -h to get full help or, even better, run 'man ffmpeg'
If you don’t see the above output after entering ffmpeg into Terminal, you need to install it. Here is a handy article that walks you through it.
In order to run the script you will need to change its permissions to be executable so that you may run it. You can do this by entering the following into Terminal:
chmod u+x convert.sh
Now you may run it by changing (cd
) to the directory you want to run the command in and typing the following (assuming convert.sh is also in that directory):
./convert.sh .
It’ll start working its magic and will produce output that looks like:
$./convert.sh . base path: . searching dir: ./EXTMOV... converting file: ./EXTMOV/3-28-08.MOD... ffmpeg version 3.1.4 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda libavutil 55. 28.100 / 55. 28.100 libavcodec 57. 48.101 / 57. 48.101 libavformat 57. 41.100 / 57. 41.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 47.100 / 6. 47.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100 libpostproc 54. 0.100 / 54. 0.100 Input #0, mpeg, from './EXTMOV/3-28-08.MOD': Duration: 00:00:17.02, start: 0.232822, bitrate: 9300 kb/s Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, smpte170m), 720x480 [SAR 32:27 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 384 kb/s [mp4 @ 0x7fb94397f800] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Last message repeated 1 times Output #0, mp4, to './EXTMOV/3-28-08.mp4': Metadata: encoder : Lavf57.41.100 Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 720x480 [SAR 32:27 DAR 16:9], q=2-31, 2800 kb/s, 29.97 fps, 30k tbn, 29.97 tbc Metadata: encoder : Lavc57.48.101 mpeg4 Side data: cpb: bitrate max/min/avg: 0/0/2800000 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 384 kb/s Metadata: encoder : Lavc57.48.101 aac Stream mapping: Stream #0:0 -> #0:0 (mpeg2video (native) -> mpeg4 (native)) Stream #0:1 -> #0:1 (ac3 (native) -> aac (native)) frame= 510 fps=145 q=3.6 Lsize= 6667kB time=00:00:16.98 bitrate=3216.0kbits/s speed=4.84x video:5938kB audio:714kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.235574% [aac @ 0x7fb943981600] Qavg: 52037.402 removing file: ./EXTMOV/3-28-08.MOD...
Let it do its thing and before you know it you’ll have all those pesky MOD files converted into something far more space efficient and usable!