Batch Script to Convert MOV Videos to MP4/MPEG using ffmpeg


The MOV video files are generally huge compare to MP4/MPEG. When taking a video using smart phones such as iphone 12 Pro Max, you get the MOV videos. Then it starts to fill up your iphone storage as well as your storage (harddisk, cloud) if you sync the videos. The MOV files are huge especially if you set video quality to high – 4k 60fps.

We can use the following scripts to batch convert the MOV videos to MPEG based on ffmpeg video encoding/decoding tool. FFMPEG is an open source tool that is available at: https://ffmpeg.org/

BASH Script to Convert MOV to MP4/MPEG

We first need to iterate all MOV videos in current folder and including the subfolder, then we can all the ffmpeg to convert each to MPG – then remove the original file to save disk space (beware of this).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
 
process() {
        local mov="$1"
        echo Processing "$mov ..."
        ffmpeg -i "$mov" -vcodec h264 -acodec mp2 "$mov.mp4"
        echo "Waiting to delete the original file: $mov"
        sleep 5
        rm -f "$mov"
        echo Remaining MOV count = $(find . -name "*.mov" | wc -l)
        echo "OK!"
        sleep 5
}
 
export -f process
 
find . -name "*.mov" -type f -exec bash -c 'process "{}"' \;
#!/bin/bash

process() {
        local mov="$1"
        echo Processing "$mov ..."
        ffmpeg -i "$mov" -vcodec h264 -acodec mp2 "$mov.mp4"
        echo "Waiting to delete the original file: $mov"
        sleep 5
        rm -f "$mov"
        echo Remaining MOV count = $(find . -name "*.mov" | wc -l)
        echo "OK!"
        sleep 5
}

export -f process

find . -name "*.mov" -type f -exec bash -c 'process "{}"' \;

This script runs on Linux. You can also run it at Window Subsystem for Linux (WSL).

ffmpeg Batch Script to Convert MOV Videos to MP4/MPEG using ffmpeg bash script BASH Shell batch script tools / utilities video converter

Converting may consume your CPU cycles and cause CPU spikes. Here, in the script, a 5 second interval of sleep between finish of video conversion and removing the original video. Also, after the original video is removed, you also have 5 seconds to Ctrl+C if you don’t want to continue.

convert-all-mov-to-mp4-using-ffmpeg Batch Script to Convert MOV Videos to MP4/MPEG using ffmpeg bash script BASH Shell batch script tools / utilities video converter

The process() is a bash function to convert a MOV video file. You can tailor it to your needs for example, naming the target MPG video file (currently adding a “.mpg” extension to the end of the original MOV file). It also reports the remaining MOV files to convert for your convenience to track the progress.

Window Script to Convert MOV to MP4/MPEG

Below is the equivalent Windows BATCH script to convert all MOV in current folder and its sub directories into MP4/MPEG video using ffmpeg video/audio encoder/decoder tool.

1
2
3
4
5
6
7
8
9
@echo off
 
for /f "delims="  %%m in ('dir /s /b *.mov') do (
        echo Processing "%%m ..."
        ffmpeg -i "%%m" -vcodec h264 -acodec mp2 "%%m.mp4"
        echo "Waiting to delete %%m"
        timeout /T 5
        del /q "%%m"
)
@echo off

for /f "delims="  %%m in ('dir /s /b *.mov') do (
        echo Processing "%%m ..."
        ffmpeg -i "%%m" -vcodec h264 -acodec mp2 "%%m.mp4"
        echo "Waiting to delete %%m"
        timeout /T 5
        del /q "%%m"
)

The timeout is windows version of the command sleep.

It took me days to convert all 1500+ MOV videos to MP4/MPEG but the result is significant – it saves me 300GB hard disk. When converting, the CPU is spiked to 100% and the CPU temperature is rising to 90 degree. You might want to run this conversion during midnight especially if your electricity billing is cheaper at night.

You also don’t need to specify “-vcodec h264 -acodec mp2” so that the ffmpeg will deduce the default parameters for the video/audio.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
671 words
Last Post: Teaching Kids Programming - One-way Jump Game via Backtracking, DP and Greedy Algorithm
Next Post: Teaching Kids Programming - First Number Equal or Larger Than Target using Next Function

The Permanent URL is: Batch Script to Convert MOV Videos to MP4/MPEG using ffmpeg

Leave a Reply