Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
#1 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
avi2mp4.sh: Convert files to MP4 (H264 or XviD/AAC)
Code:
avi2mp4.sh README
____ ____ ____ ____ ____ ____ ____ ____ ____ ____
||a |||v |||i |||2 |||m |||p |||4 |||. |||s |||h ||
||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
-------------- Converts video files in batch mode to MP4 ---------------
Where to get it: http://forum.doom9.org/showthread.php?t=133598
Before putting this script to serious use encode a few samples first.
avi2mp4.sh is a batch converter. For each file a resolution gets calcu-
lated and a compressibility test determines the minimum bit rate needed
for the level of quality the user asks for.
If this isn't possible with the maximum bitrate the user allows, then
the output resolution gets downsized and a new compressibility test
starts.
Once a matching pair of bit rate and resolution has been found the input
file gets converted to H.264/MPEG-4 AVC or MPEG-4 video and AAC audio.
Finally these streams are wrapped into MP4.
Different kinds of subtitles can be added: SRT, SUB, 3GPP (TTXT) and
VobSub.
----------------------------- Requirements -----------------------------
- bc calculator
- faac or neroAacEnc (even Wine and a Windows binary will do)
- mplayer
- mencoder
- aacgain (at least v1.7.0; you can find a Debian package at RareWares:
http://www.rarewares.org/debian/packages/unstable/)
- MP4Box (part of gpac; v0.4.4 or later required)
------------------------- Compressibility Tests ------------------------
The compressibility test is new. Send me an e-mail with concerns or
ideas you might have.
--------------------------------- Hints --------------------------------
Global options need to be set in a file in your user's home directory,
namely ~/.avi2mp4.conf. An initial configuration file will be created.
MEncoder is used for the video conversion. There are multiple possibili-
ties to influence MEncoder's behaviour. The first is the configuration
variable MENCODER_OPTS. The content will be passed on to MEncoder.
A second possibility is to add MEncoder options on a per file basis.
Put the desired options in a file and name it like the input file name
extended by the suffix ".me" (e.g. movie.avi.me).
You can add video filters on a per file basis as well. Write them into
a file the same way as before, only this time use the suffix ".vf". Your
filters will be prepended to the existing chain (scale=x:y,harddup).
avi2mp4.sh searches the video filter chain for "crop" statements. If one
is found the calculation of the output resolution will be adjusted
accordingly.
You can indicate that a video is Progressive NTSC by creating a file
with the suffix ".p" (frame rate of the output video will be 23.976
frames per second for NTSC input).
--------------------------- MPEG containers ----------------------------
MPEG containers are problematic because they don't contain a proper
index like AVI containers do. This wasn't a problem until the
compressibility test was introduced. Since then avi2mp4.sh relies on
being able to "jump" through the input file. More often then not this
didn't work with MPEG containers.
Because of that input files are now skipped when an MPEG container is
detected. You'll have to re-multiplex the files to, e.g., AVI:
mencoder -ovc copy -oac copy input.mpg -o movie.avi
To rip a DVD simply dump the title you want to convert to your disk
first:
mencoder dvd:// -ovc copy -oac copy -o movie.avi
Finally:
avi2mp4.sh movie.avi
-------------------------------- iPods ---------------------------------
You want your videos to play on your iPod?
- obey bit rate and resolution limits
- no "B" frames allowed. Also, with H.264, the baseline profile level
must be set and CABAC disabled
XVID_ENCOPTS=max_bframes=0
X264_ENCOPTS=nocabac:level_idc=30:bframes=0
- AAC's Low Complexity (LC) profile must be used
Videos created with the initial configuration file should work on your
iPod out of the box. Same should be the case for your PSP.
Please also read about the configuration variables "MP4BOX_IPOD" and
"SBTL".
----------------------------- Configuration ----------------------------
...
Last edited by micmac; 5th September 2009 at 08:41. Reason: New version |
|
|
|
|
|
#2 | Link |
|
Fighting spam with a fish
Join Date: Sep 2005
Posts: 2,350
|
Cool, thanks for your work!
__________________
FAQs:Bond's AVC/H.264 FAQ,Bond's MPEG-4 ASP FAQ Sites:Adubvideo,MeGUIWiki,MeGUI Ipod Conversion Guide |
|
|
|
|
|
#3 | Link |
|
Registered User
Join Date: May 2006
Posts: 24
|
I had a similar tool here: http://teknoraver.campuslife.it/software/mp4tools/
but mine can encode any input, not just .avi and with every aspect ratio. Would you improve mine instead of writing your own?
__________________
Code:
.""`. Matteo Croce : :" : proud Debian admin and user `. `"` `- Debian - when you have better things to do than fix a system |
|
|
|
|
|
#4 | Link | |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Quote:
I looked at your script and figured it'd take me some time to get to know it. Sorry. In the meantime I've changed avi2mp4.sh to support any file and any aspect ratio as well. Code:
1.0.5: - Small change to comments
- Use myidentify instead of midentify; now input pixel aspect
ratio doesn't have to be 1:1 anymore
- Function c; unset variables containing essential file
properties and continue
- Protect mplayer from input while extracting audio
(-nolirc -noconsolecontrols etc.)
- Remove AVI requirement; now any file is possible as input
- Add VFOPTS variable
1.0.6: - Remove '-noskip -mc 0' again
- Change "Usage: ..." info
- Add rough sketch about what the script does and what it can't
do
- Add note about iPod (tm) import
- Print target bitrate and bpp
- Unset LC_ALL and set LC_NUMERIC to POSIX to make sure we get
dot instead of comma as decimal separator as bc expects a dot
1.0.7: - Add a little enhancement to function c; ability to return to
the n-th eclosing loop
- Fix two funtion c calls returning to the wrong loops
micmac Last edited by micmac; 17th January 2008 at 16:56. |
|
|
|
|
|
|
#7 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Code:
1.0.9. - In case aspect ratio is not set simply assume Width:Height
- Add -endpos .1 to myidentify to prevent playback of audio
files; thanks to Reimar Doeffinger for the tip
- Check $VFOPTS for cropping. If detected calculate new aspect
ratio so we get a proper output resolution
|
|
|
|
|
|
#8 | Link | |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Quote:
I can't say that I tried it but it seems h264enc isn't what I was looking for. I didn't want an interactive application. Instead I wanted an application for one specific task with batch processing capabilities. That's why I came up with avi2mp4.sh. Regards mic |
|
|
|
|
|
|
#9 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Code:
1.1.0: - Remove bogus comma from sed call (BASENAME="...")
- Remove redundant scale command from bc call
- Check for (and prevent) upscaling of video
- Lower the bitrate with regards to BPP
- Move crop detection around
- Update crop detection for special cases w=0 and h=0; this
also fixes a potential division by zero
- Update comments
- Add CH and CW to function c so both get unset
- Dimension -> Resolution
- Display $CW x $CH as resolution if available
- Make sure ID_VIDEO_WIDTH, ID_VIDEO_HEIGHT, ID_VIDEO_FPS and
ID_AUDIO_NCH aren't negative
- Fix the for loop that looks at output resolutions
1.1.1: - Fix behaviour when supplied cropping values are bogus
1.1.2: - Another attempt to correct the behaviour in case of bogus
crop values; only accept numbers and let mencoder do the
dying
- Change loop expression in c-style for-loop once more just for
correctness' sake
|
|
|
|
|
|
#10 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Code:
1.1.3: - Direct error messages to stderr
- Minor comment fix
- If there's a ".p" file treat video as progressive
- Users can add mencoder options on a per-file basis
- Add tip about DVD ripping
- Add clear_variables function
|
|
|
|
|
|
#11 | Link | |
|
h264enc & xvidenc author
Join Date: May 2007
Location: /dev/video0
Posts: 808
|
Quote:
__________________
openSUSE Linux 64-bit - h264enc - xvidenc - divxenc Fedora & openSUSE repo: http://download.opensuse.org/reposit...me:/microchip8 |
|
|
|
|
|
|
#13 | Link |
|
h264enc & xvidenc author
Join Date: May 2007
Location: /dev/video0
Posts: 808
|
of course,.... I was just pointing out to your previous reply on h264enc
__________________
openSUSE Linux 64-bit - h264enc - xvidenc - divxenc Fedora & openSUSE repo: http://download.opensuse.org/reposit...me:/microchip8 |
|
|
|
|
|
#14 | Link |
|
h264enc & xvidenc author
Join Date: May 2007
Location: /dev/video0
Posts: 808
|
you should really add the 'harddup' filter at the end of the filter chain so duplicate frames get hard-coded in the file. This is essential if you're going to remux the AVI to another container so you won't lose A/V sync
also -mc 0 completely disables the A/V sync code of MEncoder so you should really stay away from it
__________________
openSUSE Linux 64-bit - h264enc - xvidenc - divxenc Fedora & openSUSE repo: http://download.opensuse.org/reposit...me:/microchip8 |
|
|
|
|
|
#15 | Link | ||
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Hi!
Quote:
Code:
mencoder ... -vf ${VFOPTS}scale=${OUT_HORIZ}:${OUT_VERT},harddup ...
Quote:
Regards mic |
||
|
|
|
|
|
#16 | Link |
|
h264enc & xvidenc author
Join Date: May 2007
Location: /dev/video0
Posts: 808
|
ahhh must have missed harddup then, sorry bout that
__________________
openSUSE Linux 64-bit - h264enc - xvidenc - divxenc Fedora & openSUSE repo: http://download.opensuse.org/reposit...me:/microchip8 |
|
|
|
|
|
#17 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Thanks for all the downloads! If you're missing a feature or if there's something else, let me know.
Btw to get around the "long filename crashes" with gpac/MP4Box, recompile it _with_ CFLAGS but without any "-OX" options. E.g. Code:
CFLAGS="-march=athlon-xp -pipe" Code:
CFLAGS="-march=athlon-xp -pipe -O2" Regards! |
|
|
|
|
|
#19 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Code:
1.1.5: - Add $MP4BOX_IPOD to set whether "MP4Box -ipod ..." is run
- Add possibility to renice the script (alter its priority)
- use "-oac pcm" instead of "-oac copy"; it does add a little
overhead (and we need more drive space) but it helps keeping
audio and video in sync; also some audio codecs cannot be
muxed into AVI, e.g. Vorbis, so now we're working around this
issue
|
|
|
|
|
|
#20 | Link |
|
Registered User
Join Date: Dec 2004
Posts: 39
|
Code:
1.1.6:
- Split release into ChangeLog, README, INSTALL and script itself
- Add possibility to use neroAacEnc AAC encoder instead of faac; it's
not Open Source but I ran into an issue with faac earlier and
apparently it's not maintained anymore
- Increase accuracy of aspect calculation; I doubt this has any effect
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|