View Full Version : image reader for VapourSynth
Chikuzen
14th October 2012, 01:00
New plugins for VapourSynth r19 or later.
vsimagereader-0.2.1.zip (http://www.mediafire.com/download/690b0y2ixvorq5c/vsimagereader-0.2.1.zip)
source code
https://github.com/chikuzen/vsimagereader
helper module to read image sequense
#vsimghelper.py
import os
import vapoursynth as vs
class ImageReader(object):
def __init__(self, path):
self.core = vs.get_core()
try:
hasattr(core, 'imgr')
except:
self.core.std.LoadPlugin(path)
def read(self, dir, ext, fpsnum=24, fpsden=1):
srcs = [dir + '/' + src for src in os.listdir(dir) if src.endswith(ext)]
return self.core.imgr.Read(srcs, fpsnum, fpsden)
put this script into Python3.x/Lib/site-packages as vsimghelper.py
usage:
>>> import vapoursynth as vs
>>> import vsimghelper as ih
>>> imgr = ih.ImageReader('/path/to/the/vsimagereader.dll')
>>> clip = imgr.read('/path/to/the/image/directory', ext='jpeg')
EDIT:
2013/07/31
Release vsimagereader-0.2.1
Reel.Deel
14th October 2012, 13:39
Hi Chikuzen, thanks again for another VS plugin. :)
I know if the width is not mod4, padding will be added, but what color is the padding supposed to be? I assume is black. The reason I ask is because I see both green and black padding.
Also, here's the source (http://www.mediafire.com/?imqg3l492uff94u) just in case if you want to try to reproduce the results below.
* Edit *
Updated to vsjpgreader 0.1.1
import vapoursynth as vs
core = vs.Core()
core.std.LoadPlugin(path=r'C:\vsjpgreader.dll')
src = core.jpgr.Read(['C:\test.jpg'])
# Only used to test YUV440P8 input since VFW/VSFS in not able to output that colorspace.
#src = core.resize.Bicubic(clip=src, format=vs.YUV422P8)
last = src
Here are the results of different image sizes.
Tested through VFW and VSFS using VapourSynth r13 and vsjpgreader 0.1.1.
Gimp 2.8 was used for jpg compression.
1) width=597 height=398
4:2:0 Works correctly. Gets padded to 600x398.
4:2:2 YUV440P8. Works correctly. Gets padded to 600x398.
4:2:2 YUV422P8. Works correctly. Gets padded to 600x398.
4:4:4 Works correctly. Gets padded to 600x398.
2) width=598 height=399.
4:2:0 Works Correctly. Gets padded to 600x400.
4:2:2 YUV440P8. works correctly. Gets padded to 600x400.
4:2:2 YUV422P8. works correctly. Gets padded to 600x399.
4:4:4 Works correctly. Gets padded to 600x399.
3) width=599 height=399
4:2:0 Works Correctly. Gets padded to 600x400.
4:2:2 YUV440P8. Works correctly. Gets padded to 600x400.
4:2:2 YUV422P8. Works correctly. Gets padded to 600x399.
4:4:4 Works Correctly. Gets padded to 600x399.
4) width=600 height=400
All input colorspaces work correctly.
5) width=602 height=401
4:2:0 Green diagonal lines appear. Gets padded to 604x402.
4:2:2 YUV440P8. Works correctly. Gets padded to 604x402.
4:2:2 YUV422P8. Green diagonal lines appear. Gets padded to 604x401.
4:4:4 Works correctly. Gets padded to 604x401.
6) width=602 height=402
4:2:0 Green diagonal lines appear. Gets padded to 604x402.
4:2:2 YUV440P8. Works correctly. Gets padded to 604x402.
4:2:2 YUV422P8. Green diagonal lines appear. Gets padded to 604x402.
4:4:4 Works correctly. Gets padded to 604x402.
Chikuzen
14th October 2012, 15:20
@Reel.Deel
Thanks for the report :)
I fixed odd height issue, and updated to 0.1.1.
About the color of padding, it is based on the jpeg decode library which is used by this plugin.
It seems that the library do padding by zero.
so, this is normal behavior.
Reel.Deel
15th October 2012, 22:51
I updated my post above to vsjpgreader 0.1.1. While that solved some of the issues, there's still one remaining.
The diagonal lines only appear on image 5 & 6, only on the 4:2:0 and 4:2:2(YUV422P8) colorspace.
http://imageshack.us/a/img23/7823/diagonal.png (http://imageshack.us/photo/my-images/23/diagonal.png/)
Chikuzen
16th October 2012, 04:05
@Reel.Deel
Updated to 0.1.2.
Please try again.
Reel.Deel
16th October 2012, 04:32
I still have the same problem, except the image is now very distorted (http://imageshack.us/photo/my-images/571/test2ke.png/).
Chikuzen
16th October 2012, 04:48
sorry, I found a typo in code.
updated to 0.1.2-2
Reel.Deel
16th October 2012, 04:55
hmm, that also did not fix it. Wish I could help you find the problem but I don't know anything about programming. :(
Chikuzen
16th October 2012, 05:30
hmm, that also did not fix it. Wish I could help you find the problem but I don't know anything about programming. :(
With which sample does your problem occur?
I tested all your 24 samples again. But seems no problem.
kolak
16th October 2012, 11:52
I updated my post above to vsjpgreader 0.1.1. While that solved some of the issues, there's still one remaining.
The diagonal lines only appear on image 5 & 6, only on the 4:2:0 and 4:2:2(YUV422P8) colorspace.
http://imageshack.us/a/img23/7823/diagonal.png (http://imageshack.us/photo/my-images/23/diagonal.png/)
Are you using latest vapoursynth?
Reel.Deel
16th October 2012, 12:42
With which sample does your problem occur?
I tested all your 24 samples again. But seems no problem.
You're correct Chikuzen, your last update fixed remaining problems with VFW. I have been testing with both VFW and VSFS, but the last time I was lazy and only tested with VSFS. That's the problem. The issue is now only with VSFS.
Here's the problematic samples (http://www.mediafire.com/?u9e33mpcdcajfjf), If someone else wants to reproduce the distorted (http://imageshack.us/photo/my-images/571/test2ke.png/) image through VSFS.
___________
@Kolak
Yes, I'm using r13.
Myrsloik
16th October 2012, 16:49
You're correct Chikuzen, your last update fixed remaining problems with VFW. I have been testing with both VFW and VSFS, but the last time I was lazy and only tested with VSFS. That's the problem. The issue is now only with VSFS.
Here's the problematic samples (http://www.mediafire.com/?u9e33mpcdcajfjf), If someone else wants to reproduce the distorted (http://imageshack.us/photo/my-images/571/test2ke.png/) image through VSFS.
Interesting... which format do you use for the output? I'll take a look at it later and see if I can figure out why it happens.
Reel.Deel
16th October 2012, 17:25
Interesting... which format do you use for the output?
Depending on the jpg colorspace, I used YUV420P8 and YUV422P8 for output.
IanB
16th October 2012, 22:57
@Myrsloik,
You may not have a bug here per se', there is some confusion in the world about the line packing of planar YUV formats.
Dib derived formats like RGB24, RGB32 and Y800 (Y8, GREY) always have lines that are 32 bit DWORD aligned. There seems to be universal conformance for this.
However planar YUV formats are apparently supposed to be packed with the line pitch equal to the rowsize. Some documentation is quite vague on this point. Avery Lee has convinced me it is true and VirtualDub implements this. However a sizeable chunk of the world assume planar lines are 32 bit DWORD aligned.
I abandoned the moral high ground in favour of a functional user solution. On input I check the returned full frame size to see if it matches a 32 bit DWORD aligned size and crib the spec accordingly. On output there is the "OPT_AVIPadScanlines" option to force 32 bit DWORD aligned output through the AVIFile interface.
Chikuzen
22nd October 2012, 11:02
I wrote vsbmpreader, and added it to the first post.
Myrsloik
22nd October 2012, 11:03
Maybe you should merge them or use a library to make a complete image reader? That'd be really good to have
Chikuzen
22nd October 2012, 12:11
Maybe you should merge them or use a library to make a complete image reader? That'd be really good to have
I will think after writing png and tga about it.
Chikuzen
23rd October 2012, 07:29
added vspngreader to the first post.
Reel.Deel
23rd October 2012, 14:04
@Chikuzen
I was wondering if the 8bit limitation is due to libpng? If not, I think it would be great if it was compatible with 16bit png's.
Thanks again for another plugin, will test when I have some free time. ;)
@Myrsloik
Any update of the problem above (http://forum.doom9.org/showthread.php?p=1596114#post1596114)?
Chikuzen
23rd October 2012, 14:41
@Chikuzen
I was wondering if the 8bit limitation is due to libpng?
no
If not, I think it would be great if it was compatible with 16bit png's.
then, I'm great :p
Reel.Deel
24th October 2012, 02:57
then, I'm great :p
Chikuzen The Great, indeed you are. :D
I read the readme and it did not mention anything about 16bit png's so I assumed that it was not supported.:o
Just now tried it with a couple of 5184x3456 16bit png's and they all work. Keep up the excellent work Chikuzen.
Chikuzen
24th October 2012, 04:11
Chikuzen The Great, indeed you are. :D
I read the readme and it did not mention anything about 16bit png's so I assumed that it was not supported.:o
Just now tried it with a couple of 5184x3456 16bit png's and they all work. Keep up the excellent work Chikuzen.
libpng itself is supporting 16bits samples completely from ancient times.
However, many softwares which using libpng are applying a limitation to it to convert 16bits to 8bits.
I did not apply any limitation to libpng except stripping off alpha.
That is the reason why there is no mention about 16bits.
Myrsloik
28th October 2012, 21:48
The bug has been located. It was actually some of the padding code from avfs I forgot to adjust so it became mismatched. The samples will work in r14. I also kinda secretly added a pad_scanlines option if you encounter one of those broken programs too.
Chikuzen
29th October 2012, 14:58
added vstgareader to the first post.
Chikuzen
1st November 2012, 11:48
Release vsimagereader-0.1.0
This is merged version of old four(BMP, JPEG, PNG and TGA) plugins.
Chirico
2nd November 2012, 13:23
For other possible OS X users, I've compiled this since the configure script will only build for Windows or Linux. You can grab it here (http://www.sendspace.com/file/m3en17). Obviously, you will also need the prerequisite image libraries installed to go along with this.
sneaker_ger
17th November 2012, 12:14
Is there any Windows 32 compile that works with VS r15?
Chikuzen
17th November 2012, 12:29
Is there any Windows 32 compile that works with VS r15?
v0.1.0 works with r15.
I will update to v0.2.0 with alpha support.
ignore warning and wait release ;)
sneaker_ger
17th November 2012, 12:35
I stopped reading after the "deprecated" warning.
Not my day...
sneaker_ger
17th November 2012, 12:45
So, how do I load an image sequence?
I guess I must somehow code the equivalent of e.g. "%08d.png" (ffmpeg notation) to Python myself?
/edit:
oh, your git has the doc on that.
Man, not my day, indeed.
Chikuzen
17th November 2012, 13:20
oh, your git has the doc on that.
Man, not my day, indeed.
Did I forget to put readme into 7z :confused:
sneaker_ger
17th November 2012, 13:27
No, you didn't. As I said: I got up on the wrong side today. Your filter is working great.
Chikuzen
17th November 2012, 13:31
I added helper module(Python script) to the first post.
That will be help you.
sneaker_ger
17th November 2012, 13:36
I already got it working, but that will make it easier in the future anyways. Thank you.
Chikuzen
11th January 2013, 17:56
updated to 0.2.0
* add new option 'alpha'
* support reading alpha channel
* support reading not constant width/height/format image files
Chikuzen
31st July 2013, 10:14
update to 0.2.1
*fix memory leak when 'alpha' is True.
*cope with the filename which includes non-ASCII characters
*update libpng to 1.6.2
kolak
11th October 2013, 22:15
DPX support?
Myrsloik
2nd December 2013, 16:58
Compiles that fix the crash bug in filter creation are available for 32 (https://dl.dropboxusercontent.com/u/73468194/vsimagereader-32.7z) and 64 (https://dl.dropboxusercontent.com/u/73468194/vsimagereader-64.7z) bit.
The fixed source is available as a fork on github (https://github.com/myrsloik/vsimagereader).
nu774
18th December 2013, 06:42
The following simple script fails here with a message "No frame returned at the end of process", followed by crash.
import vapoursynth as vs
from urllib.request import urlopen
logo = 'http://upload.wikimedia.org/wikipedia/commons/9/93/Solid_color_You_Tube_logo.png'
with urlopen(logo) as req:
with open('youtube_logo.png','wb') as fp:
fp.write(req.read())
vs.get_core().imgr.Read('youtube_logo.png').get_frame(0)
I'm not very familiar with vapoursynth, but as far as I can see, this is because vsimagereader is storing pointers retrieved from vsMap and reusing them later, at which point these pointers are no more valid.
The following fix seems to work for me:
diff --git a/src/imagereader.c b/src/imagereader.c
index e692bb4..8474f47 100644
--- a/src/imagereader.c
+++ b/src/imagereader.c
@@ -108,7 +108,11 @@ close_handler(void *instance_data, VSCore *core, const VSAPI *vsapi)
fprintf(stderr, tjGetErrorStr());
}
ih->tjhandle = NULL;
+
if (ih->src) {
+ int i;
+ for (i = 0; i < ih->vi[0].numFrames; ++i)
+ free(ih->src[i].name);
free(ih->src);
ih->src = NULL;
}
@@ -257,9 +261,11 @@ create_reader(const VSMap *in, VSMap *out, void *user_data, VSCore *core,
vs_args_t va = {in, out, core, vsapi, 0, 0, 0, 0, 0};
for (int i = 0; i < num_srcs; i++) {
- ih->src[i].name = vsapi->propGetData(in, "files", i, &err);
- RET_IF_ERR(err || strlen(ih->src[i].name) == 0,
+ const char *name = vsapi->propGetData(in, "files", i, &err);
+ RET_IF_ERR(err || strlen(name) == 0,
"zero length file name was found");
+ ih->src[i].name = malloc(strlen(name) + 1);
+ strcpy(ih->src[i].name, name);
const char *cs = check_src_props(ih, i, &va);
RET_IF_ERR(cs, "file %d: %s", i, cs);
}
Myrsloik
18th December 2013, 12:51
The following simple script fails here with a message "No frame returned at the end of process", followed by crash.
You're right, I guess there was more than one bug lurking in the code. Your fix looks correct so I'll probably apply it and make new compiles tomorrow.
Pichu
19th June 2014, 23:58
Hello! When will be available the fixed vsimagereader plugin for Vapoursynth r23 x64? I mean, I am trying to use the vsimagereader x64 plugin (for a PNG sequence) and I get this (like in the previous post):
a message "No frame returned at the end of process", followed by crash.
And the old vsimagereader 0.2.1 plugin works fine on Vapoursynth r19, but it is only 32 bit, not 64 bit.
Daemon404
28th June 2014, 20:12
Hello! When will be available the fixed vsimagereader plugin for Vapoursynth r23 x64?
Unfortunately, Chikuzen seems to have vanished a while ago. You can maybe pray Myrsloik forks it, or, and this is probably the better idea, hope someone writes a proper ImageMagick-based reader (maybe I will, but likely I'm lazy).
alexxdls
1st August 2014, 18:38
I need to encode a siquense of 16 bit/channel png files. Here is a sample of single one:
http://i66.fastpic.ru/big/2014/0801/d3/_9ada951654a9e224662df391d0eee6d3.png?noht=1
myVapourScript.vpy
import vapoursynth as vs
core = vs.get_core()
import os
ext = '.png'
dir = r'd:\TRAILERS\DCP\MOCKINGJAY-PT1_TLR-1_S_RU-XX_RU_51_2K_LION_20140729_DLA_IOP_OV\PNG/'
srcs = [dir + src for src in os.listdir(dir) if src.endswith(ext)]
v = core.imgr.Read(srcs,24,1)
v = core.fmtc.matrix(v, mat="709", col_fam=vs.YUV, bits=16, fulls=1, fulld=1)
v = core.fmtc.bitdepth(v, bits=10, dmode=1)
v.set_output()
I run the following command
d:\TRAILERS\DCP\MOCKINGJAY-PT1_TLR-1_S_RU-XX_RU_51_2K_LION_20140729_DLA_IOP_OV>"
c:\Program Files (x86)\VapourSynth\core32\vspipe.exe" "myVapourScript.vpy" - -y4
m | x264 - --demuxer y4m --input-depth 10 --output-csp i444 -o out.264and get the error
NULL name pointer passed to createFilter()vsimagereader.dll is in c:\Program Files (x86)\VapourSynth\plugins32\
What is wrong?
Myrsloik
1st August 2014, 19:14
What is wrong?
Use the fixed version in this post (http://forum.doom9.org/showpost.php?p=1656353&postcount=39).
alexxdls
1st August 2014, 19:26
Thanks
sneaker_ger
2nd August 2014, 15:23
Currently checking out VS 24 and Myrsloik's fixed build but it crashes for me (opening PNG files) plus shows the following error "No frame returned at the end of processing by Read" (vspipe). If trying to open in VirtualDub I get an exception in MSVCR120.
Myrsloik
2nd August 2014, 16:11
Currently checking out VS 24 and Myrsloik's fixed build but it crashes for me (opening PNG files) plus shows the following error "No frame returned at the end of processing by Read" (vspipe). If trying to open in VirtualDub I get an exception in MSVCR120.
It's probably one of the many issues in it. I do plan to make a simple image reader to replace it and if I'm not too busy the first version will be ready by the end of next week. This plugin is unmaintained and will be replaced.
alexxdls
7th August 2014, 04:28
Currently checking out VS 24 and Myrsloik's fixed build but it crashes for me (opening PNG files) plus shows the following error "No frame returned at the end of processing by Read" (vspipe). If trying to open in VirtualDub I get an exception in MSVCR120.I have the same shit. Waiting for a fixes...
sneaker_ger
7th August 2014, 09:39
If it's really unmaintained - as Myrsloik put it - you'd be in for a long wait. Try that instead:
http://forum.doom9.org/showthread.php?t=170981
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.