Beijar Crueza Coisa

.oOo.

clips de filmes com ffmpeg

tenho um script “,clip-video” sempre disponível para fazer pequenos clips de vídeos utilzando o ffmpeg. Tal como está, exporta os clips para 720p e 30fps, sem áudio.

#!/usr/bin/env bash

validate () {
	local fn="$1"
	local ts="$2"
	local te="$3"
	local time_pattern='^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$'

	if ! [[ -e "$fn" ]]; then
		>&2 echo "ERROR - file $fn not found"
		return 1
	fi

	if ! [[ "$ts" =~ $time_pattern ]]; then
		>&2 echo "ERROR - time_start $ts not in format 00:00:00"
		return 1
	fi

	if ! [[ "$te" =~ $time_pattern ]]; then
		>&2 echo "ERROR - time_end $te not in format 00:00:00"
		return 1
	fi

	return 0
}

clip () {
	local filename directory extension path te ts
	path="$1"
	filename="${path##*/}"
	filename="${filename%.*}"
	
	ts="${2//:}"
	te="${3//:}"

	if [[ "$path" == */* ]]; then
		directory="${path%/*}"
	else
		directory="."
	fi
	extension="${path##*.}"
	ffmpeg -i "$path" -ss "$2" -to "$3" -vf 'scale=-2:720,fps=30' \
		-c:v libx264 -crf 23 -preset fast -an \
		"$directory/$filename-clip-$ts-$te.$extension"
}

usage() {
	echo
	echo "Usage:"
	echo
	echo "	,clip-video videofile time_start time_end"
	echo
	echo "		* time_start and time_end in format 00:00:00"
	echo "		* videofile can be a full path"
	echo "		* it will use ffmpeg to create a new file with the"
	echo "		* the text '-clip-time_start-time-end' appended to filename"
	echo "		  so clips are easy to find with a ls **/*clip*"
	echo
	exit 1
}


if [[ $# != 3 ]]; then
	>&2 echo "ERROR - Number of arguments is not 3"
	usage
fi

if validate "$1" "$2" "$3"; then
	clip "$1" "$2" "$3"
else
	usage
fi

Relógio de oito horas

Porque é que os relógios analógicos têm doze horas? Porque não podem ter outro número de divisões?

Estive a experimentar com outras possibilidades e o relógio de oito horas parece ser bestialmente eficaz. Tem um desenho que se assemelha a uma bússola com os seus pontos cardeais. 8 horas dividem melhor o tempo que passamos a dormir, trabalhar e em vida particular. Se calhar alguém devia fazer um relógio mecânico assim.

Mundial de futebol…

e agora para algo completamente novo, completamente original e altamente redundante:

4 jogos. 3 campeões mundiais incluindo o detentor, 4 empates (nos 90 minutos), talvez o melhor golo do mundial e um coração do tamanho do mundo.

Parabéns CABO VERDE

Escrever em que língua?

Até há muito pouco tempo (pré–IA) se alguém aspirava a ter uma audiência vasta, via-se obrigado a escrever em Inglês. Caso contrário, os seus leitores seriam mínimos, residuais. Afinal o mundo gira em Inglês.

No entanto, com o sucesso da IA moderna, o google chrome começou a traduzir automaticamente as páginas que não estavam na língua nativa do utilizador e apesar de nem sempre essa tradução ser boa, as barreiras a escrever na nossa língua mãe foram-se esbatendo. Hoje em dia, com os GPTs mais recentes, a tradução tornou-se banal. Não há mais a necessidade de forçar uma escrita, naturalmente limitada e menos expressiva, numa língua não nativa, quando se pode tirar partido da nossa língua natural e deixar para os tradutores robóticos uma tarefa que fazem já muito bem.

Assim, sem promessas, e sem pensar muito no assunto, talvez escrevam mais em português. Afinal há tantos robôs por aí que talvez lhes possa ensinar uma coisa ou duas.

A IA não pode ser considerada “inventor”, segundo o Japão, e se calhar também segundo o bom senso, não? https://japannews.yomiuri.co.jp/science-nature/technology/20260306-314930/

Typesetting software

Desktop Publishing Software

Playing with zim files

Vibe coding, or the assisted coding, as some prefer to say, has become a brilliant way to tinker with code that other way would be out of reach (either because of lack of skill, or time, or pure laziness). It allows anyone to produce runnable code for simple common tasks without relying on other peoples code. Bespoke solutions for single problems. This has been very clear to me recently with openZim.

Zim files are a files that hold entire websites for offline viewing. Originally thought as a way to have Wikipedia save to disk (all 115GB of it, and brilliantly I’ll say), they could be used for other websites too… Hm…

“Could I offer a ZIM file of sixhat.net”

Sure I can, but what if, instead of finding someone else’s code, I simply coded my little tool? Yes, that’s what I/it vibe coded. Asked deepseek to code zim-maker so I could create sixhat.zim every time I post something. Don’t have the time to research the full zim format, to think of an architecture for this tool, or to even think about the time I’d be spending coding this. All of that would put me off. With vibe coding, this was a two hour session (mixed with other important stuff). In the end I have a tool that I can use.

Is it complete? Yes, for what need. Does it have RANDOM FEATURE. Probably not. It is probably full of bugs then? Yes, but the attack space and victims are very limited. Are you releasing the code? Why? If it is mostly code generated by AI? I might send copies to anyone that asks but why publish this online?

You can do the same thing in a couple of hours and a free AI agent. Don’t go and run other people’s code. People that you only met through reading a blog post are not a trustworthy source of anything, least code.

ZIM Readers

If you want a ZIM reader (besides coding your own, with or without AI) you can use one from the openZIM readers list.

On the mac I use Kiwix (just because I’m lazy) and there’s also a version for Android.

Interesting quirks of P5js random number generator

function draw() {
    randomSeed(frameCount);
    console.log(random());
}

This is a really interesting piece of code. Try it online.

=> https://editor.p5js.org/sixhat/sketches/WRBChpIXz

See the interesting thing? The random numbers generated are growing sequentially.

This is a side effect of using a Linear Congruent Generator. The random seed just applies the value of the seed sequentially and as the seeds are close enough, the resulting random numbers are also close to each other.

Curiously, if the user doesn’t use the randomSeed function the PRNG still sets a seed given by Math.random() * 2**32. And as Math.random() is not possible to seed…

=> https://github.com/processing/p5.js/blob/v2.2.3/src/math/random.js#L30

The solution for your sketch is not to use randomSeed with close seeds. Always multiply them with a big constant. In the previous example, multiplying frameCount by 2**16 will spread the seeds so the resulting random numbers at least don’t seem so sequential.

function draw() {
    randomSeed(frameCount * 2**16 );
    console.log(random());
}

Why do you need this? Probably you don’t need to set different seeds like this, but if you are trying to do something based on the current time (let’s say using the second() as your seed, so you have changing random values each second) then you’ll have the unpleasant surprise that it doesn’t behave randomly. For this if using second() as seed, multiply it with a big constant (eg. 1<<16).

A suggestion to p5js would be to implement a hashing algorithm to the seed value in the above example.

Playing with RAM monitors

Wrote (with AI) the same mini ram monitor CLI and the results are very interesting in terms of memory usage:

GO 14. MB Rust 9. MB C 1.2 MB

For reference, htop usually uses 9.MB in my machine.

In the age of AI, one can really build his own tools, tailored for one user. Something bespoke, and quick.

=> https://medium.com/@NMitchem/if-ai-writes-your-code-why-use-python-bf8c4ba1a055 If AI Writes Your Code, Why Use Python?

=> https://www.youtube.com/watch?v=nepKKz-MzFM FFMpeg Jean-Baptiste Kempf and Kieran Kunhya explain why EVERY CYCLE MATTERS. GREAT #FFmpeg #programming

In the age of AI fights

A  t  i  n  i  l  l  s

W  a     o  i     w  l     e     o  e     r  t  n  a     e  g  s     o  r  n
m  e     m  g  o  e  a     o     m  s  i     e  e  r  e  l  s  a  i  s  H  a
w  l  i  t  a  ,  t  y  r  a  e  y  t  t  g  t  f  h  b  k  D  a  P  s
o  i  .  M  e  c  p  n     s  r  i  l     a     r  p  g  e  e  i  .  o  e  t
c  p  i     a  i        u  d  a  o  o  x  a  o  .  h        w     t  e  h  a
a     l  s  n  t     s  t  d  i        t  e  a  G  a  c     r  w  c  d  n
j  p  v  y  3  i  t  ?
 I  r  n  g  s  a  e  .

 e  r     w  n  a  o  d  w  r  p  p  ’     e  i  s  r     i     e        a
 o  l  a  i        p  c  t  s  h  a     t  c  a  r  e  n  e     c  n  .  u  n
 i     g     c     h     e  l  a     a  i     o  i  t  a  .  a     o  o  i  a
 p  o     a     r  p  g  l  s  e  a  e     k  s  a  i     x  n  v     r     h
 o  a  e  t  i  n  o  y  r  a           t     r     i  i  a  a  b  w  n  u  n
 n  c  o        h  b  t  r  i  o  o  B  t  S  r  a  t  a     e  e  o  e  e  t
 u     e        n  e
     a  i        w  s

     e  n           r     h  e  e  l  s  c  a  o     e  b  n  u  d  t  t  i
  d  s  i  n  t  r  l  e  h  e  u  n  w  h  h  p     l  t  s  m  h  e     m  s
  l  f  h  b  k     e  a     r  d  s  r  n        g     c     t     i  n  s  n
  t  n     k  s  a  i     e     l  b  ,  m  e  c  p  n     p  s  e  F  c     e
  m  n  s  r  n  g  n  o     t  t  d  e  r  w  k  T  s  s     r  e  e     m  s
  d  y  n  i     e  e     a  t  n  f  a  l  t     l  i  .  A        n  m  d  o
  m  e  r  3  m  u  s

Computer Vision Courses online

=> https://www.youtube.com/playlist?list=PLCEC78997E3E2DAB4 Coding & Vision 101

=> https://see.stanford.edu/Course/CS223A CS223A - Introduction to Robotics

=> https://ocw.mit.edu/courses/6-034-artificial-intelligence-fall-2010/ Not Vision, but AI.

Illusions, illusions

Many interesting optical illusions / visual phenomena, coded by Professor Michael Bach. Many have high pedagogical value for computer vision topics.

=> https://michaelbach.de/index.html

=> https://michaelbach.de/ot/index.html

Playing with Voronoi

=> https://www.jasondavies.com/maps/voronoi/ Very interesting 3D visualizations

=> https://www.youtube.com/watch?v=Bxdt6T_1qgc Coding Train…

=> https://paulbourke.net/ Paul Bourke website - fantastic math and geometry website.

.oOo.