VDR Portal
Register Calendar Members List Team Members Search Frequently Asked Questions Gallery Go to the Main Page

VDR Portal » Developer » C / C++ / Scripten » avi2mp4.sh: Konvertiert Dateien nach MP4 (H264 o. XviD/AAC) » Hello Guest [Login|Register]
Last Post | First Unread Post Print Page | Recommend to a Friend | Add Thread to Favorites
Pages (2): [1] 2 next » Post New Thread Post Reply
Go to the bottom of this page avi2mp4.sh: Konvertiert Dateien nach MP4 (H264 o. XviD/AAC)
Author
Post « Previous Thread | Next Thread »
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Pfeil avi2mp4.sh: Konvertiert Dateien nach MP4 (H264 o. XviD/AAC) Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
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 ----------------------------
...


Attachments:
zip avi2mp4-1.1.16.zip (21 KB, 248 downloads)
zip avi2mp4-1.1.19.zip (21.15 KB, 159 downloads)

This post has been edited 35 time(s), it was last edited by micmac: 07.03.2010 16:59.

17.01.2008 16:12 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
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
17.01.2008 17:02 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
1.0.8: - Remove myidentify log when skipping file
       - Use rm -f
       - Add possibility to add options to mencoder calls through
         $MENCODER_OPTS

This post has been edited 1 time(s), it was last edited by micmac: 27.01.2008 14:09.

18.01.2008 03:08 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
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
27.01.2008 14:08 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
budy budy is a male
Routinier


Registration Date: 19.10.2003
Posts: 320
Herkunft: Ammersbek, Schleswig-Holstein

Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

Moin,

was erwartet das Skript denn für Parameter? Evtl. könnte man das so machen, dass da Skript auch vom vdradmin aus aufgerufen werden kann.

Cheers,
Budy

__________________

c't VDR 6.0
  • Asrock K7VT4, Athlon XP 3300+, 1 GB Ram, 2 x TT FF 1.3 mit Spannungs-Mod II
  • Debian/Etch mit eigenem no-DMA Kernel
  • außer CPU- und Netzteil-Lüfter keine drehenden Teile - bootet von CF-Card in unter 35 Sek.

27.01.2008 16:23 budy is offline Send an Email to budy Search for Posts by budy Add budy to your Buddy List AIM Screen Name of budy: budachst
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

quote:
Original von budy
was erwartet das Skript denn für Parameter? Evtl. könnte man das so machen, dass da Skript auch vom vdradmin aus aufgerufen werden kann.


Nur die Pfade zu den zu konvertierenden Dateien.
27.01.2008 16:51 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
budy budy is a male
Routinier


Registration Date: 19.10.2003
Posts: 320
Herkunft: Ammersbek, Schleswig-Holstein

Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

Das skript erwartet dann aber eine mpg Datei, z.B. aus vdrsync, oder?

__________________

c't VDR 6.0
  • Asrock K7VT4, Athlon XP 3300+, 1 GB Ram, 2 x TT FF 1.3 mit Spannungs-Mod II
  • Debian/Etch mit eigenem no-DMA Kernel
  • außer CPU- und Netzteil-Lüfter keine drehenden Teile - bootet von CF-Card in unter 35 Sek.

27.01.2008 17:24 budy is offline Send an Email to budy Search for Posts by budy Add budy to your Buddy List AIM Screen Name of budy: budachst
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

Stimmt, da hast Du Recht. Das Skript kann keine Schnittmarken interpretieren.
27.01.2008 17:56 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
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
29.01.2008 12:41 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

%)
code:
1:
1.1.1: - Fix behaviour when supplied cropping values are bogus
29.01.2008 13:05 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
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
29.01.2008 21:56 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
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
16.02.2008 10:54 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
1.1.4: - Add possiblity to set maximum output resolution, thanks to
         L. Pearce for the idea; see comments regarding $MAX_RES
       - Changed comments regarding MP4Box crashes (added suggestion
         for real workaround)
03.04.2008 11:55 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
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
15.06.2008 21:59 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
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
26.06.2008 19:10 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
1.1.7:
        - mention faac in INSTALL
        - add possibility to override neroAacEnc binary (README for more
          info)
        - add Xvid support; it's so much faster than x264, had to add it
        - add configuration file example to README
08.07.2008 09:57 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
RE: avi2mp4.sh: Dateien nach MP4 umwandeln für iPods Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
1.1.8:
        - use random ASCII file names to work around problems with special
          characters (e.g. with MPlayer's pcm writer and gpac)
        - make the script a little bolder ;)
03.08.2008 09:13 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
8:
1.1.9:
	- make sure muxing doesn't result in variable video frame rate
	- cleaned up quite a bit (quoting, brackets, ...)
	- better error detection
	- clean user configuration file before sourcing it
	- write initial configuration file
	- got rid of all evals
	- removed hardcoding of iPod-specific encoder options
31.08.2008 17:56 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
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]
07.09.2008 18:45 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
micmac
Veteran


Registration Date: 14.10.2002
Posts: 787

Thread Starter Thread Started by micmac
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
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
26.10.2008 10:24 micmac is offline Search for Posts by micmac Add micmac to your Buddy List
Pages (2): [1] 2 next » Tree Structure | Board Structure
Jump to:
Post New Thread Post Reply
VDR Portal » Developer » C / C++ / Scripten » avi2mp4.sh: Konvertiert Dateien nach MP4 (H264 o. XviD/AAC)

www.vdr-portal.de VDR Portal © 2002-2006 by genka
Forum Software: Burning Board 2.3.4, Developed by WoltLab GmbH