VideoHelp Forum




+ Reply to Thread
Results 1 to 12 of 12
  1. Hi

    IF the cats. Anyway

    please I wonder if does exist a way to change, via commandline in windows, the height value tag of an .avi file like this temp.avi

    https://www.swisstransfer.com/d/c6be6f53-50c7-4f8f-87dc-365d232a4f47

    so that the height internal tag change from the originally 1088 to 1080

    hex change from 4008 into 3808 in 3 points

    from

    Image
    [Attachment 73097 - Click to enlarge]


    to

    Image
    [Attachment 73096 - Click to enlarge]



    thanks
    Quote Quote  
  2. ah yes, but compliCat
    Quote Quote  
  3. I did what you wanted three changes, no problem to post python script to use in batch or even make an exe to run it with arguments,

    but I did those changes in avi header on pos 44, then it seams to be following video stream header bytes 54 (2bytes) and 72 (4bytes) changes, but mediainfo still reports original height 1088. Is that file suppose to be fixed?
    Image Attached Files
    Quote Quote  
  4. oh wowcat
    Quote Quote  
  5. but yes the temp_1080.avi is recognized as 1080 correctly, my mediainfo tell 1088 il the original height but this is not a problem: the height value is 1080

    another .avi example:

    https://www.swisstransfer.com/d/3d48c3e1-968c-4e1e-96b5-b0333ab94dcd

    https://www.swisstransfer.com/d/06d514ec-5fbd-4aa0-b4fc-b750995f8c7b

    also this other .avi mjpeg files are intimately 1920x1080 but written in stream copy modee by ffmpeg which however marks them as 1088
    Last edited by marcorocchini; 10th Aug 2023 at 13:13.
    Quote Quote  
  6. Originally Posted by _Al_ View Post
    I did what you wanted three changes, no problem to post python script to use in batch or even make an exe to run it with arguments,

    but I did those changes in avi header on pos 44, then it seams to be following video stream header bytes 54 (2bytes) and 72 (4bytes) changes, but mediainfo still reports original height 1088. Is that file suppose to be fixed?
    MediaInfo reports the same about his source files too, height 1080, original height 1088.
    Quote Quote  
  7. based on this, this python script was made, you can use this python file in your batch script if you have python installed, usage as python is in there:
    Code:
    import os
    import sys
    
    def load_value(avi_path, offset, length):
        with open(avi_path,'rb') as f:
            f.seek(offset,0)
            return int.from_bytes(f.read(length), byteorder='little')
    
    def get_offset(avi_path, string):
        with open(avi_path,'rb') as f:
            offset = 0
            f.seek(0)
            while (buff := f.read(16)):
                if string in buff:
                    return offset + buff.index(string) 
                else:
                    offset += 16
            else:
                print(f'  avi header with fcc type: "{string.decode()}" not found, avi header not found  in {avi_path}')
                return None
    
    def overwrite_bytes(avi_path, offset, new_integer, length):
        with open(avi_path,'r+b') as f:
            f.seek(offset,0)
            bytes_val = new_integer.to_bytes(length, 'little')
            f.write(bytes_val)
    
    def main(avi_path, new_dwHeight):
        new_dwHeight = int(new_dwHeight)
        avih_offset = get_offset(avi_path, b'avih')
        if avih_offset is not None:
            dwHeight = load_value(avi_path, avih_offset + 44, 4)
            overwrite_bytes(avi_path, avih_offset + 44, new_dwHeight, 4)
            print(f'  avih pos 44: {dwHeight} to {new_dwHeight}  {avi_path}')
        vids_offset = get_offset(avi_path, b'vids')
        if vids_offset is not None:
            dwHeight = load_value(avi_path, vids_offset + 54, 2)
            overwrite_bytes(avi_path, vids_offset + 54, new_dwHeight, 2)
            print(f'  vids pos 54: {dwHeight} to {new_dwHeight}  {avi_path}')
            dwHeight = load_value(avi_path, vids_offset + 72, 4)
            overwrite_bytes(avi_path, vids_offset + 72, new_dwHeight, 4)
            print(f'  vids pos 72: {dwHeight} to {new_dwHeight}  {avi_path}')
    
    if __name__ == '__main__':
        '''
        usage, this should change mjpg avi to height 1080 if using python in cmd prompt:
        python  change_avi_height.py  filename.avi  1080
        '''
    
        args = []
        for arg in sys.argv[1:]:
            args.append(arg)
        if len(args) < 2:
            raise ValueError('Two arguments needed. First argument is avi filename, second is new height')
        for i, arg in enumerate(args[:2]):
            if i==0:
                if not os.path.isfile(arg) or not arg.lower().endswith('.avi'):
                    raise ValueError(f'First argument must be existing avi filepath. Got: {arg}')
            else:
                try:
                    int(arg)
                except (TypeError, ValueError):
                    raise ValueError(f'Second height argument must be an integer. Got: {arg}')
        print(f'Changing avi header heights for files to: {args[1]}')
        main(*args)
    If not having python, you need exe file.
    If having python, you can make exe file yourself, install pyinstaller in cmd prompt:
    Code:
    pip install PyInstaller
    then use command (make sure there is your current python installed version like 38, 39 or latest 311):
    Code:
    "C:\Users\*** user name ***\AppData\Roaming\Python\Python38\Scripts\pyinstaller.exe"  "*** your path to python file ***\change_avi_height.py" --name "change height in mjpg avi"  -–onefile
    then in directory where your change_avi_height.py is you will find dist directory and in there your compiled EXE file you can use in batch scripts, usage is:
    Code:
    "change height in mjpg avi.exe"  "filenami.avi" 1080
    zip with that exe file:
    Image Attached Files
    Quote Quote  
  8. Image
    [Attachment 73103 - Click to enlarge]


    oh wow it works
    absoluty useful (but I don't understand how you did it, but everything is fine)

    it changes very well
    Image
    [Attachment 73104 - Click to enlarge]


    oh my ***

    thanks
    Quote Quote  
  9. Originally Posted by jagabo View Post
    MediaInfo reports the same about his source files too, height 1080, original height 1088.
    Samples he provided, temp.avi and temp2.avi does not show original height 1088 though, I might have some old mediainfo version (21.03), not sure.
    Quote Quote  
  10. my old version of mediainfo 0.7.90 over the modify temp.avi report:

    Code:
    Generale
    Complete name                            : C:\temp.avi
    Format                                   : AVI
    Format/Info                              : Audio Video Interleave
    Format profile                           : OpenDML
    File size                                : 2,65 GiB
    Duration                                 : 1 min 34s
    Overall bit rate                         : 242 Mb/s
    Writing application                      : Lavf59.16.100
    
    Video
    ID                                       : 0
    Format                                   : JPEG
    Codec ID                                 : MJPG
    Duration                                 : 1 min 34s
    Bit rate                                 : 242 Mb/s
    Width                                    : 1.920 pixel
    Height                                   : 1.080 pixel
    Original height                          : 1.088 pixel
    Display aspect ratio                     : 16:9
    Frame rate                               : 25,000 FPS
    Color space                              : YUV
    Chroma subsampling                       : 4:2:2
    Bit depth                                : 8 bit
    Scan type                                : Interlacciato
    Scan order                               : Top field first
    Compression mode                         : Con perdita
    Bits/(Pixel*Frame)                       : 4.677
    Stream size                              : 2,65 GiB (100%)


    I think ffmpeg have at least a "problem": when concatenate multiple .avi mpeg files that are 1920x1080 --> generate a final output strangely 1920X1088

    however your programs works fine
    Quote Quote  
  11. Originally Posted by _Al_ View Post
    Originally Posted by jagabo View Post
    MediaInfo reports the same about his source files too, height 1080, original height 1088.
    Samples he provided, temp.avi and temp2.avi does not show original height 1088 though, I might have some old mediainfo version (21.03), not sure.
    I was referring to his source images in another thread where he was concatenating two MJPEG AVI files into one. That's the cause of the 1088 line problem in the videos here.

    https://forum.videohelp.com/threads/410710-how-to-merge-multiple-avi-mjpeg-files#post2700803
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!