VideoHelp Forum
+ Reply to Thread
Results 1 to 23 of 23
Thread
  1. i have a vpy script i have to run on DVDs and some mp4\mkv files, i have a seperated script for each.
    all of them need to be , x265 , 10bit , crf18 , 720p , mkv .

    what would be the best way to do it so it would look like in the VSedit preview?
    Image
    [Attachment 48317 - Click to enlarge]

    if so what do i type in?

    other options are staxrip which doesnt work for me with x265 and inputs an error even on simple scripts

    for

    Code:
    from vapoursynth import core
    
    clip = core.d2v.Source(r'D:\VIDEO_TS.d2v')
    clip = core.vivtc.VFM(clip,1)
    clip = core.vivtc.VDecimate(clip)
    clip.set_output()

    Code:
    Error Video encoding using x265 2.9+34 (2.0.0.0)
    
    Video encoding using x265 2.9+34 failed with exit code: -1073741795 (0xC000001D)
    
    The exit code might be a system error code: {EXCEPTION}
    Illegal Instruction
    An attempt was made to execute an illegal instruction.
    
    
    ------------------- Video encoding using x265 2.9+34 -------------------
    
    "C:\Program Files (x86)\VapourSynth\core64\vspipe.exe" D:\test_temp\test.vpy - --y4m | D:\Programs\Staxrip.2.0.0.0.x64\Apps\Encoders\x265\x265.exe --crf 20 --output-depth 10 --frames 581 --y4m --output D:\test_temp\test_out.hevc -
    
    Error: fwrite() call failed when writing frame: 0, plane: 0, errno: 32
    Output 5 frames in 0.64 seconds (7.76 fps)
    
    
    
    StaxRip.ErrorAbortException: Video encoding using x265 2.9+34 failed with exit code: -1073741795 (0xC000001D)
    
    The exit code might be a system error code: {EXCEPTION}
    Illegal Instruction
    An attempt was made to execute an illegal instruction.
    
    
    ------------------- Video encoding using x265 2.9+34 -------------------
    
    "C:\Program Files (x86)\VapourSynth\core64\vspipe.exe" D:\test_temp\test.vpy - --y4m | D:\Programs\Staxrip.2.0.0.0.x64\Apps\Encoders\x265\x265.exe --crf 20 --output-depth 10 --frames 581 --y4m --output D:\test_temp\test_out.hevc -
    
    Error: fwrite() call failed when writing frame: 0, plane: 0, errno: 32
    Output 5 frames in 0.64 seconds (7.76 fps)
    
    
       at StaxRip.Proc.Start()
       at StaxRip.x265Enc.Encode(String passName, String commandLine, ProcessPriorityClass priority)
       at StaxRip.x265Enc.Encode()
       at StaxRip.GlobalClass.ProcessVideo()
       at System.Threading.Tasks.Parallel.<>c__DisplayClass4_0.<Invoke>b__0()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at StaxRip.GlobalClass.ProcessJob(String jobPath)
    or it could be done with pytone executable script which is also i am not sure how to do. (for demonstration you can use the simple "test.vpy" for an example)
    what do you reccomend ?
    Quote Quote  
  2. I downloaded staxrip just to check to see if something was wrong, it works correctly

    So probably something is up with your local configuration, maybe python issue or vapoursynth install issue

    Also , Y4M works correctly with recent x265 builds (I posted there was some issue in the other thread, but I just tested a few recent versions, it seems to be ok now, and that exact staxrip x265.exe version works too with commandline)



    Check if your vspipe is working, might be some version issue (maybe your vspipe is a different version)

    Code:
    "C:\Program Files (x86)\VapourSynth\core64\vspipe.exe" --info "D:\test_temp\test.vpy" -





    Since you already have multiple individual scripts, I recommend learning the commandline so you can do things in batch. It's a good time to learn about batch files and commandline as any

    You can save presets and add to joblist queue in vsedit, but you still have to load each script and queue them one by one. I think most GUI's do this too, you'd have to load each one by one to queue them. Which is a pain. Whereas a batch file you just double click and all of them are processed

    Also , are you using waifu2x-caffe upscales ? Since that part of the script works in float, I recommend going down to 10bit 4:2:0 directly in the script (and piping 10bit data). Otherwise it will be slower with additional step to go back to 10bit. Also you go float => 8bit => 10bit and the quality will be slightly lower.
    Quote Quote  
  3. the easiest it is to encode right in your script, you name it as *.py, not *.vpy and run it in some console, or even VSedit (just check script)
    Code:
    #your script to get clip, could be something else, point is just to get clip first (Vapoursynth VideoNode object)
    import vapoursynth as vs
    from vapoursynth import core
    input = r'C:\path\your.input.mp4'
    clip = core.ffms2.Source(input)
    clip = core.std.SetFrameProp(clip, prop="_FieldBased", intval=0)   #making sure it is flagged progressive
    clip = core.resize.Lanczos(clip, 640, 360, format = vs.YUV420P10)   #changing resolution, or not, but changing it to 10bit
    
    #clip.set_output()  #VSEdit needs this, otherwise it would not run
    
    
    #this second part encodes clip to *.265
    import subprocess
    import shutil
    import os
    
    output_directory = r"C:\Destination"   #you put here existing directory on your PC
    
    x265 = shutil.which('x265')  # have x265 executable in working directory or in the PATH, otherwise you get  error, argument of type 'NoneType' is not iterable
    output = os.path.join(output_directory, os.path.basename(input)+'.h265')
    
    x265_cmd = [x265, '--frames', f'{len(clip)}',
                 #'--input-csp', 'i420',
                 '--y4m',
                 '--input-depth', f'{clip.format.bits_per_sample}',
                 '--output-depth', f'{clip.format.bits_per_sample}',
                 '--input-res', f'{clip.width}x{clip.height}',
                 '--fps', f'{clip.fps_num}/{clip.fps_den}',
                 '--crf',    '18',
                 '--output', output,
                 '-']  
    process = subprocess.Popen(x265_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    
    clip.output(process.stdin, y4m = True)
    process.communicate()
    Last edited by _Al_; 8th Mar 2019 at 15:53.
    Quote Quote  
  4. and encoding directly in VS Edit it seems to work as well, it is convenient, you can save your preset in there
    script:
    Code:
    import vapoursynth as vs
    from vapoursynth import core
    input = r'C:\path\your.input.mp4'
    clip = core.ffms2.Source(input)
    clip = core.std.SetFrameProp(clip, prop="_FieldBased", intval=0)   #making sure it is flagged progressive
    clip = core.resize.Lanczos(clip, 640, 360, format = vs.YUV420P10)   #changing resolution, or not, but changing it to 10bit
    clip.set_output()
    I selected executable and then put this into that UI:
    Code:
    --y4m
    --frames {f}
    --input-depth {bits}
    --output-depth {bits}
    --input-res  {w}x{h}
    --fps {fpsn}/{fpsd}
    --crf 18 
    -o "{sd}/{sn}.h265"
    -
    Image Attached Thumbnails Click image for larger version

Name:	Capture.JPG
Views:	498
Size:	88.3 KB
ID:	48325  

    Last edited by _Al_; 8th Mar 2019 at 14:45.
    Quote Quote  
  5. to elaborate on what treat we were given with Vapoursynth, for example, make that encoder modul yourself, name it: "x265.py" or whatever name and put it into that directory :
    Code:
     .....Python37\Lib\site-packages\vapoursynth
    linux has it somewhere else, check where your site-packages directory is on linux:
    in terminal enter: python3
    then
    >>>import site
    >>>site.getsitepackages()

    so you make x265.py, put it in that directory or you have it always in working directory:
    Code:
    import subprocess
    import shutil
    import os
    import vapoursynth as vs
    from vapoursynth import core
    
    def encode(clip=None, crf=18, file='', directory=''):
    
        if not clip or not file or not directory:
            raise ValueError("clip, file or directory are mandatory arguments")
        if not isinstance(clip, vs.VideoNode):
            raise ValueError("'clip' is not a vapoursynth clip")
        if not isinstance(crf, int):
            raise ValueError("'crf' needs to be an integer")
        if not os.path.isfile(file):
            raise ValueError("'file' is not a file")
        if not os.path.isdir(directory):
            raise ValueError("'directory' does not exist")
    
        is_in_path = shutil.which('x265') is not None
        if is_in_path:
            x265 = shutil.which('x265')
        else:
            raise ValueError("put x265 executable in working directory or in the PATH") 
      
        if not clip.format.color_family == vs.YUV:
            raise ValueError("not a YUV clip")
               
        output = os.path.join(directory, os.path.basename(file)+'.h265')
    
        x265_cmd = [x265, '--frames', f'{len(clip)}',
                     #'--input-csp', 'i420',
                     '--y4m',
                     '--input-depth', f'{clip.format.bits_per_sample}',
                     '--output-depth', f'{clip.format.bits_per_sample}',
                     '--input-res', f'{clip.width}x{clip.height}',
                     '--fps', f'{clip.fps_num}/{clip.fps_den}',
                     '--crf',  f'{str(crf)}',
                     '--output', output,
                     '-']  #input
    
        process = subprocess.Popen(x265_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    
        clip.output(process.stdin, y4m = True)
        process.communicate()
        return
    then run your any script.py, that would encode your vapoursynth clip to h265 file:
    Code:
    import vapoursynth as vs
    from vapoursynth import core
    input = r'C:\path\your.input.mp4'
    clip = core.ffms2.Source(input)
    clip = core.resize.Lanczos(clip, format = vs.YUV420P10)
    #clip.set_output()
    
    output_dir = r'C:/Destination'
    
    import x265
    x265.encode(clip=clip, crf=18, file=input, directory=output_dir)
    Last edited by _Al_; 8th Mar 2019 at 18:26.
    Quote Quote  
  6. if all those .h265 extensions would throw you off of your workflow, you can put mp4 in all of those scripts, instead of h265
    Quote Quote  
  7. Originally Posted by _Al_ View Post
    if all those .h265 extensions would throw you off of your workflow, you can put mp4 in all of those scripts, instead of h265
    Most x265 builds do not support MP4 or any container, just elementary bitstream output . There is a modded x265 build (Yuuki) one that does support container, but it tends to be older than the commonly distributed ones (doesn't get updated often)

    x265 --help will tell you if that specific one does or not

    For example , the one with staxrip, or the auto build suite
    -o/--output <filename> Bitstream output file name
    yuuki mod
    -o/--output <filename> Output file name. Default is raw bitstream, MP4 if *.mp4, MKV if *.mkv

    There is a ffmpeg vapoursynth patch . So -f vapoursynth demuxer input makes A/V encoding / muxing easier. Some compiled versions at doom9, but some bugs with one of them speed wise for some scripts. (The official patch is very slow when the vpy script has more than one filter)
    Quote Quote  
  8. I have x264 that was not compiled with mp4 support,
    but that x265 yes, I guess I was lucky to pick it, it was from here:
    https://builds.x265.eu/

    so is it faster if elementary streams are generated and then muxed in mp4 later?
    Quote Quote  
  9. Originally Posted by _Al_ View Post
    I have x264 that was not compiled with mp4 support,
    but that x265 yes, I guess I was lucky to pick it, it was from here:
    https://builds.x265.eu/
    These x265 are ES only

    I think only the videolan x264 have MP4 missing (ES , MKV only)


    so is it faster if elementary streams are generated and then muxed in mp4 later?
    Speedwise I think it's faster doing it during - video/audio/muxing all in the same go . But ffmpeg doesn't support all x264 /x265 CLI features
    Quote Quote  
  10. Originally Posted by poisondeathray View Post
    https://builds.x265.eu/
    These x265 are ES only
    It muxes mp4 for me here, I had one year old version, so I checked latest version
    https://builds.x265.eu/x265-64bit-10bit-2019-03-04.exe
    and that one too encodes into mp4
    Quote Quote  
  11. Originally Posted by _Al_ View Post
    Originally Posted by poisondeathray View Post
    https://builds.x265.eu/
    These x265 are ES only
    It muxes mp4 for me here, I had one year old version, so I checked latest version
    https://builds.x265.eu/x265-64bit-10bit-2019-03-04.exe
    and that one too encodes into mp4
    It does not say MP4 support in the fullhelp

    It's just renaming the extension - not a valid container .

    If you check an encode with mediainfo, in the container field it will say "format HEVC, FileExtension_Invalid"

    instead of "Format : MPEG-4" for a valid MP4 container
    Quote Quote  
  12. yes, you are right, mediainfo gives details for me, not seeing full info, and file is not seekable, it just plays to the end, its not good
    Quote Quote  
  13. Originally Posted by _Al_ View Post
    yes, you are right, mediainfo gives details for me, not seeing full info, and file is not seekable, it just plays to the end, its not good
    well i tried all that was suggested here , by miracle the bug in staxrip was fixed at the exact same day as this post lol , now it encodes x265 just fine.
    i tried all the other methods tho.
    the first one with VSedit with the "x265-64bit-10bit" you provided here , it works and outputs a .h265 file bitstream (if i change the extention to mp4 it just plays it without time or anything) that can be used with MKVToolNix to merge with the sound , subs etc.
    also tried the .py script , it work to but it gave some interesting encode with green jagged lines and pink rainbows all over it
    Code:
    import vapoursynth as vs
    from vapoursynth import core
    input = r'D:\VIDEO_TS.d2v'
    
    clip = core.d2v.Source(r'D:\VIDEO_TS.d2v')
    clip = core.vivtc.VFM(clip,1)
    clip = core.vivtc.VDecimate(clip)
    clip = core.resize.Lanczos(clip, format = vs.YUV420P10)
    
    clip.set_output()
    
    
    output_dir = r'D:/Games'
    
    import x265
    x265.encode(clip=clip, crf=18, file=input, directory=output_dir)
    the x265 file is the same you posted (if i run this script with VSedit , it works , when i load the preview it encodes it first , then opens the preview , which is fine without any green lines)

    Originally Posted by poisondeathray View Post
    Originally Posted by _Al_ View Post
    Originally Posted by poisondeathray View Post
    https://builds.x265.eu/
    These x265 are ES only
    It muxes mp4 for me here, I had one year old version, so I checked latest version
    https://builds.x265.eu/x265-64bit-10bit-2019-03-04.exe
    and that one too encodes into mp4
    It does not say MP4 support in the fullhelp

    It's just renaming the extension - not a valid container .

    If you check an encode with mediainfo, in the container field it will say "format HEVC, FileExtension_Invalid"

    instead of "Format : MPEG-4" for a valid MP4 container
    thanks for all the ways to use this , are the HEVC files that are given with scripting method are viable to use with MKVmerge?
    Quote Quote  
  14. Originally Posted by zanzar View Post
    are the HEVC files that are given with scripting method are viable to use with MKVmerge?
    All valid HEVC elementary bitstreams can be used in mkvmerge (at least any mkvmerge versions in the last few years)
    Quote Quote  
  15. Originally Posted by poisondeathray View Post
    Originally Posted by zanzar View Post
    are the HEVC files that are given with scripting method are viable to use with MKVmerge?
    All valid HEVC elementary bitstreams can be used in mkvmerge (at least any mkvmerge versions in the last few years)
    when i open the preview in VSedit , what do i see? do i see a lossless image of the source + the filters?
    will there be differnce in quality between the methos? or will they essentially look the same if all are "crf 18"? (vs edit encode , .py , staxrip)

    i like the .py method , as i created a script for each instance and just have to click on it and wait .
    Quote Quote  
  16. Originally Posted by zanzar View Post
    when i open the preview in VSedit , what do i see? do i see a lossless image of the source + the filters?
    Yes. That preview is before lossy compression is applied

    It's analogous to previewing an .avs script in avspmod, or vdub

    will there be differnce in quality between the methos? or will they essentially look the same if all are "crf 18"? (vs edit encode , .py , staxrip)

    i like the .py method , as i created a script for each instance and just have to click on it and wait .
    If the same script, same x265.exe version is used, same settings - it should be the same
    Quote Quote  
  17. Originally Posted by poisondeathray View Post
    Originally Posted by zanzar View Post
    when i open the preview in VSedit , what do i see? do i see a lossless image of the source + the filters?
    Yes. That preview is before lossy compression is applied

    It's analogous to previewing an .avs script in avspmod, or vdub

    will there be differnce in quality between the methos? or will they essentially look the same if all are "crf 18"? (vs edit encode , .py , staxrip)

    i like the .py method , as i created a script for each instance and just have to click on it and wait .
    If the same script, same x265.exe version is used, same settings - it should be the same
    i dont know if you mentioned it , but it seems that the x265.exe needs to be at the same folder as the .py execution code.
    also i downloaded the x265 you provided here , what could be a reason to change it?
    Quote Quote  
  18. x.265 executable should be in directory where the .py Vapursynth scrip is that imports the other encoding py, or in the PATH, check how to add an executable to PATH for windows

    not sure why there is a problem, cmd lines are the same, what comes on my mind atm is that I use Python 3.6 and also having older version of Vapoursynth to match that Python 3.6 Version. Which means that output() function might need something else, not sure, I will observe it closely or when I upgrade.
    Quote Quote  
  19. I seemed to narrowed it down, those scripts using output() function for subprocess' stdin:
    Code:
    process = subprocess.Popen(x264_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    clip.output(process.stdin, y4m = True)          # to get raw stream with y4m header for  x265 encoder
    clip.output(process.stdin)                      #to get raw stdin for x264 encoder
    give jagged lines , distorted image, if clip is loaded from anamorphic video (does not matter what source loaded it) and clip is NOT RESIZED. Did about 10 different videos and it acted up only if there was HDV camcorder video, NTSC DV or VOB clip, AND those clips were not resized.

    Maybe a bug or design, not sure, just resize video to square pixel and it should be fine.
    Quote Quote  
  20. to test it and save a time encoding shorter video, you can use this line :
    clip = clip[0:50]
    that would trim your video only to 50 first frames

    because that resize should be some proprietary size , 1:1 square pixel works, but not any resize, or some oddball resize, that would encode jagged lines also
    Quote Quote  
  21. OK, good news, it is a bug , it should be fixed next release, so far the width has to be divisible by 64.. So for example widths, 640, 704, 768, .....1024, .....1280 those widths give good encodings.
    Quote Quote  
  22. Member stax76's Avatar
    Join Date
    Nov 2009
    Location
    On thin ice
    Search PM
    I'm not really understanding what is the problem here, there is another user with 'Error: fwrite() call failed when writing frame', might this be related?

    https://forum.doom9.org/showthread.php?p=1887946#post1887946
    Quote Quote  
  23. Originally Posted by zanzar View Post
    well i tried all that was suggested here , by miracle the bug in staxrip was fixed at the exact same day as this post lol , now it encodes x265 just fine.
    That is the quote from #13 input. OP stated that after upgrading staxrip (at that time) perhaps fixed that problem. Then discussion went different direction, how to encode within Vapoursynth script directly. Then there was a bug, which was fixed as well with latest releases. So that fwrite() error was not discussed in this thread at all.
    Quote Quote  



Similar Threads

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