Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using free command-line sorcery to fake Superview
#1
EDIT: There's a better way! It's over there!

Gather round, children, as I describe how I fell down a rabbit hole trying to fake Superview, and how it worked, and why I don't use it.

Some background, then. GoPro's Superview is a non-linear horizontal stretch effect. For more details, have a look here (https://gopro.com/help/articles/question...-SuperView), but the short version is that it takes a 4:3 image and stretches it to fit a 16:9 frame. But it leaves the middle alone so it's not too distorted, and increases the stretch at the edges. This means you keep the full field-of-view instead of having to crop it, and as a side bonus the action looks a little quicker Wink

I use ffmpeg (https://www.ffmpeg.org/) to do a bunch of video pre-processing which I may talk about in another thread (let me know if people are interested), but I was curious if I could achieve the Superview effect using ffmpeg as well. I initially wanted to use the displace filter, but couldn't find a way of displacing more than 128 pixels (if anyone has any ideas in that direction, let me know - maybe some pixel format hackery?), so I finally settled on the remap filter. That requires some additional input files to work, so I whacked together a quick Python script to generate those for me:

Code:
import sys
import math

def derp_it(tx, target_width, src_width):
   x = (float(tx) / target_width - 0.5) * 2 # -1 -> 1
   sx = tx - (target_width - src_width) / 2
   offset = math.pow(x, 2) * (-1 if x < 0 else 1) * ((target_width - src_width) / 2)
   return sx - offset
   

def go():
   target_width = int(sys.argv[1])
   height = int(sys.argv[2])
   src_width = int(sys.argv[3])

   xmap = open('xmap.pgm', 'w')
   xmap.write('P2 {0} {1} 65535\n'.format(target_width, height))

   for y in range(height):
       for x in range(target_width):
           fudgeit = derp_it(x, target_width, src_width)
           xmap.write('{0} '.format(int(fudgeit)))
       xmap.write('\n')

   xmap.close()

   ymap = open('ymap.pgm', 'w')
   ymap.write('P2 {0} {1} 65535\n'.format(target_width, height))

   for y in range(height):
       for x in range(target_width):
           ymap.write('{0} '.format(y))
       ymap.write('\n')

   ymap.close()

if __name__ == '__main__':
   go()

You can use it like this:

Code:
python remap_gen.py [TARGET_WIDTH] [HEIGHT] [SOURCE_WIDTH]

For 1440x1080 video, you will want the following settings:

Code:
python remap_gen.py 1920 1080 1440

This will output two files, xmap.pgm and ymap.pgm, which contain a bunch of values. We pass these into ffpmeg with our video file like so:

Code:
ffmpeg -i [INPUT_FILE] -i xmap.pgm -i ymap.pgm -lavfi remap [OUTPUT_FILE]

Which turns this:

[Image: OCFgJiO.jpg]


into this:

[Image: 87Tc1Yj.png]

As you can see, the middle stays roughly the same, but the edges are stretched out. Here's another example with a frame from an actual flying video.

[Image: 2TwsIAp.jpg]

[Image: g2N84gw.jpg]

Yes, there are a lot of artefacts at the edges. Turns out ffmpeg's remap filter doesn't do any kind of interpolation. Anyway, let's soldier on.

Applying this to video works exactly the same way. Below are a couple of videos illustrating the results. The first is the unmolested video, and the second one has the fake superview effect. This was shot on a Runcam 3S, and the first video has already been through my usual editing pipeline, which increases the colour temperature and removes most of the lens distortion.

Original



Fake Superview



So, success!

Well, kind of. The Runcam 3S doesn't support 4:3. So now what we need to do is take the 16:9 video, crop it down to 4:3 and then 'superview' it back out to 16:9. The end result is that we're sacrificing field of view for the illusion of speed. Honestly, I'm not sure it is worth the trade off. Also, the lack of image interpolation hurts the end result. Not that you can really see this in the video once the various compression algorithms have taken their pound of flesh, but it's pretty obvious in the static images. A smarter filter would do some kind of bicubic interpolation or something, but ffmpeg's remap doesn't.

In short, I don't use it. If the Runcam 3S did full-sensor 4:3 then it would make perfect sense. If ffmpeg did smoother work with remap then I would at least consider it. But they don't, so I don't.

Pyrrhic victory, baby.

The ground is for dead people.
[-] The following 7 users Like Banelle's post:
  • FlyerFpv, Whiffles, quantumvortex, Oscar, izzy26, Krohsis, SnowLeopardFPV
Reply
Login to remove this ad | Register Here
#2
Nice tutorial.
Reply
#3
Nice bit of work and a great write-up Thumbs Up

Looking at the Python script I guess it requires some understanding of the makeup up image files along with remapping filters in FFmpeg and how those actually work. It's not something I've ever looked into but I guess if someone was to spend a bit of time reading up on it, then it's probably not rocket science. Thanks for doing all the R&D work and then sharing it Cool

So if anyone has a full sensor 4:3 camera then this method seems to be a good option if you don't mind the smoothness being less than optimal.

Hopefully you won't get a cease and desist letter from GoPro through your letterbox anytime soon Whistling Big Grin
Reply
#4
(01-Mar-2019, 03:25 PM)SnowLeopardFPV Wrote: Looking at the Python script I guess it requires some understanding of the makeup up image files along with remapping filters in FFmpeg and how those actually work. It's not something I've ever looked into but I guess if someone was to spend a bit of time reading up on it, then it's probably not rocket science. Thanks for doing all the R&D work and then sharing it Cool

Each mapping file contains the coordinates in the source image for each pixel in the destination image, and the X and Y are split into seperate files. It's goofy as hell, TBH. It would be much cleaner to do it using the 'displace' filter, because you can generate the input files mathematically on the command line, which is quite neat. But in that case the input format is 8 bits, so you can't displace each pixel more than 128 in either direction (well, -128 to 127). The other disadvantages are still there, anyway, so I didn't investigate much further.

(01-Mar-2019, 03:25 PM)SnowLeopardFPV Wrote: So if anyone has a full sensor 4:3 camera then this method seems to be a good option if you don't mind the smoothness being less than optimal.

Yeah, at that point you'd either crop it down to 16:9 and lose the top and bottom of the video, or use this and gain some artefacts. In that case I'd probably use this.

(01-Mar-2019, 03:25 PM)SnowLeopardFPV Wrote: Hopefully you won't get a cease and desist letter from GoPro through your letterbox anytime soon Whistling Big Grin

Come at me, GoPro. I am armed with maths.

The ground is for dead people.
[-] The following 1 user Likes Banelle's post:
  • SDX55
Reply
#5
Thanks for your work Banelle, I made it into a simple Go program: https://github.com/Niek/superview
[-] The following 3 users Like Niek's post:
  • SDX55, Whiffles, KonradS
Reply
#6
@Banelle: Sweet although I hate Python (C#, F# guy here) but very cool,...


"THANK GOD FOR QUADCOPTERS!" has nobody at the FAA said, ever.
Reply
#7
(20-Jun-2019, 06:12 PM)quantumvortex Wrote: @Banelle: Sweet although I hate Python (C#, F# guy here) but very cool,...

Thanks!

I've actually been revisiting this in my spare time, since the Runcam 5 has 4:3 recording and that makes this a lot more viable. I've also ditched the ffmpeg command line and written my own stuff using the ffmpeg libraries and C++. That also means I can interpolate the stretch and so the results are a lot less 'pixely'.

My cam arrived yesterday so I'll try to fix the last few bits of oddness (some weirdness around the timebases mean the FPS values of the output video are a little off), give it a polish and then put it on Github.

The ground is for dead people.
[-] The following 2 users Like Banelle's post:
  • quantumvortex, Whiffles
Reply
#8
(21-Jun-2019, 09:05 AM)Banelle Wrote: Thanks!

I've actually been revisiting this in my spare time, since the Runcam 5 has 4:3 recording and that makes this a lot more viable. I've also ditched the ffmpeg command line and written my own stuff using the ffmpeg libraries and C++. That also means I can interpolate the stretch and so the results are a lot less 'pixely'.

My cam arrived yesterday so I'll try to fix the last few bits of oddness (some weirdness around the timebases mean the FPS values of the output video are a little off), give it a polish and then put it on Github.

Sounds great! I can't wait to test it out. I tried the existing code and the effect works great, but the resolution leaves a lot to be desired.
Reply
#9
I just took some Box 2 2.7k footage, squeezed from 16:9 "Supervision" to 4:3 then applied the script. Here is my result. You can definitely see the difference.

[Image: RBBwj5Gl.jpg]
Reply
#10
I absolutely love this stuff right here, aside from cubing through a gap or chasing a witchs broom in a power loop. Right on, digital gear heads Smile... thnx so much for this. Thumbs Up Tongue

var factory = new FPVCameraGoodness().ExecuteThankYou(Actions.Courtesy, 22.5);
factory.DoIt();


"THANK GOD FOR QUADCOPTERS!" has nobody at the FAA said, ever.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Tutorial Derperview - A Command Line Superview Alternative Banelle 61 11,363 21-May-2023, 08:10 PM
Last Post: Seii-FPV


Login to remove this ad | Register Here