Log in

View Full Version : changing Aspect Ratio of AVC streams in .mp4


Pages : [1] 2

hhanh
17th December 2004, 08:11
Well ... I wrote a program to change the p/ar in the mp4 file. :)

--h

Selur
17th December 2004, 08:30
@hhanh: If it works, it would be nice if you could share it with the community :)

Cu Selur

hhanh
17th December 2004, 21:08
Sure. Here it is.

Selur
17th December 2004, 21:27
mods plz authorize :)

bond
17th December 2004, 22:07
splitted and authorized

hhanh, can you plz tell us the correct commandline options to use to change the ar, thanks :)

hhanh
18th December 2004, 00:42
Usage: ARChange.exe -i mp4-file -t track-no [-a width:height]

The track-no is the video track #. You can get it with mp4info. For mp4 files made with Nero Recode, I think it's always 3.

To display the current A/R:
ARChange -i test.mp4 -t 3

To change it to 8:9
ARChange -i test.mp4 -t 3 -a 8:9

A 4:3 DVD source has a PAR of 8:9 because it is 4/3 * 480/720
For a 16:9 DVD source, it's 32:27.

--h

Selur
18th December 2004, 10:35
thx for this tool :)

Cu Selur

SeeMoreDigital
21st December 2004, 18:02
Can somebody make a GUI for this tool?

Maybe hhanh and Moitah can get their heads together and add this functionality to MPEG4 Modifier :)

What do you say guys?


Cheers

Sharktooth
21st December 2004, 18:11
MPEG4Modifier lacks the MP4 container support.
Once (and if) it will be added MPEG4Modifier will be the definitive tool :)

SeeMoreDigital
21st December 2004, 18:15
Originally posted by hhanh
Usage: ARChange.exe -i mp4-file -t track-no [-a width:height]

The track-no is the video track #. You can get it with mp4info. For mp4 files made with Nero Recode, I think it's always 3.

To display the current A/R:
ARChange -i test.mp4 -t 3

To change it to 8:9
ARChange -i test.mp4 -t 3 -a 8:9

A 4:3 DVD source has a PAR of 8:9 because it is 4/3 * 480/720
For a 16:9 DVD source, it's 32:27.
And here are the settings you'll need for both PAL and NTSC 4:3 and 16:9 DAR (which are based on PAR): -

Required AR Custom DAR(PAR) Setting
4:3 PAL 64:60 (or 16:15)
16:9 PAL 64:45
4:3 NTSC 64:72 (or 8:9)
16:9 NTSC 64:54 (or 32:27)

Cheers

hhanh
21st December 2004, 20:15
I don't know, man. I'm working on a mp4 splitter/muxer at the moment. Besides GUIs were never my forte.

--h

bond
25th December 2004, 20:35
hhanh, i now found the time to test this tool with the following commandline:
ARChange -i "C:\path to\mymp4.mp4" -t 201 -a 16:11used 16:11 because thats the value defined in mpeg-4 for 16:9 pal

i also tested different .mp4 files (different ASP video streams, created/muxed with nero, mp4ui and mp4box) and different -t/-a settings, but i always got the following error message:
Assertion failed: !"Unexpected EOF", file ARChange.cpp, line 368

abnormal program terminationany idea what went wrong?

btw is it supposed to work with AVC or ASP video streams?

with avc .mp4 files (created with ateme/nero), i get the following error message:Assertion failed: fAR || !"A/R not present", file ARChange.cpp, line 567

abnormal program termination

Mosu
26th December 2004, 23:01
I guess it's for ASP only. I'm trying to implement AR extraction for AVC at the moment, and it totally sucks compared to ASP. WAY more complicated.

But if it CAN change the AR for AVC then I'd really like to see the source code for that :D

SeeMoreDigital
26th December 2004, 23:23
Originally posted by bond
any idea what went wrong? I've got a feeling this tool might currently only work with DAR values, such as the ones I posted.

Did you try any of them?


Cheers

bond
26th December 2004, 23:38
same results with the DAR values :(

SeeMoreDigital
27th December 2004, 13:04
Originally posted by bond
same results with the DAR values :( Oh well... I thought it may have followed what Moitah posted about DAR here: -

http://forum.doom9.org/showthread.php?s=&postid=561784#post561784

But if it don't... it don't!


Cheers

RanmaSaotome
28th December 2004, 23:56
Just like to say i tested your program on a Nero Digital AVC file & it worked fine. It was an avs file encoded using Recode2 in the max definition AVC profile.

C:\Encode>mp4box -info video.mp4
* Movie Info *
Timescale 1000 - Duration 00:25:41.164
Fragmented File no - 3 tracks
File Brand avc1 - version 0
File has root IOD
Scene PL 1 - Graphics PL 254 - OD PL 254 - Visual PL 255 - Audio PL 0

Track # 1 Info - TrackID 1 - TimeScale 1000 - Duration 00:00:01.000
Track is present in Root OD
Media Type "odsm" - Media Sub Type "MPEG" - 1 samples
MPEG-4 Config: ObjectDescriptor Stream - ObjectTypeIndication 1
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 1000 - Duration 00:00:01.000
Track is present in Root OD
Media Type "sdsm" - Media Sub Type "MPEG" - 1 samples
MPEG-4 Config: SceneDescription Stream - ObjectTypeIndication 1
Synchronized on stream 1

Track # 3 Info - TrackID 3 - TimeScale 24000 - Duration 00:25:41.164
Media Type "vide" - Media Sub Type "avc1" - 36951 samples
Unknown track type


C:\Encode>ARChange -i video.mp4 -t 3
Current A/R = 1:1

C:\Encode>ARChange -i video.mp4 -t 3 -a 32:27
Current A/R = 1:1

C:\Encode>ARChange -i video1.mp4 -t 3
Current A/R = 32:27

Amazing how this tool just popped up right when I needed it thanks.

**Edit

Both nero show time & wmp now recogize the video as being 16:9 :)

It was encoded at a res of 600x400.

SeeMoreDigital
29th December 2004, 00:01
Blimey...

I wasn't expecting this tool to work with Mpeg4/AVC in MP4 files. Especially from a codec as advanced as Nero's!


Nice one!

bond
30th December 2004, 21:09
hm the following findings:

1) the tool only seems to work with .mp4 files where the avc stream already contains an ar value (which was not the case with the nero samples i had)

2) i created an avc stream with x264 and imported to .mp4 with mp4creator: seems as if x264 sets an ar in the stream when encoding automatically (in my case 64:45 for an encoded PAL 16:9 DVD source)

still i dont really get the tool to work 100% correctly:
- i run the tool on the file changing the ar
- a seperate x.mp4.out file get created (with the same filename as the input.mp4), which seems to be a valid .mp4 file
- nero and moonlight (only when you force overlay mixer2 in the graph) plays the file with the newly set ar :)
- still when i run the ar tool again on the renamed new x.mp4 it doesnt work "Invalid SAR value" :(

EthanoliX
30th December 2004, 21:58
Same problem here. The only difference is, the created file is not shown with the corrected ar. :confused:

Mosu
30th December 2004, 22:01
One problem this tool has is that it simply changes a couple of bytes in the avcC atom without decoding it properly. So it might work for some files, but it will break for others whose avcC is not layed out like the program expects.

bond
31st December 2004, 01:57
Originally posted by EthanoliX
Same problem here. The only difference is, the created file is not shown with the corrected ar. :confused:make sure to analyse the .mp4.out (remove the .out from the filename)!

Originally posted by Mosu
One problem this tool has is that it simply changes a couple of bytes in the avcC atom without decoding it properly. So it might work for some files, but it will break for others whose avcC is not layed out like the program expects.hm, maybe thats the reason why my output sample borks a little bit

Mosu
31st December 2004, 09:26
Ah mooo. Sorry, I obviously didn't look close enough at the source. It does parse the avcC atom. Sorry again.

RanmaSaotome
31st December 2004, 18:25
it may have a problem with PAL sources, my source was NTSC 16:9 & the file plays back correctly with or without overlay mixer added.

video1.mp4(NDparser)-->Nero Video Decoder-->Video Renderer.

as you say, its the file with .out at the end that has the changed AR.

kurt
5th January 2005, 22:01
everything went fine with my nero/avc testfiles (PAL source) and SeeMoreDigitals AR-Settings... thx for this nice tool hhanh! :p

pogo stick
8th January 2005, 22:11
Thanks Hhanh! Very nice! :)
It's working with avc for me, but not with every mp4.
Not with this one (http://pogo-stick.nm.ru/v.mp4). :(

hhanh
11th January 2005, 05:33
Sorry for the late answer. I was on vacation.

@bond: The unexpected EOF probably means that the file is not an AVC/MP4 file.
The assert on "A/R not present" mean that the AVCC atom does not have PAR information. Nero files always have it but there is probably a default value of 1:1. If you can't roundtrip a file through the tool, that's a bug :(

@SeeMoreDigital: P/AR of the form X:Y are supported for all X < 256 and Y < 256.

@pogo stick: I'll try your file when I get home. I'm still in transit - reenacting scenes from the Terminal.

--h

bond
11th January 2005, 21:42
great to have you back hhanh :)

could you reproduce my findings:
- doesnt work on files not having an ar info already
- not able to change the ar on files where the tool already changed the ar

also it might be nice if you could add an -o output option for defining an output file (to avoid that people have to change the extension)

thanks for your work :)

hhanh
12th January 2005, 00:10
Originally posted by bond
could you reproduce my findings:
- doesnt work on files not having an ar info already
- not able to change the ar on files where the tool already changed the ar

also it might be nice if you could add an -o output option for defining an output file (to avoid that people have to change the extension)

[/B]

The tool should work with files with an AR info present. Actually, it only works if there is an AR info. And you should be able to change the AR on the files again.
That said, there was a bug. Thanks pogostick for reporting it.

Here's an updated version. I added the -o option too.

SeeMoreDigital
12th January 2005, 00:18
Originally posted by hhanh
Here's an updated version. I added the -o option too. Can somebdy please make a GUI?


Cheers

pogo stick
12th January 2005, 21:21
Originally posted by hhanh
Here's an updated version.
Thanks a LOT! Now it's working! :)

pogo stick
11th April 2005, 10:00
Hhanh, did you think about making patch to mp4box? Would be great.
As far as I know, your tool is unique for AR changing in mp4.

hhanh00
11th April 2005, 18:44
Good idea. That shouldn't be difficult.

--h

Elias
11th April 2005, 21:57
One question hhanh00: does it change/add the aspect ratio values in the same way that MPEG4Modifier does it? That is, like the way XviD does it as well?

hhanh00
11th April 2005, 22:13
No, MPEG4Modifier works on the stream level. It modifies the A/R info stored in the VOL (or is it VOP?). That works for AVI. For the MP4 container, the A/R is somewhere in the MOOV atom (I don't remember where exactly). Incidentally, that's why I couldn't use MPEG4Modifier to change the A/R of my AVC/MP4 files.

--h

bond
12th April 2005, 17:18
mpeg4modifier doesnt handle avc but only asp (asp and avc are different things of course)

afaik the avc aspect ratio is also stored as part of the bitstream (even if in moov)
to my knowledge thats similar to how ar is stored with asp: in the vol, which to my knowledge is also part of the bitstream?

hhanh00
12th April 2005, 18:12
I don't know if the A/R is also stored in the AVC samples but VLC looks at the AVC1 atom for the aspect ratio. That's all I change with ARChanger.

--h

bond
16th April 2005, 14:25
AR is stored in VUI in the SPS afaik

hhanh00
17th April 2005, 09:10
Yes, that's the same thing. That guy is stored inside the AVCC atom.

DeeGee
24th April 2005, 05:36
I have some problems. I discovered the wonders of SmartBob(DGBob) and decided to encode some of the music videos I have on my DVD's into AVC/HE-AAC. Seemed to go fine. Then I noticed that now there is this handy tool. So redid them in anamorphic format. On another file it worked just fine, but on a another the ar chage seems to go fine, but the file is unplayable. FFDShow races trough the file without showing or playing anything and then crashing libavcodec.dll. Nero Showtime seems to actually make the video output screen resize into the correct aspect ration, but neither shows anything.

Here are some small samples.
no aspect ratio change (http://students.oamk.fi/~t3paja01/hero_noar.mp4)
aspect ratio changed (http://students.oamk.fi/~t3paja01/hero_ar.mp4)
These need quite a lot of punch from your machine as they are 704x400x50fps clips. (oddly libavcodec seems to crash also when you run out of cpu cycles on the file without ar change.)

hhanh00
24th April 2005, 06:05
Use apple dumpster and tell us the layout of your top level atoms. Is the moov atom before or after the mdat?

Thanks,
--h

DeeGee
25th April 2005, 08:03
The moov atom seems to be before mdat atom.

$00000000 ($00000014) 'ftyp' unknown atom
$00000014 ($0001f9b4) 'moov' Movie resource atom
$0001f9cc ($04b626dc) 'mdat' Movie data atom
$04b820a8 ($00000024) 'free' Free space atom


[edit] And the atoms on the file that the ar change works have just the same order. And if you didn't notice, I added sample files to my first post.

hhanh00
25th April 2005, 18:35
The problem is that the tool doesn't update the stco or co64 atoms. They indicate the offset of the media chunks in the file. When a new custom A/R is added and none was present in the file, it has to be inserted and the sample locations are changed if the moov atom was placed before the samples. I believe muxing with mp4creator60 puts the moov at the end. It's a crappy work around until the tool also updates the sample to chunk offset atoms.

Thanks,
--h

PS: You're using the 2nd version of this tool, right?

DeeGee
25th April 2005, 19:23
Yes, i'm using the second one you posted. So I need to use mp4creator instead of mp4box...

[edit] I just tested it out and it seems mp4creator (at least the version I have) changes the order to:
1. ftyp
2. moov
3. mdat

from the original
1. ftyp
2. mdat
3. moov

But archanger should work on files that have moov as last? It seems I have been trying to change ar after muxing the audio and video together. And both mp4box and mp4creator change the order so that moov isn't the last one. I simply need to do it before muxing? and it should work as long as mp4creator or mp4box doesn't lose the information on mux.

[edit2] Seems I'm lucky. Both Nero Recode 2 and x264 output mp4 files with moov as last atom. And at least mp4box conserved the information on mux. :)

ari
13th May 2005, 00:02
Originally posted by hhanh
Here's an updated version. I added the -o option too.

Err. Shouldn't that have the ARChange.cpp in it too?

hhanh00
13th May 2005, 02:17
Yes, I didn't attach the file previously. Rename to .cpp because the forum won't accept that extension.

--h

OCedHrt
27th May 2005, 09:11
What are AVC files? If I import/convert an xvid AVI into mp4 is it supposed to work? I get the EOF error when I try it.

SeeMoreDigital
27th May 2005, 09:34
Originally posted by OCedHrt
What are AVC files? Hopefully this will answer your question (http://forum.doom9.org/showthread.php?t=96059).


Cheers

Ajaja2005
25th June 2005, 15:14
How to change the aspect ratio in the h.264 HP stream in mp4 created with x264 (rev.270, wrong --sar)? Latest archange don't work :(

sbeyer20
15th July 2005, 12:25
Hi,

I donīt know what I have done wrong. I always get the EOF error. No matter if I muxed the material from AVi and from RAW but no chanche. So what is my failure?

Thanks Sven