k4d3 commited on
Commit
6f44ddc
1 Parent(s): 125b361

png2mp4 fun

Browse files

Signed-off-by: Balazs Horvath <acsipont@gmail.com>

Files changed (1) hide show
  1. zsh/png2mp4.zsh +12 -12
zsh/png2mp4.zsh CHANGED
@@ -27,6 +27,8 @@ png2mp4_x265() {
27
  conda deactivate
28
  local step_multiplier=1
29
  local repeat=1
 
 
30
 
31
  while [[ "$#" -gt 0 ]]; do
32
  case $1 in
@@ -39,29 +41,27 @@ png2mp4_x265() {
39
  output_filename="$(basename "$(pwd)")_x265.mp4"
40
  echo "Output filename: $output_filename"
41
 
42
-
43
  local nframes=$(find . -type f -name '*.png' | wc -l)
44
- local duration=$(($nframes * $repeat / 60.))
45
  local fade_start=$((duration + 3))
46
  echo "Found $nframes for a duration of $duration seconds"
47
 
48
-
49
  echo "Running ffmpeg with x265 encoding..."
50
  local font=/usr/share/fonts/TTF/Inconsolata-Light.ttf
51
  local drawtext="drawtext=fontfile=${font}:text='Steps\: %{eif\\:trunc(n*$step_multiplier)\\:u\\:3}':x=10:y=h-th-10:fontsize=24:fontcolor=white"
52
  local fadeout="tpad=stop_mode=clone:stop_duration=8,fade=t=out:st=${fade_start}:d=5"
53
- local output_preset=(
54
- -c:v libx265
55
- -preset slower -tune animation
56
- -g $repeat
57
  -pix_fmt yuv420p
58
- -x265-params "crf=20:qcomp=0.8:aq-mode=3:aq-strength=0.8:deblock=-1,-1"
 
 
 
 
59
  )
60
 
61
- ffmpeg -framerate "60/$repeat" -pattern_type glob -i "*.png" -r 60 -vf "scale=1024x1024,${drawtext},${fadeout}"\
62
- -c:v ffv1 -f matroska - | ffmpeg -f matroska -i - \
63
- -vf "$fadeout" "${output_preset[@]}" -y output.mp4
64
-
65
  if [ $? -ne 0 ]; then
66
  echo "Error: ffmpeg command failed."
67
  return 1
 
27
  conda deactivate
28
  local step_multiplier=1
29
  local repeat=1
30
+ local frame_rate=60
31
+ local resolution="1024x1024"
32
 
33
  while [[ "$#" -gt 0 ]]; do
34
  case $1 in
 
41
  output_filename="$(basename "$(pwd)")_x265.mp4"
42
  echo "Output filename: $output_filename"
43
 
 
44
  local nframes=$(find . -type f -name '*.png' | wc -l)
45
+ local duration=$(($nframes * $repeat / ${frame_rate}.))
46
  local fade_start=$((duration + 3))
47
  echo "Found $nframes for a duration of $duration seconds"
48
 
 
49
  echo "Running ffmpeg with x265 encoding..."
50
  local font=/usr/share/fonts/TTF/Inconsolata-Light.ttf
51
  local drawtext="drawtext=fontfile=${font}:text='Steps\: %{eif\\:trunc(n*$step_multiplier)\\:u\\:3}':x=10:y=h-th-10:fontsize=24:fontcolor=white"
52
  local fadeout="tpad=stop_mode=clone:stop_duration=8,fade=t=out:st=${fade_start}:d=5"
53
+ local encoder=(
 
 
 
54
  -pix_fmt yuv420p
55
+ -c:v libx265
56
+ -preset slower
57
+ -tune animation
58
+ -crf 22
59
+ -x265-params "keyint=${repeat}:min-keyint=$((repeat-1)):scenecut=0:ref=5:bframes=8:b-adapt=2:rc-lookahead=$((2*repeat)):lookahead-slices=4:aq-mode=3:aq-strength=0.8:deblock=-1,-1:sao=0"
60
  )
61
 
62
+ ffmpeg -framerate "$frame_rate/$repeat" -pattern_type glob -i "*.png" \
63
+ -vf "scale=${resolution},${drawtext},fps=${frame_rate},${fadeout}" \
64
+ "${encoder[@]}" -y sample_x265.mp4
 
65
  if [ $? -ne 0 ]; then
66
  echo "Error: ffmpeg command failed."
67
  return 1