Log in

View Full Version : Help: Using AviSynth to produce YUV


Darth Bovine
20th September 2010, 16:19
Hi All,

I've searched for this extensively (honest!) so if this is a common post please point me in the right direction coz I'm currently lost. :confused:

My problem is I've been using a helper app (found in my company, but I've no idea who wrote it) to output YUVs by passing it an avisynth script. It kinda works ok, but is very restrictive in what I can do with it. For example it will only output 422.

I've taken a look at other helper apps like Virtual Dub, but I've not been able to discover how to dump out the resultant YUV file....

Here's an example of my script (please excuse n00bie mistakes!):
y = AviSource("C:\streams\mystream_8bit.avi")
y = y.ConvertToYUY2(matrix = "rec709", interlaced = false)
y.Lanczos4Resize(1920,1088)

Basically all I want to do is produce a single file which contains a YUV of the frames in C:\streams\mystream_8bit.avi.

Thanks for any help,
DB.

Motenai Yoda
20th September 2010, 17:17
u would make an avi file by avisynth?
if i understand u should use virtualdub, open the avs script, set in video direct stream copy, and save as avi.
also matrix should be used to do an rgb<<->>yuv conversion not for yuv<->yuv
try to use ColorMatrix(clip, mode="Rec.601->Rec.709")

Darth Bovine
21st September 2010, 08:27
Thanks for the reply.

I have an *.avi file which I want to convert to a *.YUV using that script. It seems to work ok with the helper application I'm currently using but I need more flexibility.

-R.

pbristow
21st September 2010, 09:50
This sounds like the problem is with the helper app, rather than with AVIsynth. AVIsynth is not responsible for formatting output files: It's simply passing a video stream to your app. The stream it passes can take one of three forms (with the current version(s) of AVIsynth): RGB (with 8 bits per channel - either RGB24 or RGB32 (which has the extra Alpha channel)), YUY2, or YV12. More formats are being added in the newer versions that are under development, but for the moment those are your options.

You say you're able to get a 4:2:2 YUV file out OK. What else do you want to be able to do? If what you wanted was, say, a 4:4:4 YUV file, to preserve every last bit of chroma detail, than the closest you could get from the AVIsynth output would be RGB24, which your helper app would then have to convert to YUV form itself (preserving all the required detail, of course), but I'm guessing the whole point of using AviSynth in the first place was to handle the conversion from RGB (or whatever) to YUV, rather than codeing that into the helper app.

The other relevant question, of course, is what format is the data in the original file you're trying to convert? The filename says "8 bit", but is that 8-bit RGB, or 8-bit monochrome/greyscale, or what? If you post a sample from the source file, we'd be able to analyse it for you. (Keep it down to a couple of MB, ideally.)

What language is the helper app written in? Would you be able to find someone who understands the code who could work with you to improve the app?

Darth Bovine
21st September 2010, 11:34
Hi pbristow,

the original avi is in YUYV (or similar).

I've just discovered the helper on the net (I'd assumed it was written by someone in the company). It's avs2yuv.exe. I'll have a google at that and see if I can resolve my problems that way...

Ideally i'ld like to use something like VirtualDub to output the YUV... or is it even possible to get AviSynth to output files?

TiA,
DB.

Hagbard23
21st September 2010, 11:57
Yeah, then use Virtual Dub - you can choose: VIDEO->COMPRESSION->Uncompressed YCBCR. Afterwards check: VIDEO->FAST RECOMPRESS (if not, then YUY2 is converted to RGB and then to YUV again, which is senseless).

Thats it - after that hit FILE->Save as AVI.

You then have a YUV (YUY2) File inside your AVI Container.

Is it that, what you need?

Darth Bovine
21st September 2010, 13:25
Hi Hagbard23,

Partially.

I think I need pure YUV with no container. Is it easy to strip the container off?

Cheers,
DB.

Hagbard23
21st September 2010, 13:36
i think so, yes...

there should be several possibilities, but since i've never done that (YUV out of AVI) by myself i can not exactly tell. Try AVIDEMUX. Maybe someone else could give hints about that. I never had anything to do with raw YUV files, so even can't tell you the File-Suffix of YUV files... ;(

Please tell us, how the story goes on...

pbristow
21st September 2010, 13:51
Is this the one? - http://akuvian.org/src/avisynth/avs2yuv/

What this is doing is taking the data from an avisynth script and writing an AVI file, containing the YUV-encoded data.
Virtualdub can do the same, as Hagbard23 notes, and would also allow you to pick any other encoding scheme for which you have (or can acquire) suitable codecs.
When you talk about wanting to output a "*.YUV" file, is that just renamed *.AVi file, or some specific container format that I don't know about? To clarify that, consider where the file goes next after you've made it, and what information you have on what that next step of your process needs to see. Would it be happy to receive a normal AVI file (with .AVI suffix) containing the YUV data? Does it specifically need to see a file with a .YUV suffix? If it does, then what exactly does it expect to find inside the .YUV file - just a normal AVI file structure, or something else?

Also, what you still haven't clarified is, when you say the existing system is "very restrictive", what *else* do you want it to be able to do that it doesn't do already? Without knowing what the objective is, it's really hard to make any sensible recommendations.

Useful general rule (in all walks of life): More information about the problem => Better chance of finding a solution. :)

Darth Bovine
21st September 2010, 15:09
Hi

This is what I get when I run avs2yuv at command line

Usage avs2yuv <avsfile> <-(YUV format)> <outfile>
YUV format: yuv422p, yuv422i
Version 1.1 (compile time: Jul 21 2009, 15:19:53)

I really need to be able to produce 420 and 422.

The output I require is pure YUV planar with no header and no container. The next app in my chain will only take in YUV 422 or 420 planar and I need to test both (hence the need for 420 as well)...

So I might have to strip off the AVI container as previously suggested, but I'm not sure if AVIDEMUX will do that for me.

Maybe a silly question but is there a command in AviSynth that will dump the output to a file (such as I require)? Then it maybe wouldn't matter what the helper app was doing...

Cheers,
DB.

Hagbard23
21st September 2010, 17:31
Nope - i do not think so. AvS is a pure frameserver AFAIK. You have to go through a 3rd Application. And Virtual Dub is to my opinion one of the best of that sort....

Darth Bovine
21st September 2010, 20:58
ok, Kinda thought that but thought I'd ask anyhoo....

All I need now then is to find a h elper app that doesn't add the avi container...

Thanks for the help...

-DB

MatLz
22nd September 2010, 00:24
Sorry if I missed something, my english is so crappy...
Is this kind of files you want ? :
www.sendspace.com/file/rbeqf4
Infos : 20frames 320x180 at 24000/1001 fps

Darth Bovine
22nd September 2010, 10:01
Hi MatLz

Thanks for taking the time to reply and for uploading those files... unfortunately they look like they have headers (they won't open with my YUV viewer). As far as I know the YUV files are just pure pixel data

Regards,
R.

MatLz
22nd September 2010, 11:51
Argh....I was sure...

Elecard yuv viewer plays them. (exept the yuy2, as expected :D)

Dammit...

pandy
22nd September 2010, 14:46
ffmpeg

or export frames as pictures and binary join them to create .yuv file

Darth Bovine
22nd September 2010, 16:58
MatLz,

Sorry, they DO play in YUV player! I think I must have still been asleep when I tried it this morning! :o

What did you generate those with?

Cheers,
R.

MatLz
22nd September 2010, 17:30
:D

I used the ultimate secret weapon tool for that......(...).....media player classic !

There is an option :
File > utils > dsm converter
Put the script in the new window and streams will appear, right click to demux.(in fact the stream will be converted live)

But for the uyvy 4:2:2, as avisynth can't, I used virtualdub to produce this colorspace and after puted the avi in the dsm converter (this time, real 'demux')

Wilbert
22nd September 2010, 18:34
I really need to be able to produce 420 and 422.
You can use ImmaWrite for this. See examples in the documentation of Immaavs.

Darth Bovine
24th September 2010, 08:55
Thanks MatLz for that - i'll take a look at that.

Wilbert: Can ImmaWrite write a file directly from AviSynth? Can u post a link to the documentation?

Cheers,
R

Wilbert
24th September 2010, 17:07
Wilbert: Can ImmaWrite write a file directly from AviSynth?
Sort of. You have to render the file (play it in virtualdub, wmp, whatever). Perhaps not what you are looking for.


c = ColorBars().Trim(0,-1) # RGB32
ImmaWrite(c.ConvertToYUY2, "cb_raw", type="raw", planar=false)