Log in

View Full Version : Modifying mpeg4 User Data field


w0rd™
17th February 2009, 02:09
Hi, I was wondering is there any way to modify the user data setting for a batch of video files?

I have a whole lot of xvid files, and I need to change the 'user data' from xvid**** to divx****

Is there anything for example that will do this, just like using a fourCC batch modifier?


:thanks:

squid_80
17th February 2009, 07:42
Mpeg4modifier will let you change them manually but I'm not sure if there's a way to automate it.

w0rd™
18th February 2009, 08:47
Really, I wonder if it is very difficult to make something to automate it?

Damn, it would take so long to import over 60 files into Mpg4M, one by one, to change them....

Has to be some way!

squid_80
18th February 2009, 10:13
Did some digging.
Command line version, haven't tested it: http://forum.doom9.org/showthread.php?t=117553
Mpeg4toolkit, based on mpeg4modifier, apparently can do batch processing: http://forum.doom9.org/showthread.php?t=113637

kypec
18th February 2009, 10:46
Look at this thread (http://forum.doom9.org/showthread.php?t=124794) if you use Linux.
If you're a Windows guy (like me) then perhaps XVI32 utility (http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm) used together with a following script launched through batch file might ease your efforts:)
fix_header.batFOR %%f IN (*.avi) DO "C:\Program Files\xvi32\xvi32.exe" %%f /S="C:\Program Files\xvi32\replace_string.xsc" xvid divx
FOR %%f IN (*.avi) DO "C:\Program Files\xvi32\xvi32.exe" %%f /S="C:\Program Files\xvi32\replace_string.xsc" XVID DIVX

replace_string.xscREM Go to start of file
ADR $0000

REM Replace FourCC code "1st string" -> "2nd string"
REPLACEASC %1 BY %2

w0rd™
18th February 2009, 14:36
Squid_80, I used the mp4toolkit, but it didnt really do what I was after, I think it just does batch for unpacking, like MP4M. And I'm not very good with command line tools, I'm not good with all these commands, scripts etc....which bring me to kypec :)

Kypec, can you tell me what to do in a little more detail, I'm not knowledgeable in this script, commands, hex things.

I downloaded XV132, and put it in program files.
I made the bat file and pasted what you posted, and I made a file called replace_string.xsc and pasted the code you posted.

So how do I apply it to my folder of avi files?
And is this for the "user data", as I see in the code it says FourCC?

Thanks to both of you.

kypec
19th February 2009, 07:26
I downloaded XVI32, and put it in program files.
You did good, XVI32 is just a binary/hex editor for modifying arbitrary file. It supports script automation which we're gonna use to modify few bytes in your AVI files.

I made the bat file and pasted what you posted
OK, now put this BAT file in the same folder where your AVI files are located.

and I made a file called replace_string.xsc and pasted the code you posted.
This script file is supposed to be in the same folder where you have unzipped XVI32 -> in the C:\Program Files\XVI32 if you followed my advice.

So how do I apply it to my folder of avi files?
And is this for the "user data", as I see in the code it says FourCC?
Once you launch BAT file it will proceed through every single AVI file it finds in that folder and run XVI32 editor's script on it.
My two commands just replace the very first xvid string occurrence with divx and XVID with DIVX. They must be executed separately, because the replace function of binary editor is not case sensitive (as opposed to normal text editors).
Those two strings replaced usually happen to mean FourCC codes, which are located in two places in regular AVI, once for the whole file, secondly for the video stream.
If you want to replace some more complex user data entries then please do your changes on one AVI file with MPEG4Modifier (http://www.moitah.net/download/latest/MPEG4Modifier.zip) manually and upload the original file and the modified to some file hosting server, like MediaFire (http://www.mediafire.com/) for example.
You don't need to upload entire AVI files, starting 1 megabytes of each is sufficient. For splitting the AVI file you can use DGSplit (http://neuron2.net/dgsplit/dgsplit11.zip) utility. Once I examine and compare the differences you made on the AVI I'll be able to provide you with the appropriate script which will automate your task.

BTW, have you tried to play the modified AVI files in your player yet? My guess is that changing those 2 FourCC strings could resolve the compatibility issue.

olnima
19th February 2009, 16:45
...there is also a command-line-version of MPEG4Modifier for windows...
In combination with a batchfile you can automate what You want.

http://forum.doom9.org/showthread.php?t=117553

Olnima

kypec
20th February 2009, 09:05
...there is also a command-line-version of MPEG4Modifier for windows...
In combination with a batchfile you can automate what You want.

http://forum.doom9.org/showthread.php?t=117553

Olnima
That command line version has already been mentioned by squid_80. It is not usable for the purpose of OP, cause it doesn't support modification of user data in the AVI header.

w0rd™
21st February 2009, 01:55
Kypec, I did as you say, but it didn't change the user data. I changed the bat file to what I wanted exactly, and it worked!

Just to make it more clear, the xvid file has a fourCC of XVID/XviD and when opened with mp4m shows "XviD0046" in the "user data" field.
With the above bat file the fourCC changes to DIVX/DivX4 and the user data remains unchanged.
I do not want to change the fourcc anyway, as I have already a batch 4CC changer, which changes it to what I want instantly, which is DivX5/DX50.

So my only problem was the user data.
I edited the bat file and left only the first line, and changed it to:
FOR %%f IN (*.avi) DO "C:\Program Files\xvi32\xvi32.exe" %%f /S="C:\Program Files\xvi32\replace_string.xsc" xvid00 divx5

Now it seems this did the trick, the "user data" has changed from XviD0046 to DivX50046, but as you can see the "046" part remains.

Now is there any way to replace this specific "user data" field, which is always it seems, XviD followed by some numbers, which aren't always the same for every file, with DivX50***, or can it only be done if the specific data in the field is known?
Also why doe the fourcc batch changer that I have, change the fourcc instantly for a whole folder of files, but with this method it has to scan each file and change, can not the "user data" be also changed instantly the same way?

Thanks again for all the help kypec!

kypec
21st February 2009, 10:47
1) Your batch fourCC changer is probably that fast, because it scans only the very few bytes in the beginning of each AVI file which comprise the header. XVI32 must process the whole files though. It's only my assumption, anyway.
2) I suggest you to be very careful with WHAT is replaced by WHAT. It seems your replace strings have not the same length which might corrupt the AVI to be not playable anymore. Every piece of information being replaced must fit exactly where it belongs to. Once you insert 5 chars where originally only 4 chars have been the pointers present in the header(s) are no longer valid! XviD00 cannot be directly replaced by DivX5 because the latter is one byte shorter!
3) I'd recommend you to study a bit of help file included with XVI32, especially the chapter on script commands. There is also REPLACE command which operates with hexadecimal values as opposed to strings. IIRC there is also supported some Joker/wildcard substitution which you could use for replacing XviD00?? for DivX5000 or whatever you need. Just remember the data piece replaced must have the same length (count of bytes) as the original!

For testing you don't have to run batch/XVI32 scripts externally. You can open your AVI file directly in XVI32 environment, where you can examine very precisely how the replacement process works. Once the script is doing exactly what you want, you just save it to .xsc file and run it through batch.
Good luck!

olnima
22nd February 2009, 12:11
That command line version has already been mentioned by squid_80. It is not usable for the purpose of OP, cause it doesn't support modification of user data in the AVI header.

kypec: Yeah, you're right, did not look at it 'deep' enough, sorry.

@wOrd: In which way and why do You want the user-data? Is anything not playable in your DVD-player?

olnima
22nd February 2009, 14:37
OK, this

http://rapidshare.com/files/201154216/MPEG4Modifier_ChUD.zip.html

can do what You want, cmd for example

'MPEG4Modifier "myvideofile.avi" DivX503b1393p'

The video 'myvideofile.avi' is loaded and saved with userdata changed to 'DivX503b1393p' (every other userdata-entry is deleted!) as 'myvideofile_ChUD.avi' (ChUD - ChangedUserData)

Have fun, post your results,

Olnima

P.S.: It's quick and dirty and there is absolutely NO check, which UserData is given in cmd, so take care !!!

//edit: this cmd 'MPEG4Modifier "myvideofile.avi"' behaves like "normal" MPEG4Modifier

w0rd™
23rd February 2009, 03:11
1) Once you insert 5 chars where originally only 4 chars have been the pointers present in the header(s) are no longer valid! XviD00 cannot be directly replaced by DivX5 because the latter is one byte shorter!


But when I replaced xvid00 with divx5, the remaining digits of the original did not delete, but added to divx5. Like I said, the original was xvid0046, when I put in script change xvid00 to divx5, the end result was divx5046.
So did it really become shorter or just different?


I'll look at the rest , but I think it is getting too deep for my level.



@wOrd: In which way and why do You want the user-data? Is anything not playable in your DVD-player?

basically trying to get around the divx ultra of only allowing divx files?
xvid files would have to be re-encoded to author the divx dvd, but if I changed the fourCC it still wouldn't work, until I changed the user data as well, then it would allow to author without re-encoding..

OK, this

http://rapidshare.com/files/201154216/MPEG4Modifier_ChUD.zip.html

can do what You want, cmd for example

'MPEG4Modifier "myvideofile.avi" DivX503b1393p'


//edit: this cmd 'MPEG4Modifier "myvideofile.avi"' behaves like "normal" MPEG4Modifier

So is it the same as just adding the files one by one to mp4m and changing userdata and then saving the file, only difference is that it's done with command line, or does it do a batch of files at same time?


Thanks again.

kypec
23rd February 2009, 06:20
But when I replaced xvid00 with divx5, the remaining digits of the original did not delete, but added to divx5. Like I said, the original was xvid0046, when I put in script change xvid00 to divx5, the end result was divx5046.
So did it really become shorter or just different?

You are either mistyping in this post or in your batch script.
If the original data are xvid0046 (8 chars) and you supply the replace parameters xvid00 divx5 then the result will be divx546 (7 chars) and not divx5046.
Resulting AVI file will be 1 byte shorter than original. Sorry, but I can't help you any further than I did. I explained in detail how to use REPLACE functions inside XVI32, the help included explains it very well with examples provided also. If you're not able to apply those features for your target then no one else will be. The steps needed are fairly trivial: define WHAT you want to be replaced and define BY WHAT it should be replaced. Take care that both strings/groups of bytes are of same length, that's all there is to it.

olnima
23rd February 2009, 10:30
But when I replaced xvid00 with divx5, the remaining digits of the original did not delete, but added to divx5. Like I said, the original was xvid0046, when I put in script change xvid00 to divx5, the end result was divx5046.
So did it really become shorter or just different?


I'll look at the rest , but I think it is getting too deep for my level.



basically trying to get around the divx ultra of only allowing divx files?
xvid files would have to be re-encoded to author the divx dvd, but if I changed the fourCC it still wouldn't work, until I changed the user data as well, then it would allow to author without re-encoding..



So is it the same as just adding the files one by one to mp4m and changing userdata and then saving the file, only difference is that it's done with command line, or does it do a batch of files at same time?


Thanks again.

I overread "only"... :)

Just feed this modified MPEG4Modifier with a batch-file.

Copy and paste this single line

FOR /F "tokens=*" %%i IN ('dir /B /OD /TW "'MYPATH'\*.avi"') DO start /wait MPEG4Modifier %%i 'MYUSERDATA'

into a batch-file (for example chud.bat) and replace 'MYPATH' with your path to your avi-files (for example c:\myvids\avis\toconvert) and replace 'MYUSERDATA' with the Userdata You want (for example DivX503b1393p, do not use a space-char. in it) and start your batch. You do not have to do anything until every *.avi-file from the given directory is processed. Replace EXACTLY !!! (look at the quotes!) what I've written.

Olnima

//edit: Example:

FOR /F "tokens=*" %%i IN ('dir /B /OD /TW "c:\myvids\avis\toconvert\*.avi"') DO start /wait MPEG4Modifier %%i DivX503b1393p

//edit2: ... with different output-folder

FOR /F "tokens=*" %%i IN ('dir /B /OD /TW "c:\myvids\avis\toconvert\*.avi"') DO (
start /wait MPEG4Modifier %%i DivX503b1393p
move *_ChUD.avi "c:\myvids\avis\converted"
)

assuming, that

c:\myvids\avis\converted

is your preferred output-dir.

olnima
26th February 2009, 18:41
@wOrd: success ?

w0rd™
28th February 2009, 04:22
....define WHAT you want to be replaced and define BY WHAT it should be replaced. Take care that both strings/groups of bytes are of same length, that's all there is to it.

Ok, thanks, I'll try it out more, it will still be good to know.

@wOrd: success ?

hey thanks for that Olnima, it did as you say :cool:
It loads each file one by one, changes the user data, and saves each file.
So it has done what I wanted out of mpeg4mod!

But how does it replace exactly the user data, no matter what was there before? Like if I use xvi32, like kypec said, for it to replace, both values have to be known, so how does mp4m just get rid of whatever value is there and replace with another of different length?
Some files have 2 values in the user data (eg xvid** and divx**), and mp4m removes both and replaces with chosen value...

Even if you tell me answer, I will maybe not understand :p
But it makes me curious anyway, as why no easy tool can be made for this job, like a 4cc changer, maybe only way is the file MUST be loaded(or scanned) fully and saved to change value?...or maybe it can be done with xvi32 with some testing, I still need to play around with that.


Anyway, I have still achieved end result I wanted for now, so thanks for all the help Olnima and kypec!


:thanks:

olnima
28th February 2009, 11:01
Easy answer: there is no need to keep the same length (size) of userdata as you had before. I think this statement from kypec is simply wrong.

Olnima

In MPEG4Modifier You can also change the userdata manually (delete one from two entries) and the avis are not destroyed. The only thing is that You exactly have to know which userdata You want to or must have.

My modified MPEG4Modifier just clears the userdata-field after video is loaded, adds that one given in a commandline if the second cmd-parameter is given and saves all. You can do it manually if You select every userdata-entry after video is loaded and click on "-"-button.
After that click on "+"-button, add YOUR string and save.

If You open your avi-file with a hex editor and count, how often Your userdata is in the file (every frame or I-frame, I don't know), You will know, why the whole file has to be parsed and saved. :) FourCC has to be written only 2 times in the whole file.

Anyway, glad that I could help You.

//edit:
<
(every frame or I-frame, I don't know)
>

...has to be every I-frame...

w0rd™
1st March 2009, 11:33
If You open your avi-file with a hex editor and count, how often Your userdata is in the file (every frame or I-frame, I don't know), You will know, why the whole file has to be parsed and saved. :) FourCC has to be written only 2 times in the whole file.

Anyway, glad that I could help You.

//edit:
<
(every frame or I-frame, I don't know)
>

...has to be every I-frame...


Oh ok, that explains my curiosity, so it has to check it for every I-frame, as opposed to 4cc which is just twice in the whole file. I can now see why it can't be instant like a 4cc changer!


Anyway, thanks again.
:)