PDA

View Full Version : BatCode - a simple h264 mass transcoder


Northpack
19th August 2008, 01:43
Hi,

recently I had to transcode hundreds of wmv video files on harddisk - all with the same resolution and framerate - to h264. As I found no utility exactly fitting for that purpose, I developed a windows batch script doing the job (in doing so I was quite surprised how powerful stuff you can get out of such nasty batch-scripting). As my little tool proved well for my purpose, I thought it might be of some use for other people with similar tasks. So I decided to revamp it and make it available here.

BatCode v0.1.3 by Northpack

Licensed under the terms of the GNU General Public License.

Contents:
1. Introduction
2. Premises
3. Installation
4. Usage
5. Changelog
6. Known Issues

1. Introduction
---------------
BatCode is a Windows32 batch script for the purpose of
batch-transcoding a large amout of video files into x264/AAC.
It utilizes AviSynth frameserver to feed video and audio
streams to x264 encoder respectively Wavi/NeroAACEnc.
Both are eventually muxed using mp4box.
Currently, only one audio stream is supported.

2. Premises
-----------
To run BatCode, you have to have recent versions of the
employed programs (GPL/freeware) installed. These are:

- Avisynth 2.5 <http://www.avisynth.org>
- x264 <http://www.videolan.org/developers/x264.html>
- Nero AAC Encoder <http://www.nero.com/eng/down-ndaudio.php>
- Wavi <http://sourceforge.net/projects/wavi-avi2wav/>
- MP4Box <http://www.videohelp.com/tools/mp4box>

And optionally

- AsfBin <http://www.radioactivepages.com/>

If you use AviSynth DirectShowSource() input to convert
flv files you have to install lastest ffdshow filter:
<http://sourceforge.net/projects/ffdshow-tryout/>

3. Installation
---------------
3.1 Extract the content of the zip file to any folder and make
sure, the user who is supposed to run the script has write
permissons on it.

3.2 Customize batcode.ini:
Edit batcode.ini and set the parameters to the program
executables according to your system.
Set the programs' parameters according to your needs.
(Make sure you leave no spaces before or after the "=".)

3.3 Customize AVS templates:
In batcode.ini, two AVS templates are specified, one
for video and one for audio processing. These have to be
valid AVS files, except for the variable __SOURCE__ which
will be replaced with the actual source file name by the
script. Edit these AVS templates according to your needs.
To avoid trouble, make sure that the video template
only contains the video part of the source and vice versa.

4.Usage
-------
Usage: batcode <source> [destination] [ini file]

<source> may be a single filename or a set of files defined
by wildcards, including absolute or relative path. I.e.:

"c:\videos\more\*.avi" or "videos\more\justthisone.avi"

If [destination] is given, it defines the path and/or
prefix of the destination files, i.e.:

"videos\transcoded\new_"

will save the transcoded files to the path videos\transcoded
and add the prefix new_ to the name of the source files.

Normally BatCode will expect an batcode.ini in the path of
the script file. If [ini file] is given, it will use the
specified file instead. This is useful for creating profiles
with different encoder settings and AVS templates.

The command line

"batcode c:\videos\*.avi c:\videos\h264\ mysettings.ini"

will transcode all avi files inside the folder c:\videos\
to mp4 files saved to the subfolder h264 (Note that without
the trailing "\" files with prefix h264 would be created
in the folder videos).
It uses the ini file mysettings.ini instead of default
batcode.ini and thus the AVS templates specified therein.

BatCode also keeps a logfile to report which files were
encoded successfully or where errors occured. The name
of this logfile is specified in the batcode ini file.

5. Changelog
------------
v0.1.3:
- New option to fix corrupt WMV files. You can specify a
parameter asfb_dir in batcode.ini with the path to
AsfBin.exe (see 2.). If specified, BatCode will try to
fix WMV files that won't encode using AsfBin.
This should work for most WMV files that AviSynth won't
open because of corrupt or missing indexing.
v0.1.2:
- Fixed bug that BatCode won't run if there is no logfile
present already.
- BatCode now works with pathnames containing spaces,
if the pathname is put into quotes.
- BatCode now works with file- and pathnames containing
special characters (like German umlaut).
- New options introduced: you can now set the fourth command
line parameter to 4 binary digits.
The first digit tells BatCode whether to encode video
(1=encode), the second whether to encode audio (1=encode),
the third whether to mux audio and video (1=mux) and the
fourth if temporary files are to be sweeped (1=sweep,
only if muxing is enabled). Default is "1111".
v0.1.1:
- Fixed improper screen output if BatCode terminates

6. Known Issues
---------------
- MP4Box crashes AFTER finishing mux when destination
path contains relative directorys ".." or ".".

Download it here: http://www.kalebasse.de/div/batcode.zip

If you should have use for it, don't hesitate to post any questions or problems you encountered.

-Northpack

EDIT: Update to v.0.1.3

Northpack
26th August 2008, 15:14
Updated to version 0.1.3 containing bugfixes and some new features like automatically fixing currupt WMV files using AsfBin command line utility.

RunningSkittle
26th August 2008, 15:35
Nice script. Probably wont ever have a need for it, but its nice :)

I sure wish NT batch would get a serious upgrade sometime.

smok3
26th August 2008, 16:19
i would start with a graph like that, for my batch it would look like:

x264_ng.bat subjective
----------------------------------------------------------
called with input, bitrate, x264 filtering, x264 method parameters

main.batch {
x264 encoding methods as subrutines
aac encoding as hardcoded subrutine
mp4box-ing as hardcoded subrutine
}

ext files {
template.avs
}

no, its not really obvious...

Northpack
26th August 2008, 16:44
@RunningSkittle: Thanks!

@smok3: Parameter handling with NT batch is really a pain in the *ss. Besides that I think it's more comfortable to have all those settings in an ini file; you can easily create several ini files for different tasks.

RunningSkittle
26th August 2008, 17:02
Wouldnt be too hard, just as long as parameters are separated by common deliminator like "$" or ",". I would avoid using "," simple because its used in defining parameters quite often.
Although using a simple text file for settings is easier (to code and define settings) and less error prone

smok3
26th August 2008, 19:52
i'am saying define what your file does and it will get some interest, mine does use parameters thought and yes it was a pain.

doggyjumper
11th September 2008, 19:44
WOW
This script has helped me tremendously in getting a project setup .

it has given me a solution to things I have asked before and never got a respons to

Have incorporated a vbs call to check an associated file per clip to check trimming points and a few other that are created with another program (sportscoaching vid soft) .
This at the moment results in crating auto trimmed clips without changing the original clip need for further analysis in mass and saving countless hrs

as these languages are so new to me I am still figuring out various variable etc but it has given me a big boost , thanks man !!


Guy

doggyjumper
11th September 2008, 21:03
question

I am trying to ad a "preview" clip creation cq shorter clip of the original but I dont seem to be able to figure out to save this to my liking (the instruction works in another script ! meaning it saves to my liking)

after
"%_mp4b_dir%" %_mp4b_exc% && call:write_log "Finished muxing" 1 2 || set errorlevel=1

I add
"%_mp4b_dir%" -splitx 11:14 !_dst_fln!.mp4% -new %~2pv_%~n1.mp4

( note the pv_ addition I want to the filename) but I get an error . it doesnt allow me to spcify a file to save to . if I omit the -new %~2pv_%~n1.mp4 than I get my file save but with _10_14 added inbetween the filename and .mp4 (weird es klapt nicht)


Please help
thanks