Showing posts with label dance. Show all posts
Showing posts with label dance. Show all posts

FFmpeg: Colour animation from macroblock motion-vectors



The animation is created from styling the macroblock motion vectors, as displayed by FFmpeg, rather than by manipulating the actual video content. The blocks of colour are created by stacking 'dilation' filters on the motion-vector layer. Before being dilated, the colouring of the arrows is extracted from the original video by 'colorkey' overlay. Based on an earlier filtergraph experiments.¹

#!/bin/bash 
# Generate stylised animation from video macroblock motion vectors, 
# and present in a side-by-side comparison with original video. 
# version: 2018.03.28.21.08.16 
# source: https://oioiiooixiii.blogspot.com 

cropSize="640:ih:480:0" # Adjust area and dimensions of interest

ffplay \
   -flags2 +export_mvs \
   -i "$1" \
   -vf \
      "
         split [original][vectors];
         [vectors] codecview=mv=pf+bf+bb,
                   crop=$cropSize [vectors];
         [original] crop=$cropSize,
                    split=3 [original][original1][original2];
         [vectors][original2] blend=all_mode=difference128,
                              eq=contrast=7:brightness=-0.3,
                              split [vectors][vectors1];
         [vectors1] colorkey=0xFFFFFF:0.9:0.2 [vectors1];
         [original1][vectors1] overlay,
                               smartblur,
                               dilation,dilation,dilation,dilation,dilation,
                               eq=contrast=1.4:brightness=-0.09 [pixels];
         [vectors][original][pixels] hstack=inputs=3
      "



¹ see also: https://oioiiooixiii.blogspot.com/2016/09/ffmpeg-create-video-composite-of.html
source video: りりあ (LILIA)https://www.youtube.com/watch?v=U1DFzSlNkV8 (used without permission) m(_ _)m

FFmpeg: Extract section of video using MPV screen-shots



An unorthodox, but simple and effective way of accurately extracting a section of video from a larger video file, using MPV screen-shots (with specific file naming scheme) for 'in' and 'out' points.

Bash commands below serve only to demonstrate the general idea. No error handling whatsoever.
#!/bin/bash
# Extract section of video using time-codes taken from MPV screen-shots
# Requires specific MPV screen-shot naming scheme: screenshot-template="%f__%P"
# N.B. Skeleton script demonstrating basic operation

filename="$(ls -1 *.jpg | head -1)"
startTime="$(cut -d. -f-2 <<< "${filename#*__}")"
filename="${filename%__*}"
endTime="$(cut -d_ -f3 <<<"$(ls -1 *.jpg | tail -1)" | cut -d. -f-2)"
ffmpeg \
   -i "$filename" \
   -ss "$startTime" \
   -to "$endTime" \
   "EDIT__${filename}__${startTime}-${endTime}.${filename#*.}"
Another approach to this (and perhaps more sensible) is to script it all through MPV itself. However, that ties the technique down to MPV, whereas, this 'screen-shot' idea allows it to be used with other media players offering timestamps in the filename. Also, it's a little more tangible: you can create a series of screen-shots and later decide which ones are timed better.

video shown in demo: “The Magic of Ballet With Alan and Monica Loughman" DVD (2005)

UPDATE: September 11, 2018



I recently happened upon a MPV lua script created for practical video extraction.


It really works well, and I now find myself using it every time I need to clip a section of video.
link: https://github.com/ekisu/mpv-webm

MacMillan's "The Rite of Spring" + Magma - 'Slag Tanz'.








source video: https://www.youtube.com/watch?v=GEOi4ZzUud4

FFmpeg: Extract foreground [moving] objects from video


This is a somewhat crude implementation, but given the right source material, an acceptable result can be generated. It is based on FFmpeg's 'maskedmerge' filter, which takes three input streams: a background, an overlay, and a mask (which is used to manipulate the pixels of the overlay layer).

ffmpeg \
   -i background.png \
   -i video.mkv \
   -filter_complex \
   "
      color=#00ff00:size=1280x720 [matte];
      [1:0] format=rgb24, split[mask][video];
      [0:0][mask] blend=all_mode=difference, 
         curves=m='0/0 .1/0 .2/1 1/1', 
         format=gray,
         smartblur=1,
         eq=brightness=30:contrast=3, 
         eq=brightness=50:contrast=2, 
         eq=brightness=-10:contrast=50,
         smartblur=3,
         format=rgb24 [mask];
      [matte][video][mask] maskedmerge,format=rgb24
   " \
   -shortest \
   -pix_fmt yuv422p \
   result.mkv

For this process, a still background image is needed. An extracted frame from the video will do, or if the background is constantly obscured, it may be necessary to manually create a clean image from multiple frames (stacking multiple frames may produce better results too).

The background image is 'difference' blended with the video, to produce the mask which will be used with the 'maskedmerge' filter. This video stream is then converted to grayscale and adjusted to maximise the contrast levels. [N.B. The video format changes multiple times with different filter effects, and so 'format=rgb24' is set in each filterchain for colour compatibility.]

The curves and equilisation filtering is a bit hard to explain, and due to to lack of a real time preview, somewhat "hit and miss". Basically, a 'threshold' filter is being built, where just black and white areas are created. The eq/curve filters here progressively squeeze the tones together in such a way that only the wanted areas are solid white. This will change for each project, and the shown filter chain has been progressive "hacked together" for this specific video.[N.B. 'maskedmerge' interprets tonality as levels of pixel opacity in the overlay layer]



The first 'smartblur' filter fills out (dilates) the areas to create more solid structures in the mask. The second 'smartblur' filter blends the edges of the mask to create a softer cutout. Additional 'smartblur' filters can be used on the background and on the video stream it is blended with, which will act as a noise filter to cull stray momentary differences.

The final element is a new background for the extracted elements to sit upon. In this example, a simple green matte is generated. This, along with the created mask, and original video, are are provided as input for the 'maskedmerge' filter.

There are many ways this can be implemented, adjusted, and improved. In the example above, everything is done within one filtergraph, but it can be separated out into multiple passes (this would be useful for manually fixing errors in the mask). [N.B. Timing can be an issue when running this all in a single filtergraph (where the mask layer didn't match up with the overlay). 29.97fps videos proved particularly troublesome. Repeated use of 'setpts=PTS' in filter graph might help, but it this case, it was fixed by converting the video to 25fps beforehand.]

UPDATE: 2020-05-05

There is some recurring confusion over what I wrote about stacking multiple frames for the background image. It's really not that important; it's just something to help create a more general/average background image by image stacking.





# Image stacking with FFmpeg usinf 'tmix' filter.
# More info on 'tmix' filter: https://ffmpeg.org/ffmpeg-filters.html#tmix
ffmpeg -i background-frame%d.png -vf tmix=frames=3 stacked.png
 

# Image stacking is also possible with ImageMagick
convert *.png -evaluate-sequence mean stacked.png

ffmpeg maskedmerge: https://ffmpeg.org/ffmpeg-filters.html#maskedmerge
source video: ぷに (Puni) https://www.youtube.com/watch?v=B0o8cQa-Kd8
Discussion of technique on twitter: https://twitter.com/alihaydarglc/status/982950986175209472

FFmpeg: Create a video composite of colourised macroblock motion-vectors


# Generate video motion vectors, in various colours, and merge together
# NB: Includes fixed 'curve' filters for issue outlined in blog post

ffplay \
   -flags2 +export_mvs \
   -i video.mkv \
   -vf \
      "
         split=3 [original][original1][vectors];
         [vectors] codecview=mv=pf+bf+bb [vectors];
         [vectors][original] blend=all_mode=difference128,
            eq=contrast=7:brightness=-0.3,
            split=3 [yellow][pink][black];
         [yellow] curves=r='0/0 0.1/0.5 1/1':
                         g='0/0 0.1/0.5 1/1':
                         b='0/0 0.4/0.5 1/1' [yellow];
         [pink] curves=r='0/0 0.1/0.5 1/1':
                       g='0/0 0.1/0.3 1/1':
                       b='0/0 0.1/0.3 1/1' [pink];
         [original1][yellow] blend=all_expr=if(gt(X\,Y*(W/H))\,A\,B) [yellorig];
         [pink][black] blend=all_expr=if(gt(X\,Y*(W/H))\,A\,B) [pinkblack];
         [pinkblack][yellorig]blend=all_expr=if(gt(X\,W-Y*(W/H))\,A\,B)
      "

# Process:
# 1: Three copies of input video are made
# 2: Motion vectors are applied to one stream
# 3: The result of #2 is 'difference128' blended with an original video stream
#    The brightness and contrast are adjusted to improve clarity
#    Three copies of this vectors result are made
# 4: Curves are applied to one vectors stream to create yellow colour
# 5: Curves are applied to another vectors stream to create pink colour
# 6: Original video stream and yellow vectors are combined diagonally
# 7: Pink vectors stream and original vectors stream are combined diagonally
# 8: The results of #6 and #7 are combined diagonally (opposite direction)

NB: At time of writing, the latest version of FFmpeg (N-81396-g0d8b6a1) has a bug (feature?) where upper and lower bounds of 'curves' filter must be set for accurate results. This is contrary to what's written in official documentation.

alternate version:


see related: http://oioiiooixiii.blogspot.com/2016/04/ffmpeg-display-and-isolate-macroblock.html
source video: 足太ぺんた (Asibuto Penta) https://www.youtube.com/watch?v=Djdm7NaQheU

FFmpeg: Display and isolate macroblock motion-vectors in mpeg video


# Isolate motion-vectors using 'difference128' blend filter
# - add brightness, contrast, and scaling, to taste

ffplay \
   -flags2 +export_mvs \
   -i "video.mp4" \
   -vf \
   "
      split[original],
      codecview=mv=pf+bf+bb[vectors],
      [vectors][original]blend=all_mode=difference128,
      eq=contrast=7:brightness=-0.3,
      scale=720:-2
   "

Works best with higher-resolution videos; 4K source used in this case.

more info: https://trac.ffmpeg.org/wiki/Debug/MacroblocksAndMotionVectors
source video: Czech National Ballet - https://www.youtube.com/watch?v=bn12Ffi15Go
shorter alt. version: https://www.youtube.com/watch?v=KN_c4mdBpvg

What is a Flashdance?

A flashdance happens when the Abobe Flash plugin stops responding, and your whole computer locks up. You throw the keyboard on the ground and (with much gusto) "dance" upon it shouting: "You fucking cunt! You fucking cunt!"

The Scottish "No" victory, as it happened...


And if we take a look at the Answer Prancer, we can see a definite increase of agility in the No leg...

link: https://twitter.com/oioiiooixiii/status/512804085624360960

Highland Airwaves - 15 minute loop


alt. version



The original advertisment was directed by Jonathan Gurvit and choreographed by Corinne de Beer. A tweet by the latter puts the production schedule as Jan/Feb 2013.

info: http://be.net/JonathanGurvit
info: https://twitter.com/Corinne_db/status/295220872850051072
original: http://vimeo.com/63695950

PNB's Nutcracker: The ever increasing athleticism of ballet


I had never felt inclined to watch an entire version of the Nutcracker ballet, until last December, when I happened upon a Pacific Northwest Ballet GIF animation on tumblr, and decided to source a copy of PNB's 1986 movie version, choreographed and designed by Kent Stowell and Maurice Sendak. And what a wonderful production it is. The Peacock divertissement alone, as danced by Maia Rosal, made it worth watching.

Leah Merchant's arabesque in the GIF of the modern version is stunning. One must comment however, that it does lose the context of the move representing a bird preening it's tail feathers. It is now a show piece, offering the dancer a chance to show off her technical prowess. That's not meant as a criticism by any means, but as an observation of the increasing athleticism of ballet.

I once had a blog post sketched out, which documented the increasing heights of leg extensions and the evolution of the arabesque through the centuries, and ended in a humerous envisioning of what obtuse angles the leg would take in the not too distant future.

notes:
http://oioiiooixiii.tumblr.com/post/69584518064
http://www.imdb.com/title/tt0091658/
http://www.pnb.org/Artists/Corps/LeahMerchant.aspx