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

5 megjegyzés:

Unknown írta...

Hi! I found this when searching for a way to convert Fujifilm W3 Stereo AVI ti SBS mp4. Sadly, I have no knowledge about Linux and scripts... Is there any way to run this script on Windows? Please help!
// Anders

kecsap írta...

Hi Anders,

you can download ffmpeg for Windows here:

https://ffmpeg.org/download.html

You need to execute three commands to get an SBS video in command line.

1. First create left and right videos:

ffmpeg -loglevel error -i W3_VIDEO.AVI -f mp4 -acodec mp3 -map 0:v:1 -map 0:a:0 video_left.mp4
ffmpeg -loglevel error -i W3_VIDEO.AVI -f mp4 -acodec mp3 -map 0:v:0 -map 0:a:0 video_right.mp4

2. Join left/right videos to a half SBS:

ffmpeg -loglevel error -i video_left.mp4 -i video_right.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 final_sbs_video.mp4

Unknown írta...

Thanks for a very quick answer! =)
I have hundreds of W3 AVI's so I was hoping for a script to bulk process them all at once. I think your original script could achieve just that in just one step, without renaming all the original files one by one?

// Anders

kecsap írta...

Hi Anders,

I don't have experience in Windows scripting for batch files, it is pretty crappy.

Csaba

Хей, Ёоу írta...

Thank you for script, but in my case I had to swap the left and right videos.