How to change AVC level with a hex editor

I am yet to find a program which allows one to change the AVC level of an MP4 movie file on Mac or Linux without re-encoding. Fortunately, it is very easy and fast to do.

All you’ll need is a hex editor, like HexEdit on the Mac, ghex for Gnome or Okteta for KDE 4 in Linux.

Please note:  I strongly recommend that you make a copy of your MP4 file before editing it. It’s very easy to corrupt a file this way and make it unplayable.

Open your movie in your hex editor of choice and do a case sensitive search in ASCII mode for “avcC” (without the quotes), or for 61 76 63 43 in hex.

Once it is found, you will see in hex mode a series of numbers immediately after:

The first hex number is usually 01 and unimportant for our purpose.

The hex numbers which follow determine the profile type:

42 E0 – for Baseline Profile

4D 40 – for Main Profile

58 A0 – for Extended Profile

64 00 -  for High Profile

The number after that is the level, in hex, e.g.:

1F (31 in dec) is level 3.1

29 (41 in dec) is level 4.1

33 (51 in dec) is level 5.1

It’s very easy to do the conversion on a calculator which supports hex numbers (the calculators on Mac OS X and various Linuxes have Programmers’ modes which do).

In order to successfully change the AVC level, do a search and replace for all instances of the profile/level number you encounter in the file with the value you need. E.g. if you see that the file is High Profile Level 5.1 and you wish to change it to High Profile Level 3.1, do a search in hex for all instances of 64 00 33 and replace them with 64 00 1F.

Save the file and you are done.

Some notes:

  1. The main purpose of this exercise is to make MP4 files playable on the Playstation 3 without re-encoding them first. For reasons known only to Sony, it will refuse to play a file which has a needlessly high AVC level set.
  2. Did I mention that you should make a copy of your movie before you edit it with a hex editor? Please do. Many things can go wrong and I am not responsible for any data loss resulting from the application of method outlined above.

The information in this article was taken from the following forum topic:

http://www.ps3site.pl/forum/index.php?showtopic=2800

A big thank you to dk75!

13 Responses to “How to change AVC level with a hex editor”

  1. Piksel says:

    Great info! Thanks!

    I used this technique to modify some MP4’s to play on my AppleTV. They had an AVC Profile of “High@4.1″ which means you can add it to iTunes but it come up as incompatible when trying to sync to AppleTV. If you change the profile to “Main@4.1″ then it syncs and plays fine! :)

    Also, do not make the mistake of using the “0xED” Hex Editor as I did and then discover that your movies are corrupt part way through :/ It also took ages to save the file effectively re-writing the whole thing.

    What worked great for me was Hex Fiend (http://ridiculousfish.com/hexfiend/) as it only modifies the specific bytes (saves the change instantly) and the mp4s synced and played perfectly after the change was made :)

  2. Filmguy15 says:

    Hello,

    Excellent tutorial!!

    However, I can’t seem to get it to work. I follow the instructions, and find the right numbers etc, but the resulting video is just solid green, with fully functional audio. Any thoughts? Thanks.

  3. admin says:

    @Filmguy15

    The video is solid green when played where? On the PS3? In VLC?

    Perhaps your video really requires High profile to function correctly?

  4. Filmguy15 says:

    The video is green when I test it on my computer in VLC. I noticed that when I changed just the level (4.1 to 3.1) then it works (although not on my Apple TV), but if I change the profile then it’s toast. Very strange indeed. At any rate, thanks for the info!

  5. admin says:

    Maybe your video really does require the profile it’s in. The method described above is just a shortcut, which may not work. Re encoding is probably your only option at this point.

  6. Nice find. I am working out the details, but I believe I can script the entire operation, including the copy and it doesn’t take very long. Something like 2 minutes on my MBP.

    I have it working with a single setup but I am going to update it for more profiles. In my case, I have encoded most of my files the same way, which makes it nice and easy to convert. Hell, I may go so far as adding them to the iTunes library, as well. Keep an eye on my website.

  7. Thomas says:

    Here’s an easy way to do it, if you are familiar with perl:

    perl -pe ’s/\x61\x76\x63\x43\x01\x4d\x40(\x28|\x29|\x33)/\x61\x76\x63\x43\x01\x4d\x40\x1f/sgx’ Infile.mp4 > outfile.mp4

    This will substitute the profiles with 1F and make a copy of the file. I was looking to actually wrap this in some nice gui, but it looks like I won’t have time for a few days.

    You should already have perl install if you are using a Mac. This looks to be pretty fool proof, considering that the values are pretty unique. Again, it could blow up your video file, hence piping it to another file. In this case, it takes roughly 2 minutes to copy over a 1 GB file on my computer.

    This doesn’t cover all the profiles (just main) and it does require that x01 exists right after the avcC, but it does change the profile level to 1F, which the iPad supports. I have tested this on a handful of my files. Most of mine were encoded to work on an XBOX 360 using Handbrake and Connect360. So, mine are fairly standard.

    Anyway, enjoy. If I wrap it I will post up a link to it.

  8. nicorac says:

    Thanks for your post.
    I created a tool to accomplish this editing quick and fast.

    You can find it here:
    http://coolsoft.altervista.org/h264leveleditor

  9. admin says:

    Too bad it’s only for Windows. There already are tools for Windows that do this. Not so for Mac or Linux.

  10. George says:

    You can edit H.264 profile level for Mac with Subler.

    http://code.google.com/p/subler/

  11. [...] 另:似乎苹果为了保证播放流畅性,在iOS上H264只支持到main@L4.1的profile,对于L5.x的直接拒绝同步,提示不能播放。不过5.x的profile很少见,如果真碰到了的话,可以用这个方法把文件metadata里的profile修改成4.1的。 [...]

  12. philippe says:

    It works for me. On a movie MKV in high@L5.1 and on a movie MP4 in high@L5.1, bot to high@L4.1. Thanks !

  13. Hello, and thanks for your blog post.
    I have designed a tiny little PHP library that allows to set the AVC level:

    http://cnedelcu.blogspot.com/2012/06/avclevels-php-library-read-and-set.html

    It is based on your findings, and has worked fine for me on all the videos that I’ve tried.

    Regards,
    Clement

Leave a Reply