How to convert to m4v

in a script or programmatically? I have a bunch of files that need to be converted I wonder if there is a better way than going through the prompts one at a time

Windows Vista / XP

+2


source to share


2 answers


Assuming you already have a (command line enabled) program that can convert to m4v and you just want to be able to automate this process, here is a batch file that you can modify to iterate over all files in a directory and its subdirectories, and call your conversion program. As written, it uses Handbrake to convert DVD to .iso, .img or extracted as VIDEO_TS to mp4 format for consumption by XBox 360. It's quite easy to change.

Just save it as encode.bat or something.

@echo off

rem Encode DVD for XBOX360 using Handbrake
rem Anything in %ENCODED_DIR% will not be encoded because everything in there
rem is assumed to have been encoded already.
rem
rem Encodes VIDEO_TS, iso, and img .. renames img to iso

SETLOCAL ENABLEDELAYEDEXPANSION

SET FILE_TYPES=VIDEO_TS *.iso *.img
SET ENCODED_DIR=[ENCODED]
SET CONVERT_PROG=[HANDBRAKE]\HandBrakeCLI.exe
SET CONVERT_ARG_INPUT=-i
SET CONVERT_ARG_OUTPUT=-o
SET CONVERT_ARG_SETTINGS=--longest --preset="Xbox 360" --native-language=eng --subtitle-scan

IF NOT EXIST "%ENCODED_DIR%" mkdir "%ENCODED_DIR%"

FOR /F "usebackq delims==" %%i IN (`dir %FILE_TYPES% /s /d /b ^| find /V "%ENCODED_DIR%"`) DO (
    rem trim the trailing slash and we have our output name minus the extension
    SET INPUT_FILENAME=%%i
    SET OUTPUT_FILENAME=%%~pi
    SET BASE_NAME=!OUTPUT_FILENAME:~0,-1!
    SET OUTPUT_FILENAME=!BASE_NAME!.mp4

    rem rename .img to .iso so Handbrake recognizes it as a proper input format
    IF /I "%%~xi"==".img" (
        SET INPUT_FILENAME=%%~pi%%~ni.iso
        ren "%%i" "%%~ni.iso"
    )

    start "Converting" /BELOWNORMAL /WAIT "%CONVERT_PROG%" %CONVERT_ARG_INPUT% "!INPUT_FILENAME!" %CONVERT_ARG_OUTPUT% "!OUTPUT_FILENAME!" %CONVERT_ARG_SETTINGS% 

    echo ERRORLEVEL AFTER CONVERT %ERRORLEVEL% >> last_errorlevel.txt 
)

ENDLOCAL

      

So, you will need to change these variables:

SET FILE_TYPES=VIDEO_TS *.iso *.img
SET ENCODED_DIR=[ENCODED]
SET CONVERT_PROG=[HANDBRAKE]\HandBrakeCLI.exe
SET CONVERT_ARG_INPUT=-i
SET CONVERT_ARG_OUTPUT=-o
SET CONVERT_ARG_SETTINGS=--longest --preset="Xbox 360" --native-language=eng --subtitle-

      



FILE_TYPES is what you want to use as the input format for your converter program. ENCODED_DIR is the directory you want to skip (you can use it to store already encoded files or store them elsewhere). CONVERT_PROG is your converter directory. In this example, I have it in a subdirectory called [HANDBRAKE] and it is called HandBrakeCLI.exe. *** CONVERT_ARG _ **** are the settings you use to call your converter program.

Just put in what you want to convert into a subdirectory from the script. For example, without changing the script, you would rely on this directory structure:

encode_stuff\encode.bat
encode_stuff\[ENCODED]\<stuff to skip>
encode_stuff\[HANDBRAKE]\HandBrakeCLI.exe
encode_stuff\dvd1\VIDEO_TS\<movie junk>
encode_stuff\dvd2\my_dvd2.iso

      

Then when you run the script, it will create dvd1.mp4 and my_dvd2.mp4.

So, based on this description of how it works, we hope you can figure out how to change it even if you don't know too much about cmd shell programming using the batch language. If this answer does not help, you should update the original question to indicate what format you are going to, what playback device you are targeting with m4v, and if you have a program that can do the conversion.

+1


source


Handbrake is a great utility for M4V encoding. You can even configure it to run in batch. I once coded an entire season of Lost using this method. It can be run via command line or GUI, but it supports encoding files in batches anyway.



+2


source







All Articles