Log in

View Full Version : How to make Mencoder H.264 Baseline profile compatible?


2ig2ag
10th August 2009, 01:03
I have a portable player, which I believe supports playing video encoded in H.264 Baseline Profile up to Level 2.0.
I like to use mencoder to encode video for playback on it. Here is the command that I have tried, which doesn't work:
$ mencoder -vf scale=320:240 -oac copy -ovc x264 \
-x264encopts bitrate=800:bframes=0:nocabac:trellis=0:vbv_maxrate=900:level_idc=20 \
-of lavf -lavfopts format=mp4 inputfile.avi -o outputfile.mp4
I am sure the only problem with the above command is the part of -x264encopts, which I have no idea how to make it compatible with baseline profile. I have tried setting 'AVC Profiles' to 'Baseline Profile' and 'Bitrate' to '800' in MeGui, and it produces videos that play perfectly on my player.
What does setting 'AVC Profile' to 'Baseline Profile' in megui affects every parameter of x264 encoding? And how can I set mencoder to be compatible with H.264 Baseline profile?
Thanks! Someone please give me a tip.

Dark Shikari
10th August 2009, 01:07
You forgot to turn off 8x8dct.

microchip8
10th August 2009, 01:12
$ mencoder -vf scale=320:240 -oac copy -ovc x264 \
-x264encopts bitrate=800:bframes=0:nocabac:trellis=0:vbv_maxrate=900:level_idc=20 \
-of lavf -lavfopts format=mp4 inputfile.avi -o outputfile.mp4


Are you serious? Using lavf in mencoder to output an mp4? lolwut. You do know that lavf in mencoder is terribly broken and thus produces borked mp4's?

Better output to avi or raw video and then use MP4Box (gpac) to mux!

nm
10th August 2009, 01:12
Also, are you sure that the portable player supports the audio format that you copy from the AVI file? Some players only support AAC audio in MP4.

nm
10th August 2009, 01:14
Are you serious? Using lavf in mencoder to output an mp4? lolwut. You do know that lavf in mencoder is terribly broken and thus produces borked mp4's?
Indeed, but is it also broken without B-frames? IIRC, that was the main issue.

microchip8
10th August 2009, 01:21
Indeed, but is it also broken without B-frames? IIRC, that was the main issue.

Pretty much it is. My portable player which also supports only baseline, does not accept mp4's made by mencoder. If I use raw video or avi and then mux with MP4Box, no issues at all.

2ig2ag
10th August 2009, 01:22
1.I don't think it's a problem of muxing video into mp4 with lavf in mencoder, since I got no problem muxing mpeg4-sp video that way for playback on my player.
2.And I have also tried turning off 8x8dct with
-x264encopts bitrate=800:bframes=0:no8x8dct:nocabac:trellis=0:vbv_maxrate=900:level_idc=20
but still no luck.
3.The audio from the source file is AAC. My player should have no problem with it.

I believe the problem is with -x264encopts part.

nm
10th August 2009, 01:47
1.I don't think it's a problem of muxing video into mp4 with lavf in mencoder, since I got no problem muxing mpeg4-sp video that way for playback on my player.
H.264 muxing can be broken even if MPEG-4 SP works.

2.And I have also tried turning off 8x8dct with
-x264encopts bitrate=800:bframes=0:no8x8dct:nocabac:trellis=0:vbv_maxrate=900:level_idc=20
That should be compliant, although not very high quality. Try muxing separately as froggy1 said.

2ig2ag
10th August 2009, 02:27
H.264 muxing can be broken even if MPEG-4 SP works.


That should be compliant, although not very high quality. Try muxing separately as froggy1 said.

Thx a lot. Problem solved. It turns out that it's really lavf who is messing up.

Dark Shikari
10th August 2009, 02:44
Thx a lot. Problem solved. It turns out that it's really lavf who is messing up.lavf is fine; it's mencoder's interface to lavf that's problematic.

roozhou
10th August 2009, 04:13
lavf is fine; it's mencoder's interface to lavf that's problematic.

Yes, mencoder's broken lavf output has been reported for years, but it seems none of mplayer devels are willing to fix it.

sipingal
4th March 2010, 16:12
The options we need are:

no8x8dct
bframes=0
nocabac
trellis=0
nomixed-refs
global_header # please do enable this opition

After the converting, you can verify the files with mp4info which is included in libmp4 or mediainfo tools(http://mediainfo.sourceforge.net/)

I'm not at home. I will post the full options I used next time.

Selur
4th March 2010, 17:14
nomixed-refs? thought baseline would allow mixed-refs,...

Dark Shikari
4th March 2010, 18:27
nomixed-refs? thought baseline would allow mixed-refs,...Mixed refs isn't a profile feature, it's an encoder feature. Of course Baseline allows it.

phibertron
5th March 2010, 07:34
if you are using newer builds of mencoder, then you will have to watch out and see if "weightp" is included int he build
If you want to encode to a baseline profile,
you will need to turn it off "weightp = 0"

sipingal
5th March 2010, 10:25
if you are using newer builds of mencoder, then you will have to watch out and see if "weightp" is included int he build
If you want to encode to a baseline profile,
you will need to turn it off "weightp = 0"

Thank you phibertron. The weightp=0 is what I need for the latest mencoder & x264.

Here is the command I used to convert the file to ipod 5.5G format.
mencoder -overlapsub -dvd-device /dev/dvd test.avi -o test.mp4 -ofps 25000/1001 -af lavcresample=48000 -vf harddup -oac lavc -lavcopts aglobal=1:acodec=libfaac -ovc x264 -x264encopts global_header:partitions=p8x8+b8x8+i8x8+i4x4:level_idc=13:subq=5:crf=19:nocabac:frameref=1:me=umh:subme=6:nomixed_refs:me_range=32:chroma_me=1:trellis=0:no8x8dct:cqm=flat:chroma_qp_offset=0:slices=1:nr=0:bframes=0:keyint=60:keyint_min=25:scenecut=40:bitrate=330:ratetol=1.0:qcomp=0.60:qp_min=10:qp_max=38:qp_step=2:vbv_maxrate=700:vbv_bufsize=350:ip_factor=1.4:weightp=0 -of lavf -lavfopts format=ipod -vf scale=320:240 -alang eng -slang zh,chi -unicode -subfont-encoding unicode -font Consolas -subfont SimHei -subfont-text-scale 3.8 -subcp cp936 -subpos 98


BTW, perhaps you will love the tool called "mp4tags"

phibertron
5th March 2010, 18:29
Actually I use MP4box for my tags and thumbnail


mp4box -tag-list

Supported iTunes tag modifiers:
album_artist: usage: album_artist=album artist
album: usage: album=name
tracknum: usage: track=x/N
track: usage: track=name
artist: usage: artist=name
comment: usage: comment=any comment
compilation: usage: compilation=yes,no
composer: usage: composer=name
created: usage: created=1939-01-01T01:01:01
disk: usage: disk=x/N
tool: usage: tool=name
genre: usage: genre=name
name: usage: name=name
tempo: usage: tempo=integer
writer: usage: writer=name
group: usage: group=name
cover: usage: cover=file.jpg,file.png
encoder: usage: encoder=name
gapeless: usage: artist=yes,no


And if I need to add or modify chapter points, I use Drax
(I used to use mp4creator, but it became unreliable and borked things up, ever since itunes 9.x came out)


http://www.arlt.eu/blog/projects/drax/

Import Chapters:
drax.exe /import:"Chapters.txt" /file:"test.m4v"

Export Chapters:
drax.exe /export:"C:\Temp\Chapters.txt" /file:"C:\Temp\Movie.m4v"

The tool uses the GPAC MP4BOX Time Code Format (one chapter per line):
h:m:s.ms name e.g. 01:30:15.123 My Chapter