FFglitch 0.9.4 released
FFglitch 0.9.4 has been released.
Python3
The main change in this version is the addition of python3
scripting
support. This way you don’t need to use the old three-step method of
export
/glitch
/apply
for your Python scripts anymore. It can all
be done in one go, just like it was already possible with javascript
since version 0.9.1.
For example, the
Simple motion vector tutorial
in python3
would be:
def glitch_frame(frame):
# bail out if we have no motion vectors
if not "mv" in frame:
return
# bail out if we have no forward motion vectors
if not "forward" in frame["mv"]:
return
fwd_mvs = frame["mv"]["forward"]
# loop through all rows
for row in fwd_mvs:
# loop through all macroblocks
for mv in row:
# clear horizontal element of all motion vectors
# THIS IS WHERE THE MAGIC HAPPENS
mv[0] = 0; # this sets the horizontal motion vector to zero
# mv[1] = 0; # you could also change the vertical motion vector
$ ./ffedit -i temp_file.mpg -f mv -s mv_sink_and_rise.py -o glitched_file.mpg
NOTE: You have to install Python3 yourself! Get it from their website: https://www.python.org/downloads/.
Script video filter
A script video filter has been added, supporting both JavaScript and
Python, so that you can edit the pixels of a video programmatically.
You can chain the filter on top of an existing video or create a video
from scratch.
For example, create this file named uv.py
:
def filter(args):
data = args["data"]
# planes are [ Y, U, V ]
for p, plane in enumerate(data):
# skip plane Y
if p == 0:
continue
# for planes U and V, draw a color plane
for i, row in enumerate(plane):
for j in range(len(row)):
if p == 1:
row[j] = j+j
else:
row[j] = 254-(i+i)
and then run it on top of the testsrc2
video source from FFmpeg
:
$ ffgac -f lavfi -i "testsrc2=duration=10:size=256x256" -vf script="py=uv.py" -q 0 -y testsrc2_uv.mp4
and you’ll end up with this nice video:
Motion Vector Delta Feature
Motion vectors values are composed of a pred
iction part and a
delta
part, which is the value that is written to the bitstream.
A new feature named "mv_delta"
has been added to ffedit, which
allows you to fiddle with only those delta
values for both
MPEG-2
and MPEG-4
.
There is no example for this feature for now. This is left as an exercise for the reader.
Motion Vector Overflow
There is now greater control on how ffedit
should behave when it
encounters an overflow in either the "mv"
or the "mv_delta"
features.
Three more values are exported, namely "fcode"
, "bcode"
and "overflow"
.
The first two are for information purposes only and allow you to calculate
the min and max values for your motion vectors if you wish.
For MPEG-2
the values go from -(1<<(fcode+3))
to (1<<(fcode+3))-1
,
and for MPEG-4
the values go from -(1<<(fcode+4))
to (1<<(fcode+4))-1
,
which, for an fcode
of 1
, would range from [-16, 15]
for MPEG-2
and [-32, 31]
for MPEG-4
(keep in mind that those are half-pel values).
The "overflow"
field tells ffedit
how to behave when it encounters
an overflow while transplicating a file. The four possible values are
as follows:
frame["mv"]["overflow"] = "assert"; // quits ffedit on overflow
frame["mv"]["overflow"] = "truncate"; // truncates values within range for given fcode
frame["mv"]["overflow"] = "ignore"; // just ignore the overflow - same behaviour as versions before 0.9.4
frame["mv"]["overflow"] = "warn"; // ignore, like above, but also write a warning message - new default behaviour
I’m too lazy to write an example for now. This is also left as an exercise for the reader.
ffglitch.js
A new executable called qjs
(or qjs.exe
for Windows) has been added
to the release bundle, along with a new file ffglitch.js
. qjs
is the
quickjs command-line interpreter. It can
be used to test your .js
scripts. ffglitch.js
It works similarly to
ffglitch.py
, but for javascript
files. To use it, run something like:
$ ./qjs ffglitch.js -i mv.json -s mv_sink_and_rise.js -o mv_glitched.json
More changes
- Speedup exporting of JSON data by up to 40%
- Speedup importing of JSON data by up to 80%
- Added
"macroblock"
feature toMPEG-4
(works the same way as it did forMPEG-2
) - Fixed
-dqt
option for non-mjpeg (broken in0.9.3
) - Updated quickjs to quickjs-2021-03-27
My build system has changed
I now have a mac mini running Mojave and I build the macos version there. If it doesn’t run on older versions of macos please let me know and I’ll try to figure out a way to fix it.
The linux build no longer uses musl, but is built on a CentOS 7 image, which should run correctly on most modern distros.
Get it in the Download page.