View Single Post
Old 5th January 2014, 01:24   #1  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
JpegSource – advanced JPEG decoder for Avisynth 2.6

As someone asked for JPEG decoder that does no colorspace conversions and provide YUV data directly, and I've written exactly such thing for some other project – here it is, JpegSource for Avisynth.

Current (2014.4.19) version: https://www.dropbox.com/s/rjnt0y3ead...ce_20140419.7z
Previous (2014.1.5) version: https://www.dropbox.com/s/qvm4kn27b4f7bb9/JpegSource.7z

Due to various chroma subsamplings of JPEG it's Avisynth 2.6 only plugin. And even current Avisynth 2.6 doesn't support all colorspaces that you can encounter in JPEG, like YUV440 and CMYK/YCCK, so to process them you'd have to use single-channel mode. To comply with other Avisynth restrictions multi-channel mode may also "un-crop" images a bit (to provide even width to YV16 etc.), while single-channel mode always returns exact dimensions.

Syntax: JpegSource(string file, int rec, int channel, int length, float fps_num, int fps_den)
  • file – source file name
  • rec – number of reconstruction passes. Default: 1.
  • channel – load only one image channel with specified index (zero based). Default: -1 (load all channels).
  • length – clip length in frames. Default: 1000.
  • fps_num and fps_den – fps numerator and denominator. Default: 24 and 1.
MTMode to use: 1. (3 and 5 are ok too; don't use 2 or 4.)

Beside simply decoding JPEG files it can try to "reconstruct" the data. Shouldn't hurt any image. On high-quality JPEGs change is insignificant, on strongly compressed can produce quite impressive results, but won't help on recompressed files where artifacts were produced by previous compressions. Reconstruction requires SSSE3 capable CPU. For example try on this file.

Can also decode PJG-compressed JPEG files and JPEG files with arithmetic compression.

Remember that JPEGs use PC levels, Rec.601 colorspace and MPEG1 chroma position most of the time. Sadly, there is no way now for source filter to provide such information and you'd have to set correct parameters manually when converting to other colorspaces. (Actually, there is something about chroma position, but it doesn't work.)

License: free for non-commercial use, closed source. (Ad-infested software is not "non-commercial".)


Usage Notes

RGB JPEGs are decoded as YV24 etc. To get proper RGB combine them by
Code:
MergeRGB(last, UToY8(), VToY8(), "RGB24").
To correctly upsample MPEG1 chroma (most JPEGs) use
Code:
YToUV(UToY8().Spline36Resize(last.width, last.height), VToY8().Spline36Resize(last.width, last.height), last)

Last edited by SEt; 19th April 2014 at 10:03.
SEt is offline   Reply With Quote