# [HOWTO] High resolution movies for iPod (script included)

## micmac

Download the script (avi2mp4.sh) for MP4 conversion from Doom9.

Hi there,

it took me a while to figure out how to encode compatible high resolution (640:480 and the like) files for the iPod Video. In the end it turned out that there's not much to it, really. Here's how to encode videos following the iPod specs. Works for 5G and 5.5G iPods. They need to run a recent firmware, though.

Essential software:

- mencoder with x264 support

- normalize

- faac

- gpac (at least version 0.4.4, older releases screw up the tags)

Howto:

Encode the video. The following options are mandatory:

```
nocabac:vbv_maxrate=1500:vbv_bufsize=244:level_idc=30
```

The iPods can't handle CABAC which is turned on by the codec by default. Other things not supported by the iPods (8x8dct, b frames) are disabled in the codecs default settings so we don't have to worry about them. The iPod spec sheet says it can only handle up to 1500 kbit/s (for the video part), that's what vbv_maxrate is for. vbv_bufsize is the size over which vbv_maxrate is calculated. We need to set the proper AVC level (level_idc=30) as well.

Note: Maybe vbv_maxrate/vbv_bufsize are not necessary. Maybe keeping the bitrate equal or below 1500 kbit/s is enough. If you try without vbv_maxrate/vbv_bufsize and experience ill behavior during playback please tell us about it.

Anything else is pretty much up to you. Check out the on-line docs of mencoder: Link

Hints: You need progressive video frames and also the iPod can't scale the video's aspect ratio on playback so you have to take care of that while encoding.

Example:

Here's what I used. The x264 settings are the ones suggested by the mencoder docs for high quality x264 encoding with a few adjustments to make it acceptable for iPod's:

```
mencoder dvd:// -oac copy -ovc x264 -vf crop=704:360:12:56,scale=640:-10,harddup -ofps 24000/1001 -x264encopts \ pass=1:bitrate=800:nocabac:vbv_maxrate=1500:vbv_bufsize=244:level_idc=30:frameref=2:subq=5:turbo=1:threads=auto -o /dev/null

mencoder dvd:// -oac copy -ovc x264 -vf crop=704:360:12:56,scale=640:-10,harddup -ofps 24000/1001 -x264encopts \ pass=2:bitrate=800:nocabac:vbv_maxrate=1500:vbv_bufsize=244:level_idc=30:frameref=2:subq=5:turbo=1:threads=auto -o movie.avi

```

Hint: In case your source is interlaced (really interlaced, not telecined!) there's a chance you can get around deinterlacing by using the "field" parameter (-vf field=0,...). What happens when one uses field=0 on interlaced video is that only the first field (out of two per frame) is regarded. Practically this results in the division by two of the vertical resolution. So for instance instead of 576 pixels you get 288, instead of 480 you get 240. That's just fine in case you go for a final resolution of the encoded file that's smaller than that (or equal to it).

Now let's extract the audio to WAVE and afterwards normalize it:

```
mplayer -vc null -vo null -ao pcm:fast movie.avi

normalize audiodump.wav
```

Next we encode the WAVE to VBR AAC-LC (make sure you follow the example and use the .m4a extension). iPod spec says it can handle audio up to 160 kbit/s. -q 80 usually results in 120 kbit/s so that should take care of things:

```
faac -o audiodump.m4a -q 80 audiodump.wav
```

Next: Extract the raw x264 bitstream from the video:

```
MP4Box -aviraw video movie.avi
```

Then we mux the AAC audio and the x264 video data into a shiny new MP4 container and also tag it while we're at it (otherwise the iPod will display an empty line; the file will be playable, though.)

(Hint: You need to specify the real frame rate of the video, otherwise MP4Box assumes 25 fps.)

(WARNING: MP4Box creates temporary files and defaults to the /tmp directory for that. In case the temporary files exceed the space in the directory MP4Box will _not_ throw an error message. It will continue and leave you with a broken file, wondering what the hell just happened. Took me a good part of an afternoon to figure that out. Guess it's time for a bug report. Anyway, you can specify an alternative directory with the -tmp switch.)

```
MP4Box -itags name="NAME OF THE MOVIE" -new -add audiodump.m4a -add movie_video.h264:fps=23.976 movie.mp4
```

Finally you could tell MP4Box to rewrite some stuff to make the file iTunes compatible. I haven't tested if this is really necessary or if the file really works with iTunes. If you don't use iTunes don't do it. Or maybe nowadays iTunes doesn't need it anymore - then don't do it either.

```
MP4Box -ipod movie.mp4
```

But wait, we still have to put the file on the iPod. I use amarok and media-libs/libgpod-0.6.0 for that. Works like a charm.

I hope this is helpful to some!

Regards

micmacLast edited by micmac on Sat Feb 16, 2008 9:51 am; edited 28 times in total

----------

## marrowhk

Nice, thanks.

----------

## imanassypov

How do you deal with it if input is a file.avi, rather than a dvd?

Thanks!

----------

## micmac

 *imanassypov wrote:*   

> How do you deal with it if input is a file.avi, rather than a dvd?

 

Exactly the same, basically. Except that you don't use dvd:// but instead simply the filename. Any cropping and scaling may be unnecessary.

I'm thinking about writing a shell script to convert AVI files to mp4 for iPods. I know there are already scripts for that, but I haven't found one that scales down to a set bits per pixel value at a given bitrate (which is what I'm after). But until now I didn't find the drive.

----------

## imanassypov

Great!

One more question - can your script convert .iso files, or do those have to be ripped first?

Thanks again!

----------

## micmac

 *imanassypov wrote:*   

> One more question - can your script convert .iso files, or do those have to be ripped first?
> 
> 

 

I added the script to the first post. It can handle AVI files, nothing else.

----------

## micmac

Hi!

avi2mp4.sh v1.0.6 can handle any file type, AVI restriction is gone. I don't know about ISO images. My guess is if mplayer is able to handle those then avi2mp4.sh should be able to as well.

Regards

micmac

----------

## imanassypov

I tried the scipt, the resulting mp4's for some reason are not accepted by my ipod (g6)

----------

## micmac

 *imanassypov wrote:*   

> I tried the script, the resulting mp4's for some reason are not accepted by my ipod (g6)

 

Meaning the transfer works but the iPod doesn't play the movie or meaning the transfer doesn't work? How do you transfer the file? Did you read the comments within the script regarding iTunes?

----------

## micmac

```
1.0.8: - Remove myidentify log when skipping file

       - Use rm -f

       - Add possibility to add options to mencoder calls through

         $MENCODER_OPTS
```

Last edited by micmac on Wed Jan 30, 2008 7:37 am; edited 1 time in total

----------

## micmac

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

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

----------

## beatryder

Please update your requirements. You forgot to mention that aacgain needs to be installed.

----------

## micmac

Hi!

Yeah it's a little confusing. In the "HowTo" I wrote about using normalize to level the audio and in the script I use aacgain. Sorry for that. In the script aacgain is already mentioned as a requirement, though, see the comments.

mic

----------

## micmac

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

----------

## lyallp

I found the script to be quite useful and works quite well.

My only problem is that occasionally, something goes wrong with extracting the audio and a step fails with a missing file.

I have not looked too closely at this just yet and have not figured out the common factor, but if I do, I will let you know.

----------

## micmac

Hi lyallp!

Please check what step fails exactly. Is it mplayer? Or is is MP4Box? In case of MP4Box try this. Emerge it without any "-OX" option in your CFLAGS. E.g.

```

CFLAGS="-march=k8 -msse3 -pipe -fomit-frame-pointer"
```

instead of 

```

CFLAGS="-march=k8 -msse3 -pipe -fomit-frame-pointer -O2"
```

I filed a bug already

Regards

micmac

----------

## lyallp

The problem seems to be in mplayer.

Investigation continues, but it appears that the Output PCM filename, in the extract stage, is truncated at the comma. The resulting output is...

[/code]

==========================================================================

Opening audio decoder: [mp3lib] MPEG layer-2, layer-3

AUDIO: 48000 Hz, 2 ch, s16le, 128.0 kbit/8.33% (ratio: 16000->192000)

Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)

==========================================================================

[AO PCM] File: /tmp/MovieNameUpTillComma (WAVE)

I am thinking that we should create our temporary names using, say, "avi2mp4_$$.avi", or maybe filter the filenames for things like commas, colons, etc, so mplayer does not get confused.

FYI: I have tweaked my copy of the script, I am happy to email it to the author.

----------

## micmac

Please do!

----------

## lyallp

Changes included in my copy of the script include (noted in the mod log) in the copy sent to the author (for those that are interested).

1. Temporary files (that are used by mplayer) use Process ID as their name, not the original source file - the reason is mplayer, during audio extract, would truncate the filename at a comma (if there was one), resulting in 'no file found' failures.

2. Continue processing other files if one fails - particularly handy if converting lots of files and you come back next day and find it failed on the second.

3. Hard coded the iPod Nano screen size into the conversion (the Nano can take up up to 640x480 but it's screen size is 340x240 - meaning any video file with a larger size is wasted - this makes for smaller video files

I found this script to be really useful and am extremely grateful to the author for making it available.

(well, I am extremely grateful to all open source authors)

Thank you

----------

## bosele

I wonder if you would able to add a switch to enable video encoding with mpeg4, the reason being that although this script produces great quality video it's extremely slow. Usually this is not a big problem, but it is a bit overkill for converting .flv's from youtube for example. at the moment I just use another clunky script i made for lower quality vids (which basically does this:ffmpeg -i $filein -f mp4 -vcodec mpeg4 -maxrate 1000k -b 600k -qmin 3 -qmax 5  -bufsize 1048576 -g 300 -acodec libfaac -ar 44100 -ab 128k $newname.mp4), but since i am not that great at scripting it has all kinds of problems (doesn't correctly process certain filenames etc.) and i really like the audio normalization your script uses.

anyway, i'd be very gratefull if you would consider adding a switch like this.

----------

## lyallp

What I am trying to find out how to do now is how to get gpac to write the appropriate tags for converted movies.

I found in the MP4Box changelog.

```

Tagging can be done with MP4Box -itags option. The tags are passed in a single string, separated by ':', formatted as 'tag_name=tag_value'. Supported tags names are: album, artist, comment, compilation, composer, created, disk, encoder, genre, name, tempo, track, tracknum, writer. 

```

This does not include the tags that iTunes seems to use for Movie/TV Show/Podcast.

Also, I name my videos 'SxxExx - title - series name' which is not useful on the iPod as different shows blend together in a horrible mess (since it does not appear to support directories), hence I think I will be using the -'itags "name=series name - SxxExx - title"'

Further experimentation on this is required  :Smile: 

----------

## micmac

I received your mail, thank you! At the moment I'm moving so I'm a little caught up. I'll take a look when I get around to it.

Regards

mic

----------

## micmac

Hi all,

new version of the script released (see link to doom9 forum thread in top post):

```
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)
```

----------

## m@o

hey!

thanks for the script it works well.

but there are 2 problems i couldn't solve:

Problem 1:

i tried to convert .ts files, which are tv recordings. this works. since there is mostly junk in the beginning and junk at the end i have to trim the files after conversion. there is the problem.

e.g.

```
mencoder -ovc copy -oac copy -ss 00:03:30 -endpos 01:40:32 myfile.mp4 -o myfile_cut.mp4
```

gives problem with the audio.

the video seems fine, but whenever i jump in the video the audio starts at the beginning of the whole file.

any clues what this might be?

Problem 2:

sometimes the tv stations send the movies in two languages. this works fine to watch and change language in mplayer by pressing shift+3 (#). but i cann't select the audio in the command line. neither in mplayer nor in mencoder or the MENCODER_OPTS. where can i find out about which audio streams are available? i did try to read something out of the -v option but that didn't help.

here is an example of the output of a file:

```
% mplayer -v /mnt/dvr/movie/some_film.ts

MPlayer dev-SVN-rUNKNOWN-4.1.2 (C) 2000-2008 MPlayer Team

CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 4200+ (Family: 15, Model: 75, Stepping: 2)

MMX2 supported but disabled

SSE supported but disabled

3DNow supported but disabled

3DNowExt supported but disabled

CPUflags:  MMX: 1 MMX2: 0 3DNow: 0 3DNow2: 0 SSE: 0 SSE2: 1

Compiled for x86 CPU with extensions: MMX SSE2

get_path('codecs.conf') -> '/home/mao/.mplayer/codecs.conf'

Reading /home/mao/.mplayer/codecs.conf: Can't open '/home/mao/.mplayer/codecs.conf': No such file or directory

Reading /etc/mplayer/codecs.conf: Can't open '/etc/mplayer/codecs.conf': No such file or directory

Using built-in default codecs.conf.

Configuration: --cc=i686-pc-linux-gnu-gcc --host-cc=i686-pc-linux-gnu-gcc --prefix=/usr --confdir=/etc/mplayer --datadir=/usr/share/mplayer --libdir=/usr/lib --enable-menu --enable-network --disable-tv-bsdbt848 --disable-faad-external --disable-ivtv --disable-pvr --disable-fribidi --disable-enca --disable-nemesi --disable-vstream --disable-libcdio --disable-ass --charset=UTF-8 --disable-lirc --disable-lircc --disable-joystick --disable-inet6 --disable-unrarexec --disable-rtc --disable-tv-v4l2 --disable-tv-teletext --disable-radio-v4l2 --disable-radio-bsdbt848 --disable-live --disable-mad --disable-musepack --disable-pnm --disable-speex --disable-tga --disable-theora --disable-xanim --disable-libamr_nb --disable-libamr_wb --disable-libdca --disable-liblzo --disable-twolame --disable-toolame --disable-real --enable-win32dll --disable-directfb --disable-ggi --disable-md5sum --disable-sdl --disable-xinerama --disable-dga1 --disable-dga2 --disable-vesa --disable-vidix-internal --disable-vidix-external --disable-vidix-pcidb --disable-zr --enable-gui --disable-xvmc --disable-3dfx --disable-tdfxvid --disable-tdfxfb --disable-arts --disable-esd --disable-jack --disable-ladspa --disable-nas --disable-pulse --disable-3dnow --disable-3dnowext --disable-mmxext --disable-sse --disable-ssse3 --disable-altivec

CommandLine: '-v' '/mnt/dvr/movie/some_film.ts'

init_freetype

Using MMX Optimized OnScreenDisplay

Using nanosleep() timing

get_path('input.conf') -> '/home/mao/.mplayer/input.conf'

Can't open input config file /home/mao/.mplayer/input.conf: No such file or directory

Can't open input config file /etc/mplayer/input.conf: No such file or directory

Falling back on default (hardcoded) input config

get_path('some_film.ts.conf') -> '/home/mao/.mplayer/some_film.ts.conf'

Playing /mnt/dvr/movie/some_film.ts.

get_path('sub/') -> '/home/mao/.mplayer/sub/'

[file] File size is 2205990120 bytes

STREAM: [file] /mnt/dvr/movie/some_film.ts

STREAM: Description: File

STREAM: Author: Albeu

STREAM: Comment: based on the code from ??? (probably Arpi)

LAVF_check: MPEG2 transport stream format

Checking for YUV4MPEG2

ASF_check: not ASF guid!

Checking for NuppelVideo

Checking for REAL

Checking for SMJPEG

Searching demuxer type for filename /mnt/dvr/movie/some_film.ts ext: .ts

Checking for Nullsoft Streaming Video

Checking for MOV

Checking for VIVO

header block 1 size: 64

AVS: avs_check_file - attempting to open file /mnt/dvr/movie/some_film.ts

AVS: File is too big, aborting...

Checking for PVA

Checking for MPEG-TS...

TRIED UP TO POSITION 0, FOUND 47, packet_size= 188, SEEMS A TS? 1

GOOD CC: 31, BAD CC: 0

TS file format detected.

DEMUX OPEN, AUDIO_ID: -1, VIDEO_ID: -1, SUBTITLE_ID: -2,

Checking for MPEG-TS...

TRIED UP TO POSITION 0, FOUND 47, packet_size= 188, SEEMS A TS? 1

GOOD CC: 31, BAD CC: 0

PROBING UP TO 0, PROG: 0

COLLECT_SECTION, start: 64, size: 184, collected: 0

SKIP: 0+1, TID: 0, TLEN: 13, COLLECTED: 184

PARSE_PAT: section_len: 13, section 0/0

PROG: 225 (1-th of 1), PMT: 108

COLLECT_SECTION, start: 64, size: 184, collected: 0

SKIP: 0+1, TID: 2, TLEN: 100, COLLECTED: 184

FILL_PMT(prog=225), PMT_len: 184, IS_START: 64, TS_PID: 108, SIZE=184, M=0, ES_CNT=0, IDX=0, PMT_PTR=0x898c830

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

ERROR, descriptor len is too long, skipping

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 0), STREAM: 0, FOUND pid=0xcff (3327), type=0x10000002, ES_DESCR_LENGTH: 3, bytes left: 45

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 1), STREAM: 1, FOUND pid=0xd00 (3328), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 31

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(225 INDEX 2), STREAM: 2, FOUND pid=0xd01 (3329), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 17

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x6a, len=1

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 3), STREAM: 3, FOUND pid=0xd03 (3331), type=0x2000, ES_DESCR_LENGTH: 12, bytes left: 0

----------------------------

COLLECT_SECTION, start: 64, size: 184, collected: 184

SKIP: 0+1, TID: 0, TLEN: 13, COLLECTED: 184

PARSE_PAT: section_len: 13, section 0/0

PROG: 225 (1-th of 1), PMT: 108

COLLECT_SECTION, start: 64, size: 184, collected: 184

SKIP: 0+1, TID: 2, TLEN: 100, COLLECTED: 184

FILL_PMT(prog=225), PMT_len: 184, IS_START: 64, TS_PID: 108, SIZE=184, M=0, ES_CNT=4, IDX=0, PMT_PTR=0x898c830

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

ERROR, descriptor len is too long, skipping

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 0), STREAM: 0, FOUND pid=0xcff (3327), type=0x10000002, ES_DESCR_LENGTH: 3, bytes left: 45

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 1), STREAM: 1, FOUND pid=0xd00 (3328), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 31

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(225 INDEX 2), STREAM: 2, FOUND pid=0xd01 (3329), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 17

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x6a, len=1

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 3), STREAM: 3, FOUND pid=0xd03 (3331), type=0x2000, ES_DESCR_LENGTH: 12, bytes left: 0

----------------------------

COLLECT_SECTION, start: 64, size: 184, collected: 184

SKIP: 0+1, TID: 0, TLEN: 13, COLLECTED: 184

PARSE_PAT: section_len: 13, section 0/0

PROG: 225 (1-th of 1), PMT: 108

COLLECT_SECTION, start: 64, size: 184, collected: 184

SKIP: 0+1, TID: 2, TLEN: 100, COLLECTED: 184

FILL_PMT(prog=225), PMT_len: 184, IS_START: 64, TS_PID: 108, SIZE=184, M=0, ES_CNT=4, IDX=0, PMT_PTR=0x898c830

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

ERROR, descriptor len is too long, skipping

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 0), STREAM: 0, FOUND pid=0xcff (3327), type=0x10000002, ES_DESCR_LENGTH: 3, bytes left: 45

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 1), STREAM: 1, FOUND pid=0xd00 (3328), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 31

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(225 INDEX 2), STREAM: 2, FOUND pid=0xd01 (3329), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 17

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x6a, len=1

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 3), STREAM: 3, FOUND pid=0xd03 (3331), type=0x2000, ES_DESCR_LENGTH: 12, bytes left: 0

----------------------------

COLLECT_SECTION, start: 64, size: 184, collected: 184

SKIP: 0+1, TID: 0, TLEN: 13, COLLECTED: 184

PARSE_PAT: section_len: 13, section 0/0

PROG: 225 (1-th of 1), PMT: 108

COLLECT_SECTION, start: 64, size: 184, collected: 184

SKIP: 0+1, TID: 2, TLEN: 100, COLLECTED: 184

FILL_PMT(prog=225), PMT_len: 184, IS_START: 64, TS_PID: 108, SIZE=184, M=0, ES_CNT=4, IDX=0, PMT_PTR=0x898c830

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

ERROR, descriptor len is too long, skipping

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 0), STREAM: 0, FOUND pid=0xcff (3327), type=0x10000002, ES_DESCR_LENGTH: 3, bytes left: 45

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 1), STREAM: 1, FOUND pid=0xd00 (3328), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 31

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(225 INDEX 2), STREAM: 2, FOUND pid=0xd01 (3329), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 17

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x6a, len=1

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 3), STREAM: 3, FOUND pid=0xd03 (3331), type=0x2000, ES_DESCR_LENGTH: 12, bytes left: 0

----------------------------

VIDEO MPEG2(pid=3327) AUDIO A52(pid=3331) NO SUBS (yet)!  PROGRAM N. 225

==> Found video stream: 0

ADDED VIDEO PID 3327, type: 10000002 stream n. 0

==> Found audio stream: 0

ADDED AUDIO PID 3331, type: 2000 stream n. 0

Opened TS demuxer, audio: 2000(pid 0), video: 10000002(pid 0)...POS=10904, PROBE=0

Searching for sequence header... COLLECT_SECTION, start: 64, size: 184, collected: 0

SKIP: 0+1, TID: 0, TLEN: 13, COLLECTED: 184

PARSE_PAT: section_len: 13, section 0/0

PROG: 225 (1-th of 1), PMT: 108

COLLECT_SECTION, start: 64, size: 184, collected: 0

SKIP: 0+1, TID: 2, TLEN: 100, COLLECTED: 184

FILL_PMT(prog=225), PMT_len: 184, IS_START: 64, TS_PID: 108, SIZE=184, M=0, ES_CNT=4, IDX=0, PMT_PTR=0x898c830

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

PROG DESCR, TAG=9, LEN=6(6)

ERROR, descriptor len is too long, skipping

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 0), STREAM: 0, FOUND pid=0xcff (3327), type=0x10000002, ES_DESCR_LENGTH: 3, bytes left: 45

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 1), STREAM: 1, FOUND pid=0xd00 (3328), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 31

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(225 INDEX 2), STREAM: 2, FOUND pid=0xd01 (3329), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 17

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x6a, len=1

...descr id: 0x52, len=1

PARSE_PMT(225 INDEX 3), STREAM: 3, FOUND pid=0xd03 (3331), type=0x2000, ES_DESCR_LENGTH: 12, bytes left: 0

----------------------------

==> Found audio stream: 1

ADDED AUDIO PID 3328, type: 50 stream n. 1

==> Found audio stream: 2

ADDED AUDIO PID 3329, type: 50 stream n. 2

OK!

VIDEO:  MPEG2  720x576  (aspect 3)  25.000 fps  15000.0 kbps (1875.0 kbyte/s)

[V] filefmt:29  fourcc:0x10000002  size:720x576  fps:25.00  ftime:=0.0400

get_path('sub/') -> '/home/mao/.mplayer/sub/'

X11 opening display: :0.0

vo: X11 color mask:  FFFFFF  (R:FF0000 G:FF00 B:FF)

vo: X11 running at 1680x1050 with depth 24 and 32 bpp (":0.0" => local display)

[x11] Detected wm supports NetWM.

[x11] Detected wm supports FULLSCREEN state.

[x11] Detected wm supports ABOVE state.

[x11] Detected wm supports BELOW state.

[x11] Current fstype setting honours FULLSCREEN ABOVE BELOW X atoms

[xv common] Drawing no colorkey.

[xv common] Maximum source image dimensions: 2046x2046

==========================================================================

Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough

VDec: vo config request - 720 x 576 (preferred colorspace: Mpeg PES)

Trying filter chain: vo

Could not find matching colorspace - retrying with -vf scale...

Opening video filter: [scale]

SwScale params: -1 x -1 (-1=no scaling)

Trying filter chain: scale vo

The selected video_out device is incompatible with this codec.

Try appending the scale filter to your filter list,

e.g. -vf spp,scale instead of -vf spp.

VDecoder init failed :(

Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b

Selected video codec: [mpeg12] vfm: libmpeg2 (MPEG-1 or 2 (libmpeg2))

==========================================================================

==========================================================================

Opening audio decoder: [liba52] AC3 decoding with liba52

dec_audio: Allocating 3840 bytes for input buffer.

dec_audio: Allocating 6144 + 65536 = 71680 bytes for output buffer.

No accelerated IMDCT transform found

AC3: 2.0 (dolby)  48000 Hz  384.0 kbit/s

A52 flags before a52_frame: 0x2A

A52 flags after a52_frame: 0xA

Using MMX optimized resampler

AUDIO: 48000 Hz, 2 ch, s16le, 384.0 kbit/25.00% (ratio: 48000->192000)

Selected audio codec: [a52] afm: liba52 (AC3-liba52)

==========================================================================

Building audio filter chain for 48000Hz/2ch/s16le -> 0Hz/0ch/??...

[libaf] Adding filter volnorm 

ao2: 48000 Hz  2 chans  s16le

audio_setup: using '/dev/dsp' dsp device

audio_setup: using '/dev/mixer' mixer device

audio_setup: using 'pcm' mixer device

audio_setup: sample format: s16le (requested: s16le)

audio_setup: using 2 channels (requested: 2)

audio_setup: using 48000 Hz samplerate (requested: 48000)

audio_setup: frags:  16/16  (4096 bytes/frag)  free:  65536

AO: [oss] 48000Hz 2ch s16le (2 bytes per sample)

AO: Description: OSS/ioctl audio output

AO: Author: A'rpi

Building audio filter chain for 48000Hz/2ch/s16le -> 48000Hz/2ch/s16le...

Starting playback...

Increasing filtered audio buffer size from 0 to 65536

VDec: vo config request - 720 x 576 (preferred colorspace: Planar YV12)

Trying filter chain: vo

VDec: using Planar YV12 as output csp (no 0)

Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.

VO Config (720x576->1024x576,flags=0,'MPlayer',0x32315659)

VO: [xv] 720x576 => 1024x576 Planar YV12 

VO: Description: X11/Xv

VO: Author: Gerd Knorr <kraxel@goldbach.in-berlin.de> and others

Xvideo image format: 0x32595559 (YUY2) packed

Xvideo image format: 0x32315659 (YV12) planar

Xvideo image format: 0x59565955 (UYVY) packed

Xvideo image format: 0x30323449 (I420) planar

using Xvideo port 355 for hw scaling

[xv] dx: 0 dy: 0 dw: 1024 dh: 576

*** [vo] Allocating mp_image_t, 720x576x12bpp YUV planar, 622080 bytes

[xv] dx: 328 dy: 237 dw: 1024 dh: 576

*** [vo] Allocating mp_image_t, 720x576x12bpp YUV planar, 622080 bytes

Unicode font: 255 glyphs.064.438 ct:  0.004   2/  2 ??% ??% ??,?% 0 0 

Unicode font: 255 glyphs.

*** [vo] Allocating mp_image_t, 720x576x12bpp YUV planar, 622080 bytes

Uninit audio filters...: -0.525 ct: -0.140  40/ 40  7%  0%  0.0% 0 0 

[libaf] Removing filter volnorm 

Uninit audio: liba52

Uninit video: libmpeg2

vo: uninit ...

Exiting... (Quit)

```

maybe you could see how to access these audiostreams from the commandline.

i did try:

```
-aid NUMBER
```

 but that didn't work at all

```
-alang LANG
```

 did work but it seems the stream sets the name for all languages the same. (deu). so mencoder|mplayer selects the first stream that matches. is there a way to force some stream?

i'm clueless.

thanks for any hints

----------

## micmac

Hi,

problem 1 seems to be related to remuxing the file with mplayer (mp4 muxing in mplayer is apparently still buggy). And 2 seems related to the file being a ts file. Here's what I would try. I'd just use an application (for instance vdrsync or PVAStrumento (runs in Wine) to convert the transport stream into a program stream and at the same time I'd cut the file (get rid of advertising etc.). There's also ProjectX (Java) which should definitely work.

Yeah, I'd probably end up using ProjectX to convert and cut (shouldn't take more than a few minutes) and afterwards run avi2mp4.sh on the resulting file. You should be able to choose the audio track you want in ProjectX as well.

Good luck, shouldn't be too tough to figure out

micLast edited by micmac on Fri Apr 18, 2008 7:26 pm; edited 1 time in total

----------

## m@o

thx

do you have suggestion to cut the movie from problem 1 in a simple way (command line)?

ad prob 2:

thx this seems a little heavy for the everyday use  :Sad: 

i'll give it a try though.

greetz 

m@o

----------

## micmac

Hi,

if you know the times for cutting you can do it with avi2mp4.sh, e.g.:

```
-ss 3:00 -endpos 3600
```

That'd tell mencoder to start 3 minutes within the file and encode the next hour (but you already knew this). Just put it in a file called "mymovie.ts.me" and run the script on mymovie.ts.

I know that it's bothersome sometimes to convert tv captures. I used VDR, for instance, and I had the same experience. But with VDR you can set cut marks which PVAStrumento can use, so it was almost a one-click solution.

Kind regards

micmac

----------

## m@o

i did try projectx.

nice program. it worked well to cut the ts streams.

but i didn't find an option yet to select a certain audio stream. at the moment it does convert all streams to a new .ts file, which is trimmed to my specifications.

there are two things i need to do:

a) trim the movies

b) select the right audio stream

a) works with projectX, although i would prefer a command line option. a second option would be to use mencoder BEFORE converting the files to mp4 but AFTER converting them from ts to some mpeg2 material.

b) is currently based on luck. i don't know yet how to get the right audio stream when every stream is named the same.

well i think this is no job for just ONE weekend  :Wink: 

greetz

m@o

----------

## m@o

i hope i can help other out by telling how i got everything to work:

cutting recordings is supereasy and quick in projectX. once you have your default settings you just open it select a file and run. 2-3 minutes later you are done.

so i can live with projectX cutting my ts streams and copying them into shorter ts streams.   :Wink: 

 *Quote:*   

> b) select the right audio stream 

 

here i guess i was just too dumb! really! 

what are the available audio streams here:

```
...descr id: 0x56, len=5

...descr id: 0x52, len=1

PARSE_PMT(11 INDEX 0), STREAM: 0, FOUND pid=0x20 (32), type=0xffffffff, ES_DESCR_LENGTH: 10, bytes left: 53

...descr id: 0x52, len=1

PARSE_PMT(11 INDEX 1), STREAM: 1, FOUND pid=0x6ff (1791), type=0x10000002, ES_DESCR_LENGTH: 3, bytes left: 45

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(11 INDEX 2), STREAM: 2, FOUND pid=0x700 (1792), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 31

...descr id: 0xa, len=4

Language Descriptor: deu

...descr id: 0x52, len=1

PARSE_PMT(11 INDEX 3), STREAM: 3, FOUND pid=0x701 (1793), type=0x50, ES_DESCR_LENGTH: 9, bytes left: 17

...descr id: 0x6a, len=1

...descr id: 0x52, len=1

...descr id: 0xa, len=4

Language Descriptor: deu

PARSE_PMT(11 INDEX 4), STREAM: 4, FOUND pid=0x703 (1795), type=0x2000, ES_DESCR_LENGTH: 12, bytes left: 0

```

i thought it would be 0x52 or 0xa or 0x6a. well it turns out it was not   :Embarassed: 

take 0x703 or 1795, 0x700 or 1792, 0x6ff or 1791 and you are fine.

the mencoderflags:

```
-aid 1791

or

-aid 0x6ff
```

would select stream 1.

just put them into film.ts.me for the movie film.ts and the script will add it to the flags.

thanks for your help here

the script works perfectly   :Very Happy: 

m@o

----------

## micmac

Hey now!

Thanks for your info. It's interesting to know and it's nice how you figured it out. Also I like that you like my script  :D 

Kind regards

micmac

----------

## G2k

hey guys I have an .flv file I downloaded from youtube and I want to convert it to .mp4 for my iPod. What script should I be using I can't seem to find an appropriate one.

Thanks

----------

## micmac

avi2mp4.sh doesn't work? If not please post its output. I downloaded a FLV from youtube (25fps) and it worked fine. As long as mplayer can play the file and the framerate is <=30 avi2mp4.sh should work.

----------

## G2k

it made an .mp4 file that seemingly worked just fine until i got to the end of the video when the audio stopped. This is the output for the audio encoding

```
Encoding audio:

Freeware Advanced Audio Coder

FAAC 1.26.1 (Apr 26 2008) UNSTABLE

Quantization quality: 100

Bandwidth: 11025 Hz

Object type: Low Complexity(MPEG-4) + M/S

Container format: MPEG-4 File Format (MP4)

Encoding /home/user/rip/tmp/n5yTatgmsIs_mplayer.wav to /home/user/rip/tmp/n5yTatgmsIs_faac.m4a

   frame          | bitrate | elapsed/estim | play/CPU | ETA

 4929/4929  (100%)|   32.3  |    6.0/6.0    |   37.95x | 0.0 

Applying ReplayGain:

/home/user/rip/tmp/n5yTatgmsIs_faac.m4a

No changes to /home/user/rip/tmp/n5yTatgmsIs_faac.m4a are necessary

...but tag needs update: Writing tag information for /home/user/rip/tmp/n5yTatgmsIs_faac.m4a

Extracting raw x264 bitstream from video:

Extracting AVI video (format h264) to /home/user/rip/tmp/n5yTatgmsIs_mencoder_video.h264

                                                   

Muxing:

IsoMedia import - track ID 1 - Audio (SR 22050 - 2 channels)

AVC-H264 import - frame size 320 x 240 at 15.000 FPS      

Import results: 3799 samples - Slices: 26 I 3773 P 0 B - 1 SEI - 26 IDR

Saving /home/user/rip/n5yTatgmsIs.mp4: 0.500 secs Interleaving

                                                        

Cleaning up.

Encoding n5yTatgmsIs.mp4 finished.

File:         Metheny.mp4

Input file does not exist. Skipping.
```

There doesn't seem to be a problem but the audio just stops a few second before the clip ends. Any idea why?

----------

## micmac

Hi,

I checked my file for missing audio towards the end and I have the same issue. Can't tell what's wrong, though.

----------

## micmac

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

@G2k: This should fix the sync issues we experienced e.g. with YouTube files

----------

## micmac

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

----------

## brfsa

Thanks for this great script, works like a charm. 

I am planning to buy an Ipod classic 6th Gen. 

u said it is good for 5/5.5Gen. 

Anyone tested the videos on a 6th Gen IPOD Classic?

Thanks!

----------

## micmac

Glad you like it!

6th (classic) works fine.

----------

## brfsa

Hi all, I have been using it to convert some youtube flv files.

You need to mark media-video/gpac stable, because the 0.4.4 has the "-ipod" option.

# echo "media-video/gpac" >> /etc/portage/package.keywords

what are the options are you guys using for youtube flv files?

the flv files I downloaded are :

Video: 320x240  24bpp  29.970 fps, video_bitrate: 285kbps (found from from gxine stream_info)

Audio: 64kbps, 22050Hz, stereo.

And these are the settings for avi2mp4:

MAX_BITRATE="400"

BPP="0.18"

USE_NERO_AAC=""

FAAC_ENCOPTS=" -b 64 -c 22050 "

NAAC_ENCOPTS=""

X264_ENCOPTS=""

MENCODER_OPTS=""

MAX_RES="320x240"

MP4BOX_IPOD="yes"

RENICE=""

I get the output mp4 files 20-30% larger than the flv.

and the video and audio out of sync for 1 or 2 seconds.

Anyone have ideas?

----------

## micmac

```

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

----------

## micmac

```
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 ;)

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

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]

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

----------

## micmac

```
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)
```

----------

## sipingal

Mencoder is enough. I suggest you use this command to convert video:

I wrote a shell script to convert video for ipod/PSP, it works fine for me. It is freak. I am not going to upload it.  :Sad: 

For IPOD(my IPOD 5.5g): (If the filename is dvd://1, this command will convert DVD to a IPOD/PSP video file. 

```
mencoder -dvd-device /dev/dvd <filename> -o <output.mp4> -ofps 25000/1001 -af lavcresample=48000 -vf harddup -oac lavc -lavcopts aglobal=1:acodec=libfaac -ovc x264 -x264encopts global_header:bitrate=200:mixed_refs:ratetol=50:subq=5:nocabac:partitions=i4x4+p8x8+b8x8:me=umh:me_range=16:qcomp=0.6:frameref=5:bframes=0:trellis=1:level_idc=13 -of lavf -lavfopts format=ipod -vf scale=320:240 -alang eng -slang chi -unicode -subfont-encoding unicode -font Consolas -subfont SimHei -subfont-text-scale 3.8 -subcp cp936 -subpos 98
```

For PSP,

```
mencoder -dvd-device /dev/dvd <filename> -o <output.mp4> -ofps 25000/1001 -af lavcresample=48000 -vf harddup -oac lavc -lavcopts aglobal=1:acodec=libfaac -ovc x264 -x264encopts global_header:bitrate=300:ratetol=50:subq=5:partitions=i4x4+p8x8+b8x8:me=umh:me_range=16:qcomp=0.6:frameref=2:trellis=1:bframes=1:b_pyramid:weight_b:chroma_me:level_idc=21 -of lavf -lavfopts format=psp -vf scale=480:272 -alang eng -slang eng -unicode -subfont-encoding unicode -font Consolas -subfont SimHei -subfont-text-scale 2.8 -subcp cp936 -subpos 98

```

cat ~/.mplayer/mencoder.conf

```
[default]

srate=48000

a52drc=1

mc=0.2

slang="ch,chi,tw,en,eng"

fontconfig=yes

font="Consolas"

subfont="SimHei"

subfont-encoding=unicode

unicode=yes

utf8=yes

subcp=cp936

subpos=96

ffactor=0.75

sub-bg-alpha=0

sub-bg-color=0

subfont-autoscale=3

subfont-osd-scale=1.94

subfont-text-scale=1.94

subfont-outline=2.0

subfont-blur=2.0

subalign=2

spualign=-1

spuaa=4

sub-fuzziness=1

flip=no

vf=pp=de,hqdn3d

```

My mplayer USE flags:

```
media-video/mplayer

     Available versions:  1.0_rc2_p28058-r1 (~)1.0_rc2_p28288 1.0_rc2_p28450 (~)1.0_rc2_p20090226 (~)1.0_rc2_p20090322 [M]**9999 {3dnow 3dnowext X a52 aac aalib alsa altivec amrnb amrwb arts ass bidi bindist bl cddb cdio cdparanoia cpudetection custom-cflags custom-cpuopts debug dga dirac directfb doc dts dv dvb dvd dvdnav dxr3 enca encode esd faac faad fbcon ftp ggi gif gtk iconv ipv6 jack joystick jpeg kernel_linux ladspa libcaca lirc live lzo mad md5sum mmx mmxext mng mp2 mp3 musepack nas nemesi network openal opengl oss png pnm pulseaudio pvr quicktime radio rar real realcodecs rtc samba schroedinger sdl speex sse sse2 ssse3 svga teletext tga theora tremor truetype unicode v4l v4l2 vdpau video_cards_mga video_cards_nvidia video_cards_s3virge video_cards_tdfx video_cards_vesa vidix vorbis win32codecs x264 xanim xinerama xscreensaver xv xvid xvmc zoran}

     Installed versions:  1.0_rc2_p20090322(01:42:00 PM 03/26/2009)(X a52 aac aalib alsa amrnb amrwb ass bidi bindist bl cddb cdio cdparanoia dga dirac directfb dts dv dvb dvd dvdnav enca encode esd faac faad fbcon ftp gif gtk iconv jack jpeg kernel_linux ladspa libcaca live lzo mad md5sum mmx mmxext mng mp2 mp3 musepack nemesi network openal opengl png pnm pvr quicktime rar real rtc samba schroedinger sdl speex sse sse2 ssse3 teletext tga theora tremor truetype unicode vdpau video_cards_nvidia vidix vorbis win32codecs x264 xanim xinerama xscreensaver xv xvid xvmc zoran -3dnow -3dnowext -altivec -arts -cpudetection -custom-cflags -custom-cpuopts -debug -doc -dxr3 -ggi -ipv6 -joystick -lirc -nas -oss -pulseaudio -radio -svga -v4l -v4l2 -video_cards_mga -video_cards_s3virge -video_cards_tdfx -video_cards_vesa)

```

I use this command to detect video information:

```
mplayer -dvd-device /dev/dvd -endpos 0 -ao null -vo null <filename>

```

----------

## micmac

```
1.1.16:

  - fix quite a few return checks that caused avi2mp4.sh to not terminate

    properly

  - adjust ChangeLog's style :)
```

----------

## lysergicacid

i know this is an old post but anyone having issues with this ?

```
Encoding audio:

Freeware Advanced Audio Coder

FAAC 1.28

Quantization quality: 90

Bandwidth: 14800 Hz

Object type: Low Complexity(MPEG-4) + M/S

Container format: MPEG-4 File Format (MP4)

Encoding /home/loz/2010_01_07_22_18_03_16132_mplay.wav to /home/loz/2010_01_07_22_18_03_16132_aac.m4a

   frame          | bitrate | elapsed/estim | play/CPU | ETA

333055/333055 (100%)|  121.3  |  393.9/393.9  |   18.04x | 0.0

Applying ReplayGain:

Error opening file: /home/loz/2010_01_07_22_18_03_16132_aac.m4a

/home/loz/2010_01_07_22_18_03_16132_aac.m4a is not a valid mp4/m4a file.

An error occured.

Command terminated with non-zero exit status.
```

----------

## micmac

Hi there,

I had some issue with faac as well, I can't remember what it was exactly, though. But, you can use neroAacEnc (linux 32bit binary or through wine, see README) or you could choose not to use aacgain by commenting out some stuff in the script.

Regards!

----------

## micmac

BTW :)

```

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

```

----------

## lysergicacid

 *micmac wrote:*   

> Hi there,
> 
> I had some issue with faac as well, I can't remember what it was exactly, though. But, you can use neroAacEnc (linux 32bit binary or through wine, see README) or you could choose not to use aacgain by commenting out some stuff in the script.
> 
> Regards!

 

i'm on 64 bit system and don't really want wine installed, i'll look through the script n disable aac i guess, thanks for the reply  :Smile: 

----------

## micmac

Hi,

if you have a multilib 64 bit install the neroAacEnc Linux binary will work.

Regards

----------

## sipingal

It's for 768kbit/s 320×240 H.264 videos

```

    * BIT_RATE <= 768 kbps

    * 320×240

    * Up to 30 fps

    * H.264 Baseline Profile up to level 1.3

```

Following options must be set in the Baseline Profile

```

    * no B slices: bframes=0

    * no CAVLC entropy coding: nocabac

    * no 8×8 transform: no8x8dct

    * level=1.3: level_idc=13

```

More details please refer:

http://en.wikipedia.org/wiki/H.264   (Figer: Predefined profiles - BP column)

http://rob.opendot.cl/index.php/useful-stuff/h264-profiles-and-levels/

http://rob.opendot.cl/index.php/useful-stuff/ipod-video-guide/

If we have those information, we can have our owner ipod video encoding script.

My script attached. It supports encoding any video files or DVD to the ipod 5/5.5G format. 

Usage:

$ ivconvert <video files>    # if there is a subtitle file with the same as the video file in the current directory, it will embedding it in. 

$ ivconvert dvd://

```
#!/bin/sh

DVDDEVICE="/dev/dvd"

#VC_FFH264="-vc ffh264"

VC_FFH264=""

MENCODER="mencoder"

setmediainfo()

{

    mediainfo="`mplayer -dvd-device ${DVDDEVICE} ${VC_FFH264} -endpos 0 -ao null -vo null "${file}" 2> /dev/null | grep --color=never -e "^VIDEO" -e "VO: \[null\]"`"

    INFOTYPE="`echo "$mediainfo" | wc -l`"

    if [ ${INFOTYPE} -eq 1 ]

    then

   mediainfo="`echo ${mediainfo} | awk '{print $3" "$5}'`"

    elif [ ${INFOTYPE} -eq 2 ]

    then

   sedcond="`echo "${mediainfo}" | grep --color=never "VO: \[null\]" | awk '{print "s/"$3"/"$5"/g"}'`"

   if [ ${usedvd} -eq 1 ]

   then

       mediainfo="`echo "${mediainfo}" | grep --color=never "^VIDEO" | awk '{print $3" "$6}'| sed -e "${sedcond}"`" 

   else

       mediainfo="`echo "${mediainfo}" | grep --color=never "^VIDEO" | awk '{print $3" "$5}'| sed -e "${sedcond}"`" 

   fi

    elif [ ${INFOTYPE} -eq 3 ]

    then

   sedcond="`echo "${mediainfo}" | grep --color=never "VO: \[null\]" | tail -n 1 | awk '{print "s/"$3"/"$5"/g"}'`"

   if [ ${usedvd} -eq 1 ]

   then

       mediainfo="`echo "${mediainfo}" | grep --color=never "^VIDEO" | awk '{print $3" "$6}'| sed -e "${sedcond}"`" 

   else

       mediainfo="`echo "${mediainfo}" | grep --color=never "^VIDEO" | awk '{print $3" "$6}'| sed -e "${sedcond}"`" 

   fi

    else

   echo "Mediainfo error, exit"

   exit 1

    fi

    

    mediainfo="`echo ${mediainfo} | sed s'/\.//'g | tr 'x' ' '`"

}

while [ "$1" != "" ]

do

    file="$1"

    usedvd=`echo ${file} | grep --color=never "dvd://" 2> /dev/null | wc -l`

    if [ ${usedvd} -eq 1 ]

    then

   outfile="dvdrip.m4v"

   setmediainfo

    else

   outfile="${file%.*}.m4v"

   subfile="${file%.*}.srt"

   setmediainfo

    fi

    shift

    media_width="`echo ${mediainfo} | awk '{print $1}'`"

    media_height="`echo ${mediainfo} | awk '{print $2}'`"

    media_fps="`echo ${mediainfo} | awk '{print $3}'`"

    if [ ${media_fps} -lt 10000 -o ${media_fps} -gt 31000 ]

    then

   media_fps=25000

    fi

    whc=`echo ${media_width}*100/${media_height} | bc`

    if [ ${whc} -lt 130 ]

    then

   width=`echo "(${media_width}*100*240/${media_height}/100+8)/16*16" | bc`

   height=240

    elif [ ${whc} -gt 136 ]

    then

   width=320

   height=`echo "(${media_height}*100*320/${media_width}/100+8)/16*16" | bc`

    else

   width=320

   height=240

    fi

    

    if [ -f "${subfile}" ]

    then

   $MENCODER -overlapsub -dvd-device ${DVDDEVICE} "${file}" ${VC_FFH264} -o "${outfile}" \

          -ofps ${media_fps}/1001 -af lavcresample=48000 -vf harddup \

          -oac lavc -lavcopts aglobal=1:acodec=libfaac \

          -ovc x264 \

          -x264encopts global_header:bitrate=200:mixed_refs:ratetol=50:subq=5:nocabac:no8x8dct:partitions=i4x4+p8x8+b8x8:me=umh:me_range=16:qcomp=0.6:frameref=5:bframes=0:trellis=1:level_idc=13 \

          -of lavf -lavfopts format=ipod \

          -vf scale=${width}:${height} \

          -alang eng -slang chi -unicode -subfont-encoding unicode -font "Consolas" -subfont "SimHei" -subfont-text-scale 3.8 -subcp cp936 -subpos 98 -sub "${subfile}"

    else

   $MENCODER -overlapsub -dvd-device ${DVDDEVICE} "${file}" ${VC_FFH264} -o "${outfile}" \

          -ofps ${media_fps}/1001 -af lavcresample=48000 -vf harddup \

          -oac lavc -lavcopts aglobal=1:acodec=libfaac \

          -ovc x264 \

          -x264encopts global_header:bitrate=200:mixed_refs:ratetol=50:subq=5:nocabac:no8x8dct:partitions=i4x4+p8x8+b8x8:me=umh:me_range=16:qcomp=0.6:frameref=5:bframes=0:trellis=1:level_idc=13 \

          -of lavf -lavfopts format=ipod \

          -vf scale=${width}:${height} \

          -alang eng -slang chi -unicode -subfont-encoding unicode -font "Consolas" -subfont "SimHei" -subfont-text-scale 3.8 -subcp cp936 -subpos 98

    fi

done

```

mplayer enabled faac for audio encoding and x264 for video encoding.

```

eix -e mplayer

[I] media-video/mplayer

     Available versions:  1.0_rc2_p20090322 1.0_rc2_p20090731 (~)1.0_rc4_p20091026 1.0_rc4_p20091026-r1 [M](~)1.0_rc4_p20091124-r1 [M]**9999 {3dnow 3dnowext +X +a52 +aac aalib +alsa altivec +ass bidi bindist bl bs2b +cddb +cdio cdparanoia (-)cpudetection (-)custom-cflags (-)custom-cpuopts debug dga +dirac directfb doc +dts +dv dvb +dvd +dvdnav dxr3 +enca +encode esd external-ffmpeg +faac +faad fbcon ftp ggi gif -gmplayer -gtk +iconv ipv6 jack joystick jpeg kernel_linux ladspa libcaca lirc +live lzo mad md5sum +mmx mmxext mng +mp2 +mp3 nas +nemesi +network nut openal opencore-amr +opengl +osdmenu oss png pnm pulseaudio pvr +quicktime radio +rar +real +rtc (-)samba +schroedinger sdl +shm +speex sse sse2 ssse3 svga teletext tga +theora +toolame +tremor +truetype +twolame +unicode v4l v4l2 vdpau video_cards_mga video_cards_nvidia video_cards_s3virge video_cards_tdfx video_cards_vesa vidix +vorbis (-)win32codecs +x264 xanim xinerama +xscreensaver +xv +xvid xvmc zoran}

     Installed versions:  1.0_rc4_p20091026-r1(09:53:23 PM 12/28/2009)(X a52 aac aalib alsa ass bidi bindist bl bs2b cddb cdio cdparanoia dga dirac directfb dts dv dvb dvd dvdnav enca encode esd faac faad fbcon ftp gif iconv jack jpeg kernel_linux ladspa libcaca live lzo mad md5sum mmx mmxext mng mp3 nas network nut openal opencore-amr opengl osdmenu png pnm pvr quicktime rar real rtc samba schroedinger sdl shm speex sse sse2 ssse3 teletext tga theora toolame tremor truetype twolame unicode vdpau video_cards_nvidia vidix vorbis win32codecs x264 xanim xinerama xscreensaver xv xvid xvmc zoran -3dnow -3dnowext -altivec -cpudetection -custom-cpuopts -debug -doc -dxr3 -ggi -gmplayer -ipv6 -joystick -lirc -oss -pulseaudio -radio -svga -v4l -v4l2 -video_cards_mga -video_cards_s3virge -video_cards_tdfx)

     Homepage:            http://www.mplayerhq.hu/

     Description:         Media Player for Linux

```

There are some excellent tools for you: "mp4info, mp4tags"

```

$ eix -e libmp4v2

[I] media-libs/libmp4v2

     Available versions:  1.9.1!t {utils}

     Installed versions:  1.9.1!t(10:55:01 PM 12/26/2009)(utils)

     Homepage:            http://code.google.com/p/mp4v2

     Description:         Functions for accessing ISO-IEC:14496-1:2001 MPEG-4 standard

```

----------

## micmac

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

----------

