2015. május 24., vasárnap

Conversion script for FujiFilm FinePix W3 3D camera videos (avi) to SBS mp4 under Linux

When the following script is run, it looks for avi files in the current folder whose name starts with DSC... and their format is motions jpeg.
The left/right channels of the original W3 video are extracted and a final side-by-side video is created. All new videos will be in mp4 format.

Here it is the script:

#!/bin/bash

file_pattern="$@"

if [ ! $file_pattern ]; then
  file_pattern="DSC*.avi DSC*.AVI"
fi

for file in $(ls -f $file_pattern 2> /dev/null)
do
  echo Checking $file
  if [[ "$(file $file)" == *"video: Motion JPEG"* ]]; then
    echo Processing $file
    filenamebase=${file%.*}
    echo Create left video: "$filenamebase"_l.mp4
    ffmpeg -loglevel error -i $file -f mp4 -acodec mp3 -map 0:v:1 -map 0:a:0 "$filenamebase"_l.mp4
    echo Create right video: "$filenamebase"_r.mp4
    ffmpeg -loglevel error -i $file -f mp4 -acodec mp3 -map 0:v:0 -map 0:a:0 "$filenamebase"_r.mp4
    echo Join left/right videos to a half SBS video: "$filenamebase"_sbs.mp4
    ffmpeg -loglevel error -i "$filenamebase"_l.mp4 -i "$filenamebase"_r.mp4 \
           -filter_complex "pad=in_w*2:in_h, overlay=main_w/2:0, scale=in_w/2:in_h" \
           -f mp4 -b:v 6000k -acodec copy -map 0:a:0 "$filenamebase"_sbs.mp4
    echo Rename left video to 2d version: "$filenamebase"_l.mp4 to "$filenamebase"_2d.mp4
    mv "$filenamebase"_l.mp4 "$filenamebase"_2d.mp4
  fi
done