IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
[Linux] avi2mp4.sh: Convert files to MP4 (H264 or XviD/AAC)
micmac
post Aug 31 2008, 17:04
Post #1





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



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 ----------------------------
...

Get the zip file from VDR Portal

This post has been edited by micmac: Mar 28 2009, 19:05
Go to the top of the page
+Quote Post
smok3
post Sep 1 2008, 09:28
Post #2


A/V Moderator


Group: Moderator
Posts: 1731
Joined: 30-April 02
From: Slovenia
Member No.: 1922



from what i read 'Bits per Pixel' is nonsense, better implement some sort of compression test.


--------------------
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung
Go to the top of the page
+Quote Post
micmac
post Sep 1 2008, 17:22
Post #3





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



QUOTE (smok3 @ Sep 1 2008, 02:28) *
from what i read 'Bits per Pixel' is nonsense, better implement some sort of compression test.


Hey!
Can you quote a source on that? Fact is, it works pretty well.
Go to the top of the page
+Quote Post
smok3
post Sep 2 2008, 12:30
Post #4


A/V Moderator


Group: Moderator
Posts: 1731
Joined: 30-April 02
From: Slovenia
Member No.: 1922



http://forum.doom9.org/showthread.php?t=13...=bits+per+pixel

QUOTE
Bits per pixel is not a valid measurement. Some sources need more bits than others


practical example;
http://somestuff.org/flashAVC/flvplayer.ph...ne-x640y352.mp4
(any film source would look mucho worse at that bitrate for example)

then, even if BPP value would be true for specific sources at specific resolution, this won't scale linearly with resolution, etc.

so, to conclude, it fails because:
- wont scale with resolution
- every source is different from any other source
- wont scale with different encoder settings

3 times false and you are out wink.gif

p.s. this is just some general observation, i wont use your script, so don't do anything because of me.

This post has been edited by smok3: Sep 2 2008, 12:54


--------------------
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung
Go to the top of the page
+Quote Post
micmac
post Sep 7 2008, 17:52
Post #5





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



Thanks for the pointer!
CODE
1.1.10:
    - remove BPP usage
    - add compressibility check
    - delete INSTALL file (put content into README)
    - clean up README
    - (hopefully) last batch of quoting fixes
    - make scripting style more consistent
    - better sed scripts
    - use $HOME instead of "~" expansion
    - move command substitutions out of [tests]
Go to the top of the page
+Quote Post
micmac
post Feb 7 2009, 16:49
Post #6





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



CODE
1.1.11:
    - during compressibility test capture mencoder output in a file
      and display content of file in case mencoder exits with an
      error, otherwise user wouldn't know what went wrong
    - used long command options when available
    - don't write/source temporary configuration file
    - don't just source the mplayer -identify output either for that
      matter
    - only load necessary variables from configuration file and
      mplayer's identify output
    - use random name for myidentify output, too
    - set sane PATH, IFS and umask
    - clear all aliases and the command path hash
    - prevent core dumps
    - end shebang line with hyphen
    - changed name of array media_vars to all_media_vars and added
      an array called mplayer_media_vars for clarity's sake
    - made parsing of file for variable a function
    - changed the initial configuration a bit
    - refuse to crop repeatedly
    - demand Bash, version 2 or greater
1.1.12:
    - added subtitle support (SRT, SUB and VobSub)
    - added $TRACK_LANG so user can set a three digit language code.
      It's not _that_ useful because you can not set it on a
      per-file or even-per track basis. Why did I even add it in the
      first place? :D
    - call MP4Box from within the tmp directory do avoid another bug
      (for some reason MP4Box added something like ".idx" to the
      command line otherwise)
    - some small fixes (comments, README)
    - call MP4Box without "-isma" because it removes the subtitles
1.1.13:
    - script now refuses to (try to) convert mpeg containers
    - updated README
Go to the top of the page
+Quote Post
fracai
post Feb 10 2009, 16:28
Post #7





Group: Members
Posts: 80
Joined: 6-June 08
Member No.: 54085



Not to steal an thunder from this script, I'm sure it's nifty, but an alternative is to use Handbrake. Mac, *nix, and Windows binaries are available, doesn't require the installation of any other supporting tools, and includes a number of encoding presets for iPods, Apple TV, XviD players, etc.
Go to the top of the page
+Quote Post
micmac
post Mar 28 2009, 19:06
Post #8





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



CODE
1.1.14:
    - now 3GPP text subtitles (.ttxt) are recognized as well
    - new configuration variable SBTL, see README
    - pass TRACK_LANG & video fps along as a global MP4Box argument
    - changed subtitle handling, now for text subtitles the 3GPP
      header is adapted slightly for proper display (I tried to
      follow the findings of this blog entry:
      http://blog.jharding.org/2008/11/subtitles-on-appletv-and-iphone.html
      Thanks for the ideas!)
    - use "-ipod" argument directly when muxing
1.1.15:
    - fix subtitle related mistake
    - set vim modeline
    - some cleanups (in README as well)
Go to the top of the page
+Quote Post
micmac
post May 17 2009, 08:30
Post #9





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



CODE
1.1.16:
  - fix quite a few return checks that caused avi2mp4.sh to not terminate
    properly
  - adjust ChangeLog's style :)
Go to the top of the page
+Quote Post
micmac
post Mar 7 2010, 17:02
Post #10





Group: Members
Posts: 86
Joined: 4-July 05
Member No.: 23121



CODE
1.1.17:
  - Fixed a few spelling error
  - Changed initial configuration (point out a few differences between PSPs and
    iPods
1.1.18:
  - Fixed the if-block that deals with cropping and updating the aspect ratio
1.1.19:
  - Use wildcard when cleaning up instead of trying to delete file by file
  - Changed default config for PSPs/iPods, apparently x264 changed b frame
    behaviour or default config regarding b frames
  - Substitute some more short command options with long ones
    (wc/bc/grep/renice)
  - Recomplicated track language handling again to fix VobSub track languages
    (these are now determined by MP4Box as it should be); the video track does
    not get a language assigned anymore as that was more or less stupid anyway;
    the language code is now applied only to audio and text subs
Go to the top of the page
+Quote Post
diepod
post May 7 2010, 02:07
Post #11





Group: Members
Posts: 1
Joined: 7-May 10
Member No.: 80449



Thank you very much for your hard and continuing work.

This script is kickass!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 2nd October 2014 - 13:36