PDA

View Full Version : Encoding YUY2


paulom
27th October 2009, 21:48
I'm using Avisynth to trim, splice and add subtitles to video files recorded with a still camera. Their colorspace is YUY2, and I don't want to make any color conversions. I'm using Microsoft Expression Encoder 3, but I see no way of preventing it to output YV12.
Does anyone know an encoder that can take YUY2 as input and just compress it, outputting YUY2?

canuckerfan
27th October 2009, 21:55
what type of codec you looking for? mpeg2? h.264? xvid? in the case of mpeg2, there's CCE.

Blue_MiSfit
27th October 2009, 23:24
No.

You're confused :)

YUY2 is an uncompressed video format with 4:2:2 chroma subsampling. Your camera records video in 4:2:2 (mjpg I'd guess?), and decodes to YUY2 on your PC.

You don't need 4:2:2 encoded files, unless this is part of some larger workflow. There's no benefit to greater than 4:2:0 when it comes to final delivery encoding, it's only useful for acquisition and filtering / compositing etc...

You need to tell us more about what you're doing in order for us to make an educated workflow suggestion. It sounds like you want to produce VC1 streams, since you're using Expression Encoder 3 - right? Silverlight streaming? BluRay? Something more sinister? :devil:

~MiSfit

paulom
28th October 2009, 18:49
I'll try to explain it better. Please tell me if I have mistaken something.

Gspot and VirtualDub say the files recorded by my camera are mpeg-1, I-frames only. I've found no other way of telling the color format than with Avisynth. I open a file with DirectShowSource() and Info() says the color space is YUY2.

I want to save video files to be viewed on my PC. If I had infinite resources and power, saving as uncompressed AVI would be just great (maybe within some years...). As this is not possible, the video stream must be compressed.

Which codec I use is not really important. I was using the VCM version of Windows Media Video 9 (with VirtualDub) untill Ben Waggoner, replying one of my posts, told me to use Expression Encoder 3. He said it was newer, better, faster, and supported Avisynth. Well, for me they seem just the same, both output YV12.

Why not YV12? Let me quote http://avisynth.org/mediawiki/FAQ_YV12:
Are there any disadvantages of processing in YV12?
There is a degradation of color information in YV12, which is often acceptable, but not for high quality processing and interlaced material, where it is better to use YUY2 which is less subsampled.
If source format is not YV12 (analog capture, DV) or final encoding format is not YV12, then color format conversion will results in chroma interpolation with some quality decreasing.
So, I just need to compress the video without degrading it more than necessary. Sure I don't need a lossless codec, but I would like to escape from chroma interpolation.

Hope I have made it more clear, and maybe you can help me.:)

Blue_MiSfit
28th October 2009, 18:51
What's wrong with keeping the MPEG-1 files as-is? If you're just watching on the PC I see no reason to transcode.

~MiSfit

Didée
28th October 2009, 19:15
To start with, Mpeg-1 uses YV12 colorspace (yaya, Y'CbCr with 4:2:0 sampling). Mpeg-1 can not use YUY2 at all. The reason you "see" (or seem) to get YUY2 is because the decoder converts the decompressed YV12 signal to YUY2 before spitting it out. That's just a matter of the decoder and/or its setup.

Therefore, the information/detail that you want to preserve is not present at all. The "degradation" you want to avoid is, in fact, already in the source. End of story.

Blue_MiSfit
28th October 2009, 20:56
Nice :) I had neglected to realize that MPEG-1 only supported 4:2:0. Something seemed a little fishy :)

So, if you've got MPEG-1, it has to be progressive YV12. Therefore, you can safely transcode it to any format you see fit without worrying about losing color information - provided you use a reasonable bitrate and appropriate settings!

I'd say leave it as-is.

~MiSfit

paulom
29th October 2009, 12:44
The reason for not just leaving them as they are is that I'm using Avisynth to edit them. I must save the output somehow.

What you are saying is that in Avisynth, DirectShowSource("MyVideo.mpg") automatically converts colorspace to YUY2, right?

Then, I thought, if I use DirectShowSource("MyVideo.mpg", pixel_type="YV12") I should get the right thing... No, I've got a VirtualDub error "File does not have a video stream". I've also tried pixel_type="AUTO". The result is again YUY2.

Looks like I still need some help...:confused:

HymnToLife
29th October 2009, 13:12
Just to be sure, could you open one of your files in Mediainfo (http://mediainfo.sf.net) and paste the text report (View > Text)?

paulom
29th October 2009, 14:42
Just to be sure, could you open one of your files in Mediainfo (http://mediainfo.sf.net) and paste the text report (View > Text)?Here is it:

General
Complete name : D:\Video\MOV03401.MPG
Format : MPEG-PS
File size : 18.4 MiB
Duration : 14s 700ms
Overall bit rate : 10.5 Mbps

Video
ID : 224 (0xE0)
Format : MPEG Video
Format version : Version 1
Format settings, Matrix : Default
Duration : 14s 700ms
Bit rate mode : Variable
Bit rate : 9 994 Kbps
Width : 640 pixels
Height : 480 pixels
Display aspect ratio : 4:3
Frame rate : 30.000 fps
Scan type : Progressive
Bits/(Pixel*Frame) : 1.084
Stream size : 17.5 MiB (95%)

Audio
ID : 192 (0xC0)
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 2
Duration : 14s 400ms
Bit rate mode : Constant
Bit rate : 64.0 Kbps
Channel(s) : 1 channel
Sampling rate : 32.0 KHz
Resolution : 16 bits
Stream size : 113 KiB (1%)

HymnToLife
29th October 2009, 15:06
Well, as Didée said, MPEG-1 is always YV12. I guess you can just use DGIndex/MPEG2Source() instead, which will keep the YV12 (yes, it works for MPEG-1 too).

paulom
29th October 2009, 19:06
Yes, it worked with DGIndex/MPEG2Source. But it's a quite awkward task if you have tens of mpeg-1 files. I have to decide if it's worth doing that and avoiding the YV12 > YUY2 > YV12 conversions. I would like to know your opinion, please.

By the way, look at what I have found in thread Doom9's Forum > Capturing and Editing Video > Avisynth Development > DirectShowSource.dll CVS Pre-Release:
Known problem:

YV12 pixel format is very difficult to get. DirectX seems hell bent :devil: on returning YUY2 as a priority. Only codecs that can be configured to return YV12 exclusively seem to to have a chance of returning YV12 data, but even then the Graph builder may throw in a YUY2 decoder for good measure. Manually build a graph (.grf file) with GraphEdit if this is a problem. ;)

Blue_MiSfit
29th October 2009, 19:15
If you use ffdshow to decode the MPEG-1, you should be able to configure it to return YV12.

~MiSfit

hanfrunz
30th October 2009, 10:07
if you just want to cut your mpeg1 material into parts try tools like womble mpeg video wizard (http://www.womble.com/). It can edit mpeg files without reencoding (stream copy).

Alex_ander
30th October 2009, 11:30
I thought, if I use DirectShowSource("MyVideo.mpg", pixel_type="YV12") I should get the right thing...
In your case it's not AviSynth' DirectShowSource that turns YV12 into YUY2, it's Direct Show filter installed on the system. That filter is used (with its internal decoder settings) by DirectShowSource, so you can't modify its output in DirectShowSource parameteres (those could only help in case the detected color space didn't match the actual type coming from that filter). That's why it didn't work for you. It is only possible to configure that filter itself if you find out which of the installed ones is used by default.

P.S. However, if you anyway want to re-encode the videos after adding subtitles - some encoders like CCE or Canopus (I don't know how Expression Encoder does it) internally start encoding from YUY2 space and many users intentionally convert YV12 to YUY2 in the end of the script for that reason. So if you don't have visual problems, maybe it's possible (if not better) to leave it as is.

davidhorman
30th October 2009, 12:40
if you just want to cut your mpeg1 material into parts try tools like womble mpeg video wizard (http://www.womble.com/). It can edit mpeg files without reencoding (stream copy).

Except for a few frames around the cuts, where GOPs will be broken. It's doubtful anyone would notice, though.

David

paulom
30th October 2009, 14:17
In fact, I'm doing more than just trimming and splicing. I'm also playing with subtitles, transitions, and some correction filters. I have to reencode.

I would like to try the ffdshow solution. I have installed it, but Gspot says that DirectShow keeps using quartz.dll to decode video.

Blue_MiSfit, could you please give some quick instructions on how to make DirectShow use ffdshow?
Or maybe there's another way of using ffdshow to open a video in Avisynth?

Thank you all for helping.:)

rkalwaitis
30th October 2009, 16:31
Which one of the correction filters are you using? If they are temporalsoften or spatialsoften from avisynth, then you are right, you need to be in YUY2 for them to operate properly. But Its not avisynth that wants them to be in YV12, its your film player or encoder.

Gavino
30th October 2009, 16:43
If they are temporalsoften or spatialsoften from avisynth, then you are right, you need to be in YUY2 for them to operate properly.
Only SpatialSoften requires YUY2. TemporalSoften works on both YUY2 and YV12 (and also RGB32).

paulom
30th October 2009, 17:52
Which one of the correction filters are you using? If they are temporalsoften or spatialsoften from avisynth, then you are right, you need to be in YUY2 for them to operate properly. But Its not avisynth that wants them to be in YV12, its your film player or encoder.
The filters accept YV12 or YUY2 as well, I believe.

Sorry, instead of "I have to reencode" I should have said "I have to use Avisynth".
A tool like hanfrunz mentioned above is of no use.

rkalwaitis
30th October 2009, 18:16
Thanks Gavino I thought it was both functions.

paulom
31st October 2009, 02:22
I wrote:
I would like to try the ffdshow solution. I have installed it, but Gspot says that DirectShow keeps using quartz.dll to decode video.
I had downloaded the original ffdshow. Later I read about ffdshow-tryouts, installed it in another machine, and... IT WORKS!!!

DirectShow is using ffdshow to decode my mpeg-1 files! Colorspace is YV12! :p

All I have to do is use WMV9, Expression, or whatever codec to encode YV12 as YV12. No color conversions! :):):)

Blue_MiSfit
31st October 2009, 17:30
And there you go :)

I simply must suggest you use x264 to encode your final video :devil: - it's an amazing codec!

Expression is a wonderful piece of software though, don't get me wrong!

~MiSfit