f-log

just another web log

31 May 2019:
blender animation custom python metadata
I have been mucking about with cameras in Blender to try and get a good match on a photograph. The photograph is taken from an odd location and has some lens distortions that I can not match. In response am creating videos showing how varying the different camera parameters affects the view.

As part of this I wanted to show the camera parameters as they changed. Blender has a metadata option and there is great write up about how to use Python to add custom data here that appears to have been taken from here
which is often referenced with how to show the metadata outside of the frame

This what worked for me
import bpy

def stamp_set(scene):
    render = scene.render
    render.use_stamp_note = True
    render.stamp_note_text = "Sensor size: {:.2f}".format(bpy.data.cameras[0].sensor_width)

bpy.app.handlers.render_pre.clear()    
bpy.app.handlers.render_pre.append(stamp_set)


Which will clear all existing pre-render handlers and then add my custom one that sets the metadata to include the camera sensor width each time a frame renders.
25 May 2019:
i am tierd and i want to go to bed
Recently I have noticed I am spending too much time on watching videos, from GoT and Battlestar Galactica to YouTube. To combat this I have instigated a number of counter measures.

Phone limits YouTube App time to 1hr per day so I still get my fix.
Phone switches into Wind Down mode. Screen goes grey scale, but still works if necessary.
The under-shelf lighting shifts to a Pink colour.
And on top of that I am trying(really hard) to go to be earlier.

If I am desperate to waste my time and stay up late, I can still do it, but so far these measures are making a big impact.

Now if I could just come up with a way to remind myself to exercise each day ...
25 May 2019:
forcing ffmpeg to my overlaying will
I had been asked to compile a video from two different sources for a sports event. Blender to the rescue and after about 24hrs I had a 15 minute video. Not very efficient.

Then I had the sources updated and I tried again. This time I knew what I was doing but the Rendering was still taking many hours.

When I was asked for a third time I took step back and reviewed what I was doing;


FFmpeg is incredibly powerful, but also a bit of a black box, requiring strange incantations. However there is a lot of people talking about it on the various StackOverflow sites and I managed to piece the following together.

example cam1 next to cam2

ffmpeg -i camera2.mp4 -vf scale=384:216 camera2_scaled.mp4
Scales the camera2.mp4 to 384x216, which is just about right for the PiP overlay to not occlude any of the action.

ffmpeg -i camera2.mp4 -ss 00:00:00.75 camera2_offset.mp4
Creates a video that skips the first .75 seconds, offsetting it by that amount. That tiny amount was almost imperceptible when combining the two videos at the beginning, but by the end the synchronisation was way off and very annoying.

FFmpeg being a typical linux application can combine these.
ffmpeg -i camera2.mp4 -ss 00:00:00.75 -vf scale=384:216 camera2_scaled_and_offset.mp4

example cam2 overlaid and scaled on cam1

Now the overlay.
ffmpeg -i camera1.mp4 -i camera2_scaled_and_offset.mp4 -filter_complex "[0:v][1:v] overlay=0:504" PiPOverlay.mp4
Takes the inputs "camera1.mp4" and "camera2_scaled_and_offset.mp4" and using a complex filter(more on that later) overlays video index 1 [1:v] on top of video index 0 [0:v] at the pixel location of 0,504. Putting it in the bottom left corner.

There was some editing/cutting of the footage next.

ffmpeg -i PiPOverlay.mp4 -t 00:29:30 -acodec copy -vcodec copy part1.mp4
This creates a new video "part1.mp4" that contains only the first 29 mins 30 seconds.

ffmpeg -i PiPOverlay.mp4 -ss 00:31:30 -to 00:33:18 -acodec copy -vcodec copy part2.mp4
This creates a new video "part2.mp4" that contains only the frames from 31:30 to 33:18.

Then to combine them you need a text file listing the components in order.
find . -iname "part*.mp4" -printf "file '%f'\n" | sort -n > part.list
ffmpeg -f concat -i part.list -c copy video_parts_combined.mp4

The find command prints out the file names with a "file " prefix and sorts them numerically(computers like to order things alphabetically) and the output is stored in "part.list".
The "concat" command of FFmpeg then concatenates them together.

example image sequence

Next I did a nice information card in Blender matching the resolution of my target video. Low number of samples, orthographic camera, all Emission materials. Then I parented all the components and animated them with a bounce. Rendered that as a transparent PNG sequence.

example image sequence overlaid on target video

Found a lot of examples for FFmpeg that did not quite match my requirement or that had lots of extra parameters that were not needed for what I wanted. This was the result, after a lot of trail and error.

STARTSEC=3
MIDSEC=$((60*17))
ENDSEC=$((60*31))
ffmpeg -i video_parts_combined.mp4 \
-itsoffset $STARTSEC -i /tmp/%04d.png \
-itsoffset $MIDSEC -i /tmp/%04d.png \
-itsoffset $ENDSEC -i /tmp/%04d.png \
-filter_complex "[0:v][1:v]overlay [temp0]; \
[temp0][2:v]overlay [temp1]; \
[temp1][3:v]overlay [out]" -map [out] finished.mp4


First I created three variables for easy alterations. One for each of the areas that the info card should appear; at 3 seconds and then at 17 minutes and 31 minutes. Then I created four inputs for FFmpeg; the base video and the image sequence three times each with the different start offsets.
Now we get into filter_complex territory; video index 1 [1:v] is overlaid on video index o [0:v], but assigned to [temp0] then [temp0] is overlaid with video index 2 [2:v] and assigned to [temp1]. This is repeated to overlay video index 3 [3:v] onto [temp1], resulting in [out].
The "-map" takes the [out] and creates the final "finished.mp4" video file.

Caution: I was not interested in audio in any of this process, so reuse at your own risk.
18 May 2019:
ubuntu takes control windows style
Ubuntu WTH!

I have an old laptop with Ubuntu on that had been buried under a stack of paper for a few months. Finally fished it out and started it up.

First job update APT cache.
sudo apt-get update
... ran fine
next actually upgrade the packages installed.
sudo apt-get upgrade
... ERROR
something about the lock file for frontend being in use.

Try again and again and then check if anything is using frontend
lsof | egrep frontend
nothing...

Double check any other apps running, you know like the Software Updater. There is nothing other than my terminal!

Time to reboot

Unattended-upgrade in progress during shutdown, please don't turn off the computer

AGHHHhhh...!! I am not running Windows!

DO NOT WANT!

All the Ubuntu devs had to do was have the Software Updater GUI showing, like they do normally, but apparently I am not allowed to know what my system is doing :(

I would love to switch to another distro, but this machine runs Ubuntu to make sure it runs bog standard.
18 May 2019:
blender vse fight scene at start frame
Quick note to myself about Blender animations that contain Videos and Scenes.
DO NOT START AT ANY OTHER FRAME THAN 0 !!!

Context:
Loaded a 30min video into the Video Sequencer and then created a Scene with animated elements. Added the Scene to the VSE and everything worked well. Started the render going ...
12hrs later the drive ran out of space (19G) and the render stopped. Then I moved everything to a new drive and set the Start frame to be the "next" frame and set it rendering again.

I noticed that the progress information kept flicking from one value to another for the "current frame". After 6hrs I realised this was rendering the Scene frame well ahead of the video frame.

When you set the Start frame in a normal Blender animation that is the frame Blender starts rendering from. But when you have a VSE setup the video frame matches the Start frame but the Blender Scene instead renders frame n+Start frame.

The fix, of course, is to make sure the "overwrite" checkbox is cleared and just restart the render from Start frame 1. Blender checks for the frame file names before it happily continues from Start frame.

And this is a reminder to ALWAYS render to PNG/JPEG not MPG/MP4 and then ffmpeg it back to a movie at the end.
loading results, please wait loading animateloading animateloading animate
[More tags]
rss feed

email

root

flog archives


Disclaimer: This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk In fact I'm not responsible for anything ever, so there!