Video file batchscript renamer with metadata

Started by lonetraceur, March 10, 2015, 01:23:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lonetraceur

Hey everyone,
I'm not sure if this is the right place to post this in but I've had the need recently to write a quick and simple DOS file renamer that take the contents of a corresponding .LOG file and use that data to construct a more meaningful filename for the video file.

For instance:
The Video file is: 8G4A5744.MOV
The Logfile is: MVI_5744.LOG
The Video file is renamed to: 5744_ISO320_F4_48th_50mm_23fps_4600K.MOV

It's pretty rudimentary and not very smart, but I thought I'd share it anyway. I've found it quite helpful to distinguish files quickly.

So a few things first:
1. You need to switch on the Magic lantern create logfile feature. Movie > Movie Tweaks > Movie Logging : On
2. Once you copy all your files to you computer, make sure you have ONLY the LOG files and corresponding MOV files in there you want to convert.
3. Test it first before doing anything on all your production files!
4. Copy the batch file into the same directory as the LOG and MOV files.

- SINGLE FILE RENAMER -

To run the script, simply write:

C:> VMFR logfilename.LOG videofilename.MOV

This will rename the videofile to contain the Metadata.

To create the batchfile, copy the below code into a file called: VMFR.bat


@echo off
REM ============================================
REM === VIDEOFILE METADATA FILENAME REWRITER ===
REM === Single Files                         ===
REM ============================================

REM === VARIABLES ===
set "TAB=    "

REM === CHECK FOR HELP ===
IF "%1"=="/?" (
ECHO Uses the Magic Lantern LOG files to rename corresponding video filename.
ECHO.
ECHO %tab%usage: VMFR logfile videofile.
ECHO.
ECHO Ensure that the logfile and videofile are in the same directory as this batchfile.
) ELSE (

REM === CLEAR OUTPUT FILES ===
break>output.txt
break>output1.txt
break>result.txt

REM === GRAB DETAILS FROM META FILE ===
echo filename: %1 >> output.txt
findstr "^ISO" %1 >> output.txt
findstr "^Aperture" %1 >> output.txt
findstr "^Shutter" %1 >> output.txt
findstr "^Focal length" %1 >> output.txt
findstr "^FPS" %1 >> output.txt
findstr "^White" %1 >> output.txt
@echo %2 >> output.txt

REM === SET TOKENS ONTO A LINE ===
for /f "tokens=* delims=" %%i in (output.txt) do (
  echo/|set /p ="-%%i" >> output1.txt
)

REM === GRAB TOKENS FROM LOG FILE ===
  FOR /F "tokens=3,6,9,13,17,20,24,30 delims=:_./-, " %%i in (output1.txt) DO (
    SET filename=%%i_ISO%%j_F%%k_%%lth_%%mmm_%%nfps_%%o.%%p
    @echo %filename% >> result.txt
    REN %2 %filename%
)

REM === DELETE OUTPUT FILES ===
DEL output.txt
DEL output1.txt
DEL result.txt
)



- MULTI FILE RENAMER -

Further on from the single file renamer, I've written a multi-file renamer. This will rename an entire folder of .MOV files using their corresponding .LOG files.
The usage is slightly different and again, very basic, but it works.

If you have a group of MOV files labelled : 8G4A5744.MOV,8G4A5745.MOV,8G4A5746.MOV, etc...
And the corresponding LOG files named : MVI_5744.LOG,MVI_5745.LOG,MVI_5746.LOG, etc...

To use, you need to simply add the MOV file prefix and file extension.
So the video files Prefix would be : 8G4A in this example and the extension is MOV

So to run the script you would type:

C:> VMFR_multi 8G4A MOV

Again, similar to the single file renamer, you can paste the below code into a file called VMFR_multi.bat (or whatever you like).

See code below:


@setlocal enableextensions enabledelayedexpansion
@echo off
REM ============================================
REM === VIDEOFILE METADATA FILENAME REWRITER ===
REM === Multi Files                          ===
REM ============================================

REM === VARIABLES ===
set "TAB=    "

REM === CHECK FOR HELP ===
IF "%1"=="/?" (
ECHO Uses the Magic Lantern LOG files to rename corresponding video filenames.
ECHO.
ECHO %tab%usage: VMFR [videofileprefix] [videofileextension].
ECHO.
ECHO.
ECHO This batchfile will search for the all the LOG files in the current directory and
ECHO try to match using the last four digits of the filename to the corresponding
ECHO Movie file.
ECHO It will then rename the movie file with the Magic Lantern Metadata.
ECHO.
) ELSE (

REM === CLEAR FILES ===
break>output.txt
break>result.txt

REM === CREATE THE NEW FILENAME FOR EACH LOGFILE ENTRY ===
FOR %%f in (*.LOG) DO (
SET FILENAME=%%f
SET FILENAME=!FILENAME:~4,4!
SET VIDEOFILE=%1!FILENAME!.%2
FOR /F "delims=" %%a in ('findstr "^ISO" %%f') DO SET ISO=%%a
FOR /F "delims=" %%a in ('findstr "^Aperture" %%f') DO SET APERTURE=%%a
FOR /F "delims=" %%a in ('findstr "^Shutter" %%f') DO SET SHUTTER=%%a
FOR /F "delims=" %%a in ('findstr "^Focal length" %%f') DO SET FOCAL=%%a
FOR /F "delims=" %%a in ('findstr "^FPS" %%f') DO SET FPS=%%a
FOR /F "delims=" %%a in ('findstr "^White" %%f') DO SET WHITE=%%a

ECHO !FILENAME! !ISO! !APERTURE! !SHUTTER! !FOCAL! !FPS! !WHITE!, !VIDEOFILE! >> output.txt
)

REM === OUTPUT THE NEW FILENAMES TO A RESULT FILE ===
FOR /F "tokens=1,3,6,10,14,17,21 delims=:_./-, " %%i in (output.txt) DO (
  SET filename=%%i_ISO%%j_F%%k_%%lth_%%mmm_%%nfps_%%o.%2
SET videofile=%1%%i.%2
  @echo !filename!,!videofile! >> result.txt
)

REM === RENAME FILES ===
FOR /F "tokens=1,2 delims=, " %%a in (result.txt) DO (
REN %%b %%a
ECHO Renamed %%b = %%a
)

REM === HOUSEKEEPING ===
DEL output.txt
DEL result.txt
)



Anyway, I hope this helps someone. It definitely helps to speed up my workflow, especially when I import a lot of footage into Premiere and then have to relabel everything.

I'm sure it could be improved upon a lot (Selecting which metadata to use, etc...) but it's a start.  :)

Good luck!