0

I am working on a project that involves analyzing videos filmed on a GoPro in ImageJ; unfortunately, this means I have to convert all my videos (~400) to TIFF stacks. Therefore, I would like to create a batch file that will take a folder of MP4 videos, convert them to AVI files at 10fps with the first 4:20 removed, then convert those AVI files to TIFF stacks and have the resulting TIFFs sorted into folders based on their names. I have tried going straight from MP4 to TIFF and have always gotten an error message, hence the MP4 to AVI to TIFF conversions.

I have been going at this in a step wise manner by finding other batch codes people have developed on here, and I have gotten to the point where the batch file will convert the videos to TIFF files with sequential numbers at the end of the file names for the TIFF stacks, but I am struggling to get the sorting into folders part correct.

The file naming convention I have been using is just the standard GoPro naming convention but with the addition of sequential numbers (i.e., GOPR0210_0001.tiff, GOPR0210_0002.tiff, etc.) so that the TIFF stack is in the correct order.

Right now what I have is:

@echo off

for %%f in (*.MP4) do ffmpeg -y -ss 00:04:20 -i "%%f" -r 10 -qscale 0 "%%~nf_10fps.avi"

for %%f in (*.AVI) do ffmpeg -i "%%f" -pix_fmt rgba -compression_algo deflate %%~nf_%%05d.tiff

for %%a in (*.tiff) do (
set f=%%a
set g=!f:~0,10!
md "!g!" 2>nul
move "%%a" "!g!"
)

pause

I got the listed code for moving the files from .bat file sorting files into folders but I just end up with all my TIFF files sorted into a folder called "!g!"

I have also looked at/tried:

Any tips, comments, or helpful hints would be greatly appreciated! This is my first time trying to make a batch file. Thanks!

  • Congrats. For a "first batch file" this isn't bad. You just forgot to [setlocal enabledelayedexpansion](https://stackoverflow.com/a/30284028/2152082) – Stephan Sep 14 '18 at 18:03
  • Thanks! that definitely fixed it. I didn't realize what delayed expansion was for. I thought I had tried running the file with that included but I guess not. –  Sep 17 '18 at 14:25

0 Answers0