Log in

View Full Version : ImageWriter unclarity about JPG parameters


TCmullet
10th November 2020, 20:31
I see Avisynth DOES have the ability to copy frames to image files! But the docs are rather incomplete.

1. When I do type="JPG", there is no info or examples on how to set the compression quality. It can be anywhere from 1 to 100. After experimenting, I've decided I'd like to do all of mine to 50 percent. How can I specify that?

2. Also, should I be concerned about color space issues? The video (via the script) will be read by Virtualdub. Previously, I was using the Vdub "copy source frame to clipboard", then paste into IrFanView, then saving to JPG. What joy is mine to know I can skip a lot of that tedium! But when I request IrFanView to "Save as", it has a slew of option which I leave alone except for "quality". Mediainfo tells me that the JPGs I've stored previously are "YUV". Assuming it would be wise to store the images from ImageWriter in the same color space as my prior pictures, how do i specify that it write it out as "YUV"?

Groucho2004
10th November 2020, 20:42
Just use RGB:

ConvertToRGB()
ImageWriter(file = "F:\Test\pic-", start = 0, type = "jpg", info = true)

TCmullet
10th November 2020, 21:55
I'm confused in 2 ways. I think I prefer to use YUV as 1, My other files are YUV, and 2, I think I've heard that YUV will take less space than RGB.

But regardless of that, you didn't tell me how to specify the quality setting of 50 that I want. If there is a default quality parameter, it ought to be documented somewhere.

Groucho2004
10th November 2020, 21:59
Maybe you should look at the documentation:
http://avisynth.nl/index.php/ImageWriter

TCmullet
10th November 2020, 22:08
Groucho, I told you at the beginning that I had read them, they were inadequate (there's no reference to the JPG quality setting, at least that I can find and I read it rather thoroughly I think), so therefore I started this thread. If I missed it, please point it out to me. But I DID read it all BEFORE starting this thread.

Groucho2004
10th November 2020, 22:18
Groucho, I told you at the beginning that I had read themNo, you did not. I read your first post twice, there's nothing about reading documentation on avisynth.nl. All I can see is "But the docs are rather incomplete." What docs?

Anyway, when you write a jpg, the color space options are YCbCr, RGB, CMYK, Grayscale and YCbCrK as far as I know.

TCmullet
10th November 2020, 22:38
What docs are incomplete? Docs is short for documentation, and if I said the documentation is incomplete, that implies that I read it.

(I was a computer programmer for a couple decades after college, so I know the importance of "reading the manual first" before asking for help.)

I still respectfully hope that you or someone will tell me how to set something like "quality=50".

Groucho2004
10th November 2020, 22:43
What docs are incomplete? Docs is short for documentation, and if I said the documentation is incomplete, that implies that I read it.

(I was a computer programmer for a couple decades after college, so I know the importance of "reading the manual first" before asking for help.)

I still respectfully hope that you or someone will tell me how to set something like "quality=50".

What docs are incomplete? Docs is short for documentation, and if I said the documentation is incomplete, that implies that I read it.Sigh...

I still respectfully hope that you or someone will tell me how to set something like "quality=50".Do you see the "quality" in the parameter list for ImageWriter? If you want to specify that you'll have to use a lossless format in ImageWriter and then batch convert to jpg with another program.

TCmullet
10th November 2020, 23:31
Of course I don't see a quality setting; it's not listed. That's why I figured there is information about parameters that never made it into the docs (documentation) but that all you gurus do know. Sounds like your short answer, which you went to great lengths to avoid telling me, was that the filter failed to include such parameters like it should have. Therefore there must be a DEFAULT value. And as neither you nor anyone else (so far) knows what that default value is, I will have to try a couple frames and see how the file size compares to a graphic program's known quality setting. Maybe the default value will be adequate. I strongly prefer not to pursue finding a batch conversion utility.

As good as most Avisynth functions are generally, I am rather surprised that JPG parameters were totally left out. Maybe JPG was included only as a concession in world where (maybe) most people want eBmp. i can see if you are going to export ALL frames for TEMPORARY use, then that makes sense as you're going to scrap the eBMPs eventually anyway. In my case, I'm extracting from a video that is basicly a slide show, in which I want to create the slides. (I will be doing single frames exclusively ("start=x, end=x"). In some cases, I'll be doing ImageReader (also new to me) to import permanently held still images into a range of video frames in a different project.

TCmullet
12th November 2020, 20:42
When I'm used to programs like IrFanView that prompt me with a screen like this which has about 14 options that can be set, I'm rather surprised that any program would be out there that would fail to give even a single option. At the very least I'd expect them to say "these are the jpeg parameters that are internally set and they cannot be changed".

poisondeathray
12th November 2020, 20:55
vdub , avspmod, ffmpeg support avs scripts and can save image sequences including jpeg with various options


2. Also, should I be concerned about color space issues?


possibly;

jpeg are frequently stored as full range YUV (commonly 4:2:0 subsampling, but 4:2:2, 4:4:4 are supported, also RGB is supported) but often decoded as RGB . e.g. If you use ImageSource() to load , they will be loaded as RGB. However, ffmpeg based programs decode them as their stored full range YUV format.

Should you be worried? Possibly, depending on what you started with, and how you are using it, what programs you are using. You might have to make some adjustments. Also if you do not control the matrix for YUV<=>RGB conversions, you might get slight color shifts. JPEG by convention uses full range, 601. But HD video uses 709 limited range .

TCmullet
12th November 2020, 21:36
Poison, you're raising a different issue, but interesting. Was your last comment referring to the idea that some contexts define black as 0 IRE but others define it as +7 IRE?

However, in most cases, I will have saved stills out of an MP4 video, then add it back to another video via ImageSource (which I haven't tried yet, but I'm sure it works.)

poisondeathray
12th November 2020, 21:55
Poison, you're raising a different issue, but interesting


I'm giving you other options instead of ImageWriter. You're using vdub anyways, so why use ImageWriter ?


Was your last comment referring to the idea that some contexts define black as 0 IRE but others define it as +7 IRE?


No

There are several possible issues, including wrong color matrix

If you started with HD YUV video, and used vdub "copy source frame to clipboard", it will use Rec601 (SD color) to convert to RGB . The colors will shift slightly. If you started with typical SD video, it should be ok. Also if there considerations if you're using interlaced video vs. progressive video (they have to be converted differently)


However, in most cases, I will have saved stills out of an MP4 video, then add it back to another video via ImageSource (which I haven't tried yet, but I'm sure it works.)

Yes it works, but it returns RGB.

You go through several lossy steps, including jpeg, YUV=>RGB=>YUV stages, up/down sampling chroma (lossy unless done with nearest neigbor)

(But I guess you don't really care if you're using quality = 50)

Then why use an image sequence ? If your goal was some small filesize, it would be much smaller and higher quality as a YUV video with temporal compression

TCmullet
12th November 2020, 22:06
I'm not doing image sequences. I'm saving slides from video slide shows, both to keep them as slides, then to later use them as slides in new video slide shows, using ImageSource. ImageWriter will always be start=x, end=x. ImageSource will always be start=x, end=y where y is much bigger than x and reflects that the source frame will be on the screen for many seconds.

StainlessS
12th November 2020, 23:13
I think typical default for jpeg quality in an app is usually about 85, so 50 seems a tad low.

TCmullet
13th November 2020, 00:35
Thanks, Stainless. I'll be roughly verifying that when I make a test run of a couple pics that I already saved manually via Vdub, tediously (copy source frame to clipboard, paste into IrFanView window, save).

Do YOU have any idea why not even JPEG quality setting was not incorporated into the ImageWriter parameters? Do you think maybe it was a belief by the author that all image files created would only be temporary files?

TCmullet
13th November 2020, 00:38
I think typical default for jpeg quality in an app is usually about 85, so 50 seems a tad low.
In IrFanView, I experimented with about 6 quality settings to judge tradeoff between my visual perception of quality and file size. I was surprised that 50 seemed as good as anything higher. These were 1080p images viewed over much of my 24" monitor. Quality=1 was funny.

StainlessS
13th November 2020, 10:08
Do YOU have any idea why not even JPEG quality setting was not incorporated into the ImageWriter parameters?
Dont know. Maybe because ImageWriter for multiple formats, and Quality only relevant for one or several of the choices, Png best for lossless.

pinterf
13th November 2020, 10:57
ImageWriter is using the devIL image library for saving jpeg (and other format).
Unfortunately this library has exactly _zero_ parameter on controlling the image quality.
Other than the file name, we have no control. Basically we have only a single choice: save it or not :)