0

Edit: its not liking it when I specify .exr as the output file....not sure if there's a fix to support exr in ffmpeg. Just pretends its .png then unless you can help with that as well

Hi so I transcoded a 30 min video into a 16 bit 1080p.exr image strip. I then plan on upscaling these images with ffmpeg to 4k. I then want to render it out again as an 8 bit h.264 .avi.

Somewhere here I want to apply sharpening to make the upscale a bit cleaner (this command looked nice when applied to the exr on their own):

-filter "unsharp=1x=13:ly=13"la=2.0"

Will unsharpening re-encode? Because my final video output is h.264 8/10bit I don't want to re-encode that.

My question is where in my commands should I be applying the unsharp? And should I only apply it once or as many times throughout that it makes things look nice?

I thought for simplicity I would divide my commands up, but maybe they should be done as a single command? Will a single command lessen the number of re-encodes any?

Step 1. Upscale:

ffmpeg -i %d.exr -vf scale=3840:-1 C:\Users\Me\Desktop\Test\output_3840.exr

Step 2: Turn images into .avi (not sure if this works for avi, i kno it works for mkv tho)

ffmpeg -framerate 500/21 -i %d.exr -c:v libx264 -crf 18 -pix_fmt yuv422p10le output.avi

Step 3: Unsharpen...but when/where?

-filter "unsharp=1x=13:ly=13"la=2.0"

I'm not even sure how to combine these, or like I said if doing so will limit the re-encodes. Is there a single command I can/should be using here based on the 3 above? I'll just do the audio as a separate command with -c copy so it doesn't re-encode, it makes it less confusing for me.

  • Of course it will re-encode. You can't change the content without re-encoding. Stop fretting about the infinitesimal losses re-encoding is going to make, when the end result is an 8-bit h.264 file. It. Won't. Make. Any. Difference. – stib Nov 27 '18 at 3:26
  • my base footage is h.264 though. so unfortunately i need to worry about it. and limit the total render to 1, and transcode and render the number of extra times necessary inbetween. – kite Nov 27 '18 at 3:51
  • No, the compression has already happened. Once ffmpeg has decoded the footage that's as good as it's going to get. Adding the 16-bit png stage will not increase the quality of the input, it will in fact decrease it very very slightly due to quantisation loss. But mostly it will just be a PITA for no benefit. – stib Nov 27 '18 at 3:55
  • Artifacts are the problem I'm trying to avoid. Re-encoding the fooage as h.264 it creates artifacts. Re-encoding twice creates a stupid amount of them and its very noticable, thus I need to keep of and limit the re-encodes and rely on trancode to higher bit numbers if necessary. The problem is my base footage is 8 bit. – kite Nov 27 '18 at 3:58
  • But you don't need to re-encode twice. Upscale and filter in the one operation. Did you look at my answer? – stib Nov 27 '18 at 4:06
1

Just do it all as one step and forget about up-sampling to 16 bit. That just adds complexity, processing time, extra storage and for no gain in quality in the end result that anyone could possibly perceive.

fmpeg myinputVideo.avi -vf "scale=3840:2160,unsharp=1x=13:ly=13"la=2.0" myoutput.mp4

The internal process of ffmpeg works basically like this:

 _______              ______________
|       |            |              |
| input |  demuxer   | encoded data |   decoder
| file  | ---------> | packets      | -----+
|_______|            |______________|      |
                                           v
                                       _________
                                      |         |
                                      | decoded |
                                      | frames  |
                                      |_________|
 ________             ______________       |
|        |           |              |      |
| output | <-------- | encoded data | <----+
| file   |   muxer   | packets      |   encoder
|________|           |______________|

The "decoded frames" box basically is where the pixels in the image are stored in memory as uncompressed RGB or YUV (or whatever) samples. That's the point where your footage is as good as it is going to get. Any extra filtering or processing will notionally degrade the image due to quantisation loss, or compression etc.. That image is what is sent to the filter chain. What you're doing is:

demux → decode → [decoded frames] → resample → encode → mux → save → 
demux → decode → [decoded, resampled frames] → upscale → sharpen → encode → mux → save

so you're applying your filters to frames that have had an extra resample and encode step added, not to mention taking up a whole bunch'a space on your HDD.

When you filter something the output of one filter goes to the input of the next filter in the chain, so if you put scale first the scaled image is then sent to the sharpen filter.

 _______        ________        _________        ________
|       |      |        |      |         |      |        |
| input | ---> | scale  | ---> | sharpen | ---> | output |
|_______|      |________|      |_________|      |________|

You can get more complex by using -filter_complex which allows you to have various inputs and outputs for filters.

https://ffmpeg.org/ffmpeg.html#Filtering for more ascii-art empowered knowledge

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.