Edge emphasis screwup

Started by SaVe, August 29, 2015, 12:42:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SaVe

so i know this is gonna sound very annoying for any seasoned magic lantern user or anyone with some common sense, but I forgot to uncheck the edge emphasis before starting to shoot today. the whole thing has gone unnoticed until I checked the clips on my laptop.

The parts of the shot in critical focus now look like someone poured sharpness over it, and I have no idea how to recover that. Also I am not exactly a pro in post-producing, but I can find my way around AE.

Anyone has a magic trick that will take away my woes?

attached is the woe in question


a1ex

Quote from: SaVe on August 29, 2015, 12:42:57 AM
Anyone has a magic trick that will take away my woes?

Sorry, didn't notice the issue back then. I know it's late, but... I think I've just found the magic trick.



Details: edge-emphasis-fix.html (11 MB)

I'll remove that feature; meanwhile, the fix might be helpful for other users with the same issue.

Narumon

Quote from: a1ex on November 02, 2018, 02:17:55 PM
Sorry, didn't notice the issue back then. I know it's late, but... I think I've just found the magic trick.


Details: edge-emphasis-fix.html (11 MB)

I'll remove that feature; meanwhile, the fix might be helpful for other users with the same issue.


I need this fix so bad, but cant quite understand what I need to do. Is there a more straightforward to do list?
I have MOV files from my 550D - What tools I need to get rid of that edge emphasis?

Thank you!

a1ex

You need octave and ffmpeg; the procedure is performed on the command line (regardless of the operating system).

- ffmpeg to split the video into frames -> [1] in the notebook
- octave script to apply the correction -> [16] in the notebook
- ffmpeg to re-assemble the video -> [18] in the notebook

That's it.

Narumon

Quote from: a1ex on November 11, 2018, 05:14:08 PM
You need octave and ffmpeg; the procedure is performed on the command line (regardless of the operating system).

- ffmpeg to split the video into frames -> [1] in the notebook


When I wrote this command in command line: ffmpeg -loglevel quiet -hide_banner -i '151.MOV' frame%03d.png
Nothing happens :(

Narumon

This command (ffmpeg -i 151.MOV image-%07d.png) done the trick. Now I have a few hundred png files.
But I cant make octave to work. I copied the command in a new.m file, but dont know what to do. If I starting the octave.vbs.... its a menu of something. I dont know what to do, please help :(

Narumon

I think I was able to get it work. Now it makes the output png-s. Fingers crossed :P

Narumon

Quote from: a1ex on November 11, 2018, 05:14:08 PM
You need octave and ffmpeg; the procedure is performed on the command line (regardless of the operating system).

- ffmpeg to split the video into frames -> [1] in the notebook
- octave script to apply the correction -> [16] in the notebook
- ffmpeg to re-assemble the video -> [18] in the notebook

That's it.

Can you help me a bit please? After 15 hours of "cleaning" i tried to re-assemble the video, and everything went okay, except that the frame rate is 25fps (the original was 23.98fps), so the audio is out of sync. How can I modify this command for 23.98fps out file?

ffmpeg -i fixed%07d.png -i 140.MOV -vcodec mjpeg -q 0 -acodec copy -map 0:v:0 -map 1:a:0 140_fixed.avi

Thank you

Narumon

The input pngs time is different than the original. This is only the fps difference?

Input #0, image2, from 'fimage-%07d.png':
  Duration: 00:07:11.52, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24(pc), 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '140.MOV':
  Metadata:
    major_brand     : qt
    minor_version   : 537331968
    compatible_brands: qt  CAEP
    creation_time   : 2018-08-03T15:58:02.000000Z
  Duration: 00:07:29.95, start: 0.000000, bitrate: 47321 kb/s
    Stream #1:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709), 1920x1080, 45783 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default)
    Metadata:
      creation_time   : 2018-08-03T15:58:02.000000Z
    Stream #1:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)

Danne

Working?
Quoteffmpeg -i fixed%07d.png -i 140.MOV -vcodec mjpeg -q 0 -acodec copy -map 0:v:0 -map 1:a:0 -r 23.98 140_fixed.avi

Could you upload the octave script you are using too?

Narumon

Hi!

Thans - this is doing the trick, but something wrong with it... :( The output file now 23.98 but still out of sync, and when generating the ffmpeg constantly gives these messages:

Past duration 0.917595 too large
Past duration 0.958397 too large  13578kB time=00:00:01.83 bitrate=60619.4kbits/s dup=0 drop=1 speed=1.81x
Past duration 0.999199 too large
Past duration 0.651985 too large  18186kB time=00:00:02.41 bitrate=61594.3kbits/s dup=0 drop=1 speed=1.58x
Past duration 0.692787 too large
Past duration 0.733589 too large
Past duration 0.774391 too large
Past duration 0.815193 too large
Past duration 0.855995 too large
Past duration 0.896797 too large
Past duration 0.937599 too large
Past duration 0.978386 too large
Past duration 0.671989 too large  22026kB time=00:00:02.91 bitrate=61811.6kbits/s dup=0 drop=2 speed=1.43x
Past duration 0.712791 too large
Past duration 0.753593 too large  26378kB time=00:00:03.58 bitrate=60252.8kbits/s dup=0 drop=3 speed=1.41x
Past duration 0.794395 too large

Narumon

Quote from: Danne on November 12, 2018, 07:12:59 PM
Working?
Could you upload the octave script you are using too?

This is the script which works for me - but only with the installed octave. The command line version constantly gives error that cant find the image package.

  pkg load image

# frame numbers hardcoded for the test clip
for k = 1:10788

  # read frame k
  a = im2double(imread(sprintf('image-%07d.png', k)));

  # 5x5 median filter
  am55 = a;
  for i = 1:3
    am55(:,:,i) = medfilt2(a(:,:,i), [5 5]);
  end

  # limit fine detail to +/- 0.05 around the 5x5 median filtered image
  delta3 = min(max(a - am55, -0.05), 0.05);
  fixed3 = am55 + delta3;

  # save the fixed frame
  imwrite(im2uint8(fixed3), sprintf('fimage-%07d.png', k));
end

a1ex

Would this work any better? Just a guess; not tested; based on this guide:

ffmpeg -framerate 23.976 -i fixed%07d.png -i 140.MOV -vcodec mjpeg -q 0 -acodec copy -map 0:v:0 -map 1:a:0 140_fixed.avi


@Danne: check the HTML notebook linked earlier.

Narumon

Quote from: a1ex on November 12, 2018, 07:38:38 PM
Would this work any better? Just a guess; not tested; based on this guide:

ffmpeg -framerate 23.976 -i fixed%07d.png -i 140.MOV -vcodec mjpeg -q 0 -acodec copy -map 0:v:0 -map 1:a:0 140_fixed.avi


Whoaaaa, this is it!!
Thank you, thank you, thank you! You are the KING!

I now have a usable video finally!
Now I just need to do this procedure again about 150 more times.... (That is the amount of video files which I did with edge emphasis turned on...) :(

a1ex

Quote from: Narumon on November 12, 2018, 07:52:17 PM
Now I just need to do this procedure again about 150 more times....

150*10788/24/60/60 = 18 *hours* of video. 150*15 = 94 days of computer time. Wait, what?!

15 hours on this clip => about 4-5 seconds per frame in octave.

This does exactly the same filtering, but... twice as slow on my system:

convert frame001.png -median 5x5 frame001.png -fx 'min(max(v, u-0.05), u+0.05)' fixed001.jpg


Not a FFMPEG expert, but it appears to have a median filter and some advanced capabilities. If the above filtering can be done in one single ffmpeg command, processing might be a lot faster.

Avisynth has a median filter, too.

Alternative: the above filter written in some fast language, possibly as ffmpeg plugin, possibly with GPU acceleration. Not an expert with these either.

Danne

Great octave stuff!
I had some success with a ffmpeg filterchain. It´s very fast too:
real 0m8.272s
user 0m12.814s
sys 0m0.235s

This is a more extreme cleaning but it can be easily tweaked:
ffmpeg -i Input.mp4 -vf removegrain=4,removegrain=4,removegrain=4,removegrain=4,removegrain=4,unsharp=9:9:1.0:9:9:0 -c:v libx264 -preset ultrafast -crf 10 Output.mov

Filter here:
https://ffmpeg.org/ffmpeg-filters.html#toc-removegrain

Gave this:


Original





An alternative with not so strong filtering is this:
ffmpeg -i Input.mp4 -vf removegrain=4,removegrain=4,removegrain=4,removegrain=4,unsharp=7:7:0.8:7:7:0 -c:v libx264 -preset ultrafast -crf 10 Output.mov

You can put the command in a for loop and it will do all of you files in one go...


Here´s a for loop that will convert a bunch of formats:
for f in *.{mp4,MP4,mov,MOV,avi,AVI}; do
ffmpeg -i "$f" -c:v libx264 -crf 10 -vf removegrain=4,removegrain=4,removegrain=4,removegrain=4,unsharp=7:7:0.8:7:7:0 clean_"$f"
done


Do:
brew install ffmpeg
If not installed already.

Narumon

Quote from: a1ex on November 12, 2018, 09:00:07 PM
150*10788/24/60/60 = 18 *hours* of video. 150*15 = 94 days of computer time. Wait, what?!

15 hours on this clip => about 4-5 seconds per frame in octave.
Avisynth has a median filter, too.

Alternative: the above filter written in some fast language, possibly as ffmpeg plugin, possibly with GPU acceleration. Not an expert with these either.

Not all videos are the same length. Yesterday I done 3 more, which was 1 or 2 minutes long. Overall the speed is 11-14 picture /minute. (Ryzen5 1600x).

A will try to look after a faster but same quality solution.

Narumon

Quote from: Danne on November 12, 2018, 10:24:54 PM
Great octave stuff!
I had some success with a ffmpeg filterchain. It´s very fast too:

This is a more extreme cleaning but it can be easily tweaked:

Filter here:
https://ffmpeg.org/ffmpeg-filters.html#toc-removegrain

An alternative with not so strong filtering is this:
ffmpeg -i Input.mp4 -vf removegrain=4,removegrain=4,removegrain=4,removegrain=4,unsharp=7:7:0.8:7:7:0 -c:v libx264 -preset ultrafast -crf 10 Output.mov

You can put the command in a for loop and it will do all of you files in one go...

I will try these, but the above image is not good enough I think. Its roughly the same result as the Adobe Premiere built in median filter gives. Too plastic. :(

Danne

If the median filtering is the same or similar the effect could be refined by tweaking the command.

a1ex

Quote from: Danne on November 13, 2018, 09:30:48 AM
If the median filtering is the same or similar [...]

It's not.

Quote from: a1ex on November 12, 2018, 09:00:07 PM
convert frame001.png -median 5x5 frame001.png -fx 'min(max(v, u-0.05), u+0.05)' fixed001.jpg

That fx thingie is essential for bringing back the fine details. Tuning can be done from that constant (0.05); lower values will filter more aggressively, higher values will preserve more fine details.

No idea how to specify the same operation with ffmpeg syntax, though.

Danne

Finetuning in this filter doesn't seem incorporated so would require some coding. Didn't check deeper into ffmpeg but maybe something else could work.

Danne

Tested some more and think this was a good compromise of things:
for f in *.{mp4,MP4,mov,MOV,avi,AVI}; do
ffmpeg -i "$f" -c:v libx264 -crf 10 -vf removegrain=4,removegrain=4,unsharp=3:3:1.0:3:3:0.0 clean_"$f"
done


Add:
ffmpeg -i "$f" -c:v libx264 -crf 10 -vf removegrain=4,removegrain=4,unsharp=5:5:1.0:5:5:0.0 clean_"$f"
for a slightly sharper output.

Original


ffmpeg


Octave script(warmer tone?)


a1ex

I don't get any difference in colors here.

ffmpeg -i "LV DIGIC Peaking Issue-d44BDcfRwdo.mp4" first.png
octave fix_first.m # 5x5 median; output fixed-oc.png
octave fix_first33.m # 3x3 median; output fixed-oc33.png
convert first.png -median 5x5 first.png -fx 'min(max(v,u-0.05),u+0.05)' fixed-cv.png # nearly identical to octave 5x5
ffmpeg -i "LV DIGIC Peaking Issue-d44BDcfRwdo.mp4" -vf removegrain=4,removegrain=4,unsharp=5:5:1.0:5:5:0.0 fixed-ff.png # somewhat resembling octave 3x3 output
ffmpeg -i "LV DIGIC Peaking Issue-d44BDcfRwdo.mp4" -c:v libx264 -crf 10 -vf removegrain=4,removegrain=4,unsharp=5:5:1.0:5:5:0.0 fixed.mp4; ffmpeg -i fixed.mp4 fixed-ff2.png

Edit: after uploading the images, I do notice a difference when viewing them with Firefox (images saved from Octave look different). With some local image viewers (Eye of Mate, Gimp, Geeqie, gThumb), all of them look identical. Go figure.

The PNG saved by ImageMagick has the following additional metadata (missing from the one saved by Octave):

+Gamma                           : 1.961
+White Point X                   : 0.3127
+White Point Y                   : 0.329
+Red X                           : 0.64
+Red Y                           : 0.33
+Green X                         : 0.3
+Green Y                         : 0.6
+Blue X                          : 0.15
+Blue Y                          : 0.06
+Background Color                : 255 255 255
+Pixels Per Unit X               : 1
+Pixels Per Unit Y               : 1
+Pixel Units                     : Unknown


Here's a hack:
convert first.png fixed-oc.png -fx 'v' fixed-och.png

This keeps metadata from the original frame (saved by ffmpeg) and image contents from the corrected frame (saved by octave). Exiftool -tagsFromFile didn't seem to work.

Some fun stuff - look at this image with Firefox or Chrome, then save it and open it on our PC:


Danne

That is why tif is superior  ;)

a1ex

Maybe, but that won't solve our color difference issue. The reassembled video looks darker/warmer, no matter what still image format you use, out of jpg, png, ppm and tif. And I'm unable to display the tif file in the web browser; that's why I've used .png.

The following does the trick, i.e. the output video has correct colors, regardless of the still image format (jpg, png, ppm, tif):

ffmpeg -i "LV DIGIC Peaking Issue-d44BDcfRwdo.mp4" -y frame%03d.png # or tif or ppm or jpg

# process the images (octave script or whatever)

ffmpeg -framerate 23.976 -i frame%03d.png -i "LV DIGIC Peaking Issue-d44BDcfRwdo.mp4" -pix_fmt yuv420p -colorspace smpte170m -color_trc bt709 -color_primaries bt709 -color_range tv -c:v libx264 -crf 10 -c:a copy -map 0:v:0 -map 1:a:0 -y from-png.mp4


Idea from https://www.reddit.com/r/ffmpeg/comments/8t54bm/converting_yuvj420p_to_yuv420p_issues_with_black/

Then, trial and error to make sure the format is "yuv420p(tv, smpte170m/bt709/bt709)", i.e. matching the original clip.


ffprobe LV\ DIGIC\ Peaking\ Issue-d44BDcfRwdo.mp4
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt709/bt709), 1920x1080 [SAR 1:1 DAR 16:9], 3163 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
ffprobe from-png.mp4
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt709/bt709), 1920x1080 [SAR 1:1 DAR 16:9], 14947 kb/s, 23.98 fps, 23.98 tbr, 11988 tbn, 47.95 tbc (default)


Updated the HTML notebook with this command.