Page 1 of 6 123 ... LastLast
Results 1 to 10 of 59

Thread: HOWTO: AviSynth video processing with WINE

  1. #1
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    HOWTO: AviSynth video processing with WINE

    ===============
    HOWTO: AviSynth video processing with WINE
    ===============


    This guide has been tested with Ubuntu 9.10, 10.04 and 10.10, and AviSynth 2.5.8 and 2.6.0 Alpha 2 (090927), but should work in any modern Linux distribution, with any 2.5+ version of AviSynth (and probably older ones too).

    Unless otherwise noted, all Windows-like paths (e.g. c:\windows\system32) in this guide refer to the corresponding locations in your WINE virtual drive (by default, ~/.wine/drive_c).

    This document is copyright 2009-2010 Firas Kraïem. It may be redistributed in any form, for any purpose, with or without modification, provided that this copyright notice appears in the distribution.


    AviSynth is a very powerful video processing tool for Windows. Since it uses Windows-only interfaces like VfW (Video for Windows), AviSynth scripts cannot be used directly as input for Linux video encoding tools. However, a solution exists: avs2yuv is an utility designed specifically for WINE, which takes an AviSynth script as input, and dumps its output as a yuv4mpeg stream to stdout or to a file, thus allowing further processing using any encoding tool that supports yuv4mpeg input.


    Usage

    In order to use it, the AviSynth DLLs (avisynth.dll and devil.dll) must be present in your WINE library path. Just running the AviSynth installer in WINE will do the trick. I also recommend copying avs2yuv.exe to c:\windows\system32 so you can run it by typing just wine avs2yuv, instead of its full access path.

    Finally, it is a good idea to have the latest x264 (see for example this guide about compiling it), since the build from the Karmic repositories is old and lacks some options that make our lives easier.

    The avs2yuv homepage shows some usage examples. Another handy one, using x264 for encoding, would be:

    Code:
    wine avs2yuv input.avs - | x264 --stdin y4m --output output.264 -
    The --stdin y4m parameter is important: it tells x264 that what it gets on stdin is a yuv4mpeg stream. By default, x264 expects raw YUV data, which is not what we have.

    If you kept the x264 version from the repos, you can use:

    Code:
    wine avs2yuv -raw input.avs - | x264 --fps 24000/1001 --output output.264 - 848x480
    Since the x264 version from the repos does not support y4m on standard input, you have to pass raw YUV data instead, which means that you also have to specify the framerate and resolution of your video stream.

    If you have a lot of similar encodings to do, you can use shell scripts to automate that, for example:

    Code:
    % cat encoding.sh
    #!/bin/sh
    #
    # Usage:
    #
    # encoding.sh [input] [pass] [bitrate] [output]
    #
    # input:   input .avs script
    # pass:    1 for first pass, 2 for second pass
    # bitrate: bitrate :D
    # output:  output file
    
    if [ $2 = 1 ]; then
        output=/dev/null
    else
        output=$4
    fi
    
    wine avs2yuv $1 - | x264 --preset slower --tune animation \
    --pass $2 --bitrate $3 --stats "$4.pass" --bframes 4 --ref 8 \
    --trellis 1 --colormatrix bt470bg --stdin y4m --output $output -
    
    % ./encoding.sh input.avs 1 1500 output.264
    [..]
    % ./encoding.sh input.avs 2 1500 output.264

    Bugs and caveats

    • FFT3DGPU does not work in WINE 1.2 but works in WINE 1.3 (remember to install Direct3D first, it's d3dx9 in winetricks).
    • VSFilter does not work correctly in WINE 1.0 (though hopefully no one uses it anymore). It works in WINE 1.2/1.3, but some fonts look very bad with it.
    • RemoveGrain's dynamically linked builds (RemoveGrain.dll, RemoveGrainSSE2.dll, RemoveGrainSSE3.dll, et al.) require the Microsoft Visual C++ 2005 runtime libraries (vcrun2005 in winetricks). The statically linked builds (RemoveGrainS.dll, et al.) do not.


    All other filters I've tested work out of the box. Of course, I can't test them all, so if you find one that doesn't, please report in this thread.
    Last edited by Bachstelze; June 6th, 2011 at 04:36 PM.
    「明後日の夕方には帰ってるからね。」


  2. #2
    Join Date
    Dec 2008
    Beans
    7

    Re: HOWTO: AviSynth video processing with WINE

    Hello,

    Thank you for this post, this is very usefull.

    I am curious about the impact on performance using avysinth in wine.

    Thank you,
    ymark

  3. #3
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: AviSynth video processing with WINE

    I still have to benchmark that, but it's surefine to not have to reboot in Windows when you need to encode something.

    My current experience is that it is at least not slower. Might be faster on 64 bit machines since it allows to use a 64 bit build of x264.
    Last edited by Bachstelze; November 21st, 2009 at 09:01 PM.
    「明後日の夕方には帰ってるからね。」


  4. #4
    Join Date
    Dec 2008
    Beans
    7

    Re: HOWTO: AviSynth video processing with WINE

    Hello


    Thanks for the quick reply.


    I've started to test this on a Ubuntu 9.04.
    I've installed wine, deployed avysinth 2.56 and avs2yuv.exe.


    I am trying to run the following command :

    Code:
    wine avs2yuv input.avs - | x264 --stdin y4m --output output.264 -
    and i get something like this :

    x264: unrecognized option '--stdin'
    ALSA lib ../../../src/seq/seq_hw.c:457snd_seq_hw_open) open /dev/snd/seq failed: No such file or directory
    Application tried to create a window, but no driver could be loaded.
    Make sure that your X server is running and that $DISPLAY is set correctly.
    errle:apartment_createwindowifneeded CreateWindow failed with error 0
    input.avs: 480x272, 500000/40833 fps, 1556 frames
    Output error: wrote only 185710 of 195840 bytes


    I guess the problem is from x264. It doesn't recognize the --stdin parameter.

    I've compiled the latest x264 too, but with no success.


    From the x264 help i see :


    Code:
    Infile can be raw YUV 4:2:0 (in which case resolution is required),
      or YUV4MPEG 4:2:0 (*.y4m),
      or AVI or Avisynth if compiled with AVIS support (no).
    Outfile type is selected by filename:
     .264 -> Raw bytestream
     .mkv -> Matroska
     .mp4 -> MP4 if compiled with GPAC support (yes)
    There is no --stdin parameter in the help menu


    Somebody have some sugestion?


    Thank you,
    ymark
    Last edited by ymark; November 22nd, 2009 at 12:48 AM.

  5. #5
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: AviSynth video processing with WINE

    You're probably using an old version of x264. The --stdin parameter does appear in the latest ones:

    http://mewiki.project357.com/wiki/X264_Settings#stdin

    EDIT: You said you compiled the latest x264. Did you also uninstall the version from the repos if you had it installed? What does this command output?

    Code:
    which x264
    Last edited by Bachstelze; November 22nd, 2009 at 10:29 AM.
    「明後日の夕方には帰ってるからね。」


  6. #6
    Join Date
    Dec 2008
    Beans
    7

    Re: HOWTO: AviSynth video processing with WINE

    Hello,

    You were right. That was an older version. I've not uninstalled the version from repositories.

    I removed the repo version and compiled again

    Now all works fine,

    Thank you

  7. #7
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: AviSynth video processing with WINE

    Guide updated with instructions to use the x264 build from the repos. As you can see, it's a tad more complicated, so I highly recomment compiling the latest x264.
    「明後日の夕方には帰ってるからね。」


  8. #8
    Join Date
    Dec 2005
    Location
    St. Petersburg, FL
    Beans
    529
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: HOWTO: AviSynth video processing with WINE

    If you use Sherpya's mplayer/mencoder Windows builds (regular, and ffmpeg-mt), you should be able to retain the framerate and resolution info.

    On a pure Ubuntu setup with Linux mplayer and Linux x264, this works:
    Now that that's done, we're all set. What's going to happen is that we'll make a named pipe using mkfifo, then have mplayer open the video, and pipe it over to x264.
    Code:
    mkfifo /path/to/input.y4m
    x264 /path/to/input.y4m <options> | mplayer -nosound -vo yuv4mpeg:file=/path/to/input.y4m /path/to/inputfile
    Obviously, /path/to/inputfile and whatnot represent the actual paths on your setup, usually /home/username/video.avi or /home/username/Documents/video.avi or whatever it really is. The same goes for that named pipe. <options> is obviously where your x264 options go.
    Taken from a tutorial I'd written for Intrepid, but should still be valid. I have confirmed that Sherpya's build of mplayer r29851 can play AviSynth scripts, and the mencoder builds do as well (I use the mencoder builds a lot, so that was a given, but I don't use mplayer to test my scripts so I had to check). So hopefully, it is possible to pipe from Windows mplayer to Linux x264 and keep the resolution and framerate intact so you don't have to specify it. It seems to rest in whether Windows mplayer can correctly dump to mkfifo's output.

    Special note: Using && to run the mkfifo and the x264 | mplayer commands in one incurs a performance hit that running mkfifo first, and then the other does not.
    Last edited by qyot27; December 5th, 2009 at 09:08 AM.

  9. #9
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: AviSynth video processing with WINE

    I've found mplayer to be unreliable sometimes. For example when given a lossless x264 stream as input, the output was not frame-accurate (my subtitles were off-by-one).
    「明後日の夕方には帰ってるからね。」


  10. #10
    Join Date
    Dec 2005
    Location
    St. Petersburg, FL
    Beans
    529
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: HOWTO: AviSynth video processing with WINE

    Quote Originally Posted by Bachstelze View Post
    I've found mplayer to be unreliable sometimes. For example when given a lossless x264 stream as input, the output was not frame-accurate (my subtitles were off-by-one).
    Couldn't that be a problem with libass, though? If it is, then taking the decision out of its hands by using TextSub() would resolve it. The problem with that encode could have been if the H.264 stream had certain frame types, though (does mplayer have a known problem with B-frames/B-pyramid/mixed refs?) - with AviSynth this would be null and void.

    I can't seem to get ffmpeg to pipe correctly here, but if mplayer really is the culprit and not libass, maybe ffmpeg would be unaffected? I have to rebuild ffmpeg with --enable-avisynth first, though.

Page 1 of 6 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •