VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 30 of 30
Thread
  1. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    is it possible/simple enough to write a quick customized utility that changes the Aspect Ratio flag in an xvid ?

    so far, i read that there is a flag for changing, but i don't know where it is or how to identify it.

    i recently found out that i encoded a bunch of xvids with the wrong aspect ratio. i know i can change them inside mpeg4modifier, but i want to write my own routine to handle this so that i could run them inside a batch list via drag-drop.

    thank you in advance.
    Quote Quote  
  2. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    but doesn't it recreate the video file ? that's why i was looking for how to identify it inside the video so that i could just change a couple of values without re-writing a new file.
    Quote Quote  
  3. Compare hex dumps of before and after Mpeg4Modifier. The falgs aren't in a fixed location (it will vary depending on the program that created the file) so you'll have to parse the chunks, at least partially.
    Quote Quote  
  4. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i was thinking the same thing, if i encode 1 frame with 4:3 and another with 16:9 and last as 2,35:1 (per xvid config) maybe that will help me determine if something simple or not. thanks.
    Quote Quote  
  5. From the CLI "fc/b" command, both files saved by Mpeg4Modifier:

    Code:
    Comparing files 4x3 DAR.avi and 16X9 DAR.AVI
    000085F4: 2C B0
    000085F5: 3E B6
    00026F6E: 2C B0
    00026F6F: 3E B6
    0005CFA8: 2C B0
    0005CFA9: 3E B6
    0008F272: 2C B0
    0008F273: 3E B6
    000A99EA: 2C B0
    000A99EB: 3E B6
    000D932C: 2C B0
    000D932D: 3E B6
    00106E06: 2C B0
    00106E07: 3E B6
    00125B80: 2C B0
    00125B81: 3E B6
    001678B8: 2C B0
    001678B9: 3E B6
    001CE136: 2C B0
    001CE137: 3E B6
    002234B6: 2C B0
    002234B7: 3E B6
    0025E1A6: 2C B0
    0025E1A7: 3E B6
    0029E1DE: 2C B0
    0029E1DF: 3E B6
    002DDD1A: 2C B0
    002DDD1B: 3E B6
    0030D9D0: 2C B0
    0030D9D1: 3E B6
    003298B0: 2C B0
    003298B1: 3E B6
    00347B76: 2C B0
    00347B77: 3E B6
    00372152: 2C B0
    00372153: 3E B6
    003912A2: 2C B0
    003912A3: 3E B6
    From VirtualDub's hex editor and riff viewer:

    Click image for larger version

Name:	riff.png
Views:	482
Size:	96.6 KB
ID:	16275
    Quote Quote  
  6. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i had decided to sratch the custom tool to read/write directly to the file since hexing is too complicated for me. i just can't get it. i also tried using the "From the CLI "fc/b" command, both files saved by Mpeg4Modifier:" but there is no --fc/b command in the cli tool. i'm using the mmcl.exe tool. it is the strangest tool so far, does seem to work for me. all it does is display this same help screen below and i'm already tired of it.

    Code:
    MPEG4 Modifier CL v1.4.4a
    http://www.moitah.net/
    
    Arguments: [switches] source_path [dest_path]
      dest_path is only optional with --info or --frame-list
    
    Switches:
      --unpack             Remove packed bitstream.
      --pack               Add packed bitstream.
      --par <val>          Set the pixel aspect ratio, <val> is:
                             square - Square Pixel Shape
                             43pal - 4:3 PAL Pixel Shape
                             43ntsc - 4:3 NTSC Pixel Shape
                             169pal - 16:9 PAL Pixel Shape
                             169ntsc - 16:9 NTSC Pixel Shape
                             custom <width:height> - Custom Pixel Shape
      --dar <val>          Set the display aspect ratio, <val> is:
                             custom <width:height> - Custom Display Shape
      --field-order <val>  Change the interlaced field order, <val> is:
                             tff - Top Field First
                             bff - Bottom Field First
      --info               Display detailed information about the video.
      --frame-list <path>  Write a text file containing each frame's type,
                           timestamp, and size to the location specified.
      --always-write       Write a new file even if the video format isn't being
                           changed (useful for converting OpenDML AVIs < 2GB to 
                           standard AVIs).
    Quote Quote  
  7. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i need to change the --dar setting from this (x:235 y:100) to (x:4 y:3) but there is no function in cli to change it not to mention its not working for me. i will search another route. thanks guys for trying to help me out. if i find anything i'll post back.
    Quote Quote  
  8. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    ok, i finally got mmcl to work:

    "D:\tools\mpeg4 Modifier CL\mmcl.exe" --dar custom 4:3 "d:\video.avi" d:\v.avi

    so, this method re-write the video, something i was trying to avoid, plus, it took a short time to process. i am guessing that the info is not in one place but in every header or frame chunk, whatever. anyway, here is an example output run of the test file i did, 2m51s clip, aprox 5 seconds to complete:

    Code:
    MPEG4 Modifier CL v1.4.4a
    http://www.moitah.net/
    
    
    Loading: 7.0%
    Loading: 18.3%
    Loading: 29.3%
    Loading: 39.8%
    Loading: 51.3%
    Loading: 63.3%
    Loading: 74.2%
    Loading: 85.4%
    Loading: 96.5%
    Loading: 100.0%
    Loading: 100.0%
    
    Saving: 0.8%
    Saving: 6.6%
    Saving: 7.1%
    Saving: 12.6%
    Saving: 18.3%
    Saving: 22.4%
    Saving: 24.3%
    Saving: 26.4%
    Saving: 28.4%
    Saving: 29.8%
    Saving: 32.7%
    Saving: 34.0%
    Saving: 37.2%
    Saving: 40.8%
    Saving: 45.6%
    Saving: 50.5%
    Saving: 55.3%
    Saving: 60.4%
    Saving: 65.7%
    Saving: 70.5%
    Saving: 75.4%
    Saving: 80.2%
    Saving: 85.4%
    Saving: 90.0%
    Saving: 94.8%
    Saving: 100.0%
    Saving: 100.0%
    Video was written successfully.
    Quote Quote  
  9. Originally Posted by vhelp View Post
    so, this method re-write the video, something i was trying to avoid
    If you use Mpeg4Modifier to add PAR and DAR flags you'll see the resulting files aren't the same size. Sometimes you have to add/remove data to/from the stream, not just change the existing data. That requires a remux.*

    Originally Posted by vhelp View Post
    plus, it took a short time to process. i am guessing that the info is not in one place but in every header or frame chunk, whatever.
    Yes, that's obvious from the fc results I gave earlier. For example, the first line "000085F4: 2C B0" means at offset 85F4 in the files the first file had a 2C and the second file had a B0. There were a few dozen differences spread throughout the file.


    * I suppose you could look to see if the existing file uses PAR or DAR flags, then set the AR you want by adjusting whichever it has. I think you can get away without remuxing if you do that.
    Last edited by jagabo; 14th Feb 2013 at 22:45.
    Quote Quote  
  10. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    great, so it looks like a custom utility will be needed to read and compare two files and report only the difference, similar to the example you posted earlier. i can probably do that and experiment swapping the values transparently (w/out re-writing a new video file) in the dest file and see if that plays with the new aspect ratio. i will consider playing around with the idea over the long weekend. thank you all for the suggestions.
    Quote Quote  
  11. You don't need write a custom utility to show the differences. You can use fc at the CLI. There are also more sophisticated file compare programs with a GUI that can work with binary files and detect insertions and deletions as well as simple byte differences.

    Once you've identified where the differences are you need to figure out how to locate the AR flags in in any particular AVI file. That will probably require parsing the RIFF chunk* tree, locating the video chunks, identifying which ones have the AR flags**, whether they are DAR or PAR flags, then overwriting them.


    * RIFF chunks start with a 4 byte identifier follwed by a 4 byte length (little endian). In the example I gave earlier you can see the identfier is "00dc" and the length is 00002F69, 12,137 bytes.

    ** Examine known samples looking for identifiable structures that are unique to those chunks. Or even better, get the Xvid and/or Divx specs and learn how they lay out their data.
    Quote Quote  
  12. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    thanks for the explanations.

    ok, so i figured out your original fc/b function. its the windows dos/console app

    Code:
    C:\WINDOWS\system32>fc/?
    Compares two files or sets of files and displays the differences between
    them
    
    
    FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
       [drive1:][path1]filename1 [drive2:][path2]filename2
    FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
    
      /A         Displays only first and last lines for each set of differences.
      /B         Performs a binary comparison.
      /C         Disregards the case of letters.
      /L         Compares files as ASCII text.
      /LBn       Sets the maximum consecutive mismatches to the specified
                 number of lines.
      /N         Displays the line numbers on an ASCII comparison.
      /OFF[LINE] Do not skip files with offline attribute set.
      /T         Does not expand tabs to spaces.
      /U         Compare files as UNICODE text files.
      /W         Compresses white space (tabs and spaces) for comparison.
      /nnnn      Specifies the number of consecutive lines that must match
                 after a mismatch.
      [drive1:][path1]filename1
                 Specifies the first file or set of files to compare.
      [drive2:][path2]filename2
                 Specifies the second file or set of files to compare.
    to compare some 1 frame (xvid) avi's, i use:

    "c:\windows\system32\fc.exe" /B "D:\tools\mpeg4 Modifier CL\235.avi" "D:\tools\mpeg4 Modifier CL\043.avi"

    output

    Code:
    Comparing files D:\TOOLS\MPEG4 MODIFIER CL\235.avi and D:\TOOLS\MPEG4 MODIFIER CL\043.AVI
    00004778: 7A 78
    00004779: 81 40
    0000477A: 9D 4D
    Quote Quote  
  13. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i could only find one player that will actually play a 1 frame file, smplayer..but, i am having one problem, i can't seem to figure out how to configure it to repeat by default when you open a file. when i open a 1 frame clip, it opens/close instantly. however, after it finishes playing, i set it to repeat using the following setting: (right-click, play, A-B, repeat) then i play to see the aspect ratio. however, when i open another file, the repeat is lost.

    does anyone know how to set it repeat and save it in preference ?
    Quote Quote  
  14. DECEASED
    Join Date
    Jun 2009
    Location
    Heaven
    Search Comp PM
    i could only find one player that will actually play a 1 frame file, smplayer.
    SMPlayer

    Use MPC-HC, problem solved.

    P.S.: For the notes, only the MPC-HC "Mpeg Splitter" has problems with single-frame video streams. The flaw is very-old, and seemingly it will never be fixed.
    Quote Quote  
  15. Sorry, I thought you understood FC was the CLI file compare app. It should be in your search path so you shouldn't need to specify the entire path to the program. If the files are in the CWD you don't need to specify the full path. If there are no spaces in the path you don't need quotes. So if you CD to the folder with the two files the following should work:

    Code:
    fc /b 235.avi 043.avi
    I don't know about a player that plays single frame AVI file well. What about making a video with one long GOP? Maybe 5 seconds. That will give you enough time to verify the displayed aspect ratio and probably only have one set of DAR/PAR flags.
    Quote Quote  
  16. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i don't have mpc-hc (6mb) installed, but am installing now since its a small file. i need to be able to repeat multiple drag/drop in order to test visually since reading the flags (ie mediainfo, gspot) may not be reliable, for obvious reasons.

    thanks jagabo. i long path/quotes are bc i use need it in my tool suite.

    long gop... i want to minimize any form of inconsistancy of hits as possible, so i felt 1 frame would be efficient, less data to worry about.

    i'm not familiar with all the apps floating around the web that might be able to do what i want. might be easier to just write a quick file reader/writer to swap those three posted values and see what happens. later i can extend the complexity to more than one frame, repeat swap etc., until i figure out the correct way to update aspect ratio (if possible) and w/out rewriting video file. i found a couple of old apps that read/write low level, enough for the job, i think. i just have to re-aclimate myself in those old projects to strip out the code into a new short project.
    Quote Quote  
  17. There are lots of free hex editors that will allow you to quickly change a few bytes in a file. I use an older release of this:

    http://www.hhdsoftware.com/free-hex-editor

    VirtualDub also has a built in hex editor with which you can do the same. It has the additional benefit of having a RIFF Chunk Tree view.
    Quote Quote  
  18. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    success! i was able to change AR on the 1 frame xvid avi. the tool is crude, but works.

    the 1st test run caused the blue screen of death and i lost everything and had to re-create the tool changes. always save. save. save. anyway. after a dozen or so test runs, i finally got it working. based on what i've seen in the above, (fc/b compare) there are three values that must be updated.

    now, i will take to next level, and re-create new xvid avi's with more than 1 frames.
    Quote Quote  
  19. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    success! i was able to change AR on the 3 frame xvid avi. now, i will attempt a greater number of frames. it is looking like there are three values to change. this may be the AR flag parameter(s) to change. i worked out what the values are for each AR:

    Code:
    7FF6BD - 16:9
    78404D - 4:3
    7A819D - 2:35
    so, now all that is left to do in this aspect ratio changer utility:

    1. determin where these values live
    2. add a selector to change AR
    3. undo ?
    Quote Quote  
  20. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    as it turns out, once you reach a certain threshold in frames, a new group of values repeat. but i think it can still work, i just need to change my aproach, and search for the AR sequence strings (already posted above) and apply the changes to all searched out values, still without rewriting a new video file. i think i can complete this utility tomorrow. its late and i'm tired, so until then.
    Quote Quote  
  21. Originally Posted by vhelp View Post
    i just need to change my aproach, and search for the AR sequence strings
    It's very dangerous to blindly replace three byte sequences. It's always possible that video or audio data will have those same sequences*. You will corrupt the files if you change those. At the very least look for longer sequences. For example, looking for a "00dc" followed 28** bytes later by the AR sequence would be much safer. What you really should do is parse the RIFF chunks, verify it's Divx or Xvid, positively locate the video chunks with the AR flags, then change them.

    Remember PAR and DAR flags are handled differently. So you 'll have to identify which is used and handle them appropriately. Then there are custom PAR/DAR flags which won't match the sequences you listed.


    * I searched for one of your 3 byte sequences and found hundreds of them in a 700 MB AVI file. A quick inspection revealed that most of them were not AR flags.

    ** that's where it was in the hex dump I posted earlier. But you must verify that it's always at that position, regardless of what version of Xvid was used; whether it was Xvid, Divx, ffmpeg that created the file, etc.
    Last edited by jagabo; 19th Feb 2013 at 07:37.
    Quote Quote  
  22. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i agree.

    so, anyway. parsing the RIFF has become a challenge. i've been reading a lot of docs on it and to be honest, its confusing since most of the sources i've seen are in c, c++, c# or vb-xyz, etc. i haven't found any delphi source code examples, so in short, this may take some time (maybe a few weeks or longer. i have other things like life,etc) for me to figure all of it out. but i will try and figure it out. ty all for the above replies. if i figure it out i'll come back and update, tx again.
    Quote Quote  
  23. Originally Posted by vhelp View Post
    parsing the RIFF has become a challenge. i've been reading a lot of docs on it and to be honest, its confusing since most of the sources i've seen are in c, c++, c# or vb-xyz, etc. i haven't found any delphi source code examples
    Conceptually, it's very simple. Chunks have a 4 byte identifier followed by a 4 byte length followed by the data. Chunks can be nested.

    http://msdn.microsoft.com/en-us/library/windows/desktop/dd318189%28v=vs.85%29.aspx

    So you look at the first four bytes to see if it's a chunk you're interested in. Read the next for bytes to get the length of the chunk. Deal with the chunk or skip ahead that many bytes to see the next chunk. You can use VirtualDub's hex editor with its RIFF chunk viewer to see the structure.

    Click image for larger version

Name:	chunks.png
Views:	774
Size:	53.8 KB
ID:	16375

    In this example the "avih" chunk is highlighted (by clicking on the chunk in the left window) in the right window in orange. In the right windows you can see the first four bytes are "avih", the chunk's length is 0x00000038 (56 bytes). For basic AVI header elements the hex editor can show the field names. I clicked on the "02" in the right window and VirtualDub showed the size of that field (four bytes) by highlighting it in green. It also shows the name and function of that field at the bottom of the window (dwStreams: number of audio, video, etc. streams".

    You can probably write your own parser faster than you could analyze, understand, and adapt somebody else's.
    Quote Quote  
  24. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    ok, so i've been playing around with different ideas parsing different size xvid avi files and may have found a solution. hopefully i can finally apply the fix to my xvid files. also, while working on these ideas i learned i had a whole bunch more folders full of xvids encoded with wrong ar. course, once i'm sure its ready, i will backup those folders and apply the fix. but, to speed things up (visually) i wonder if i can jimmy something up that i can run the patched xvids through that will play just (one frame out of x) so i can quickly assure myself all are fixed. something that i can run via command line and repeat (play+pause+stop) next clip, until folder finished. anyway. once i complete the utility, i'll post a solved in the title and move on to my other projects.
    Quote Quote  
  25. you can probably use mplayer in slave mode to do the playback check,...
    Quote Quote  
  26. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    i finally found a reliable method to parse an xvid avi for its aspect ratio values. however, the routine takes too long because i have to read in the file 1 byte at a time. but that's not a real problem since i can read much faster if i know how to calculate the distance for the next frame and only need to read in a couple of values. the routine should be near instant once i get that part worked out.

    for simplicity and speed sake, using the 3 frame xvid video example, how do i calculate or obtain the same values for len and offset, or is this stored somewhere in the list_movi chunk for each frame listed below:

    Code:
    LIST - movi - (len=109920, off=10252)
       00wb - (len=19220, off=10260)
       00dc - (len=54282, off=29488)
       00dc - (len=34670, off=83778)
       00dc - (len=1712,  off=118456)
       idx1 = (len=64,    off=120176)
    i just need the 00dc values. once i have that, then i can make dynamc adjustments to the seek position for each frame..should be instant once worked out..thanks.
    Quote Quote  
  27. Originally Posted by vhelp View Post
    i just need the 00dc values. once i have that, then i can make dynamc adjustments to the seek position for each frame..should be instant once worked out..thanks.
    No, the audio and video chunks will be interleaved. You have to parse all the chunks. As with all chunks, the length of the chunk is the dword following the chunk ID. Your process be something like:

    1) read 4 byte chunk id
    2) read 4 byte length
    3) if this is a chunk you're interested in do whatever you need to do
    4) skip ahead (seek) length bytes
    5) repeat 1-4 until done
    Quote Quote  
  28. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    ok, i think i figured it out, no wonder why i wasn't getting it initialliy when i tried...the hex value are reversed, when i want to calculate the length, (the position after the chunk id) it is not 0AD4 = 2772, instead it is D40A which now = 54282, which is what shows in the above example. hex always confused me. so all i really need is the offset only, not the length. i will have to play around till i get it working in the seek routine. i'm getting closer. thanks again.
    Quote Quote  
  29. Originally Posted by vhelp View Post
    ok, i think i figured it out, no wonder why i wasn't getting it initialliy when i tried...the hex value are reversed, when i want to calculate the length,
    Of course, AVI is an Intel architecture based container. Always little endian. I mentioned that earlier in post 12.
    Quote Quote  



Similar Threads