k4d3 commited on
Commit
e46473f
1 Parent(s): 13bc041

Signed-off-by: Balazs Horvath <[email protected]>

Files changed (2) hide show
  1. .zshrc +1 -78
  2. zsh/png2mp4.zsh +125 -7
.zshrc CHANGED
@@ -913,80 +913,7 @@ filePath = '$filePath'
913
  print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found')))"
914
  }
915
 
916
- # Function: png2mp4
917
- # Description:
918
- # This function converts a series of PNG images into an MP4 video file using ffmpeg.
919
- #
920
- # Usage:
921
- # png2mp4 [--max <number>]
922
- #
923
- # Parameters:
924
- # --max <number> (optional): Stops the video at the specified number of images.
925
- #
926
- # Actions:
927
- # 1. Sets the frame rate to 8 fps
928
- # 2. Uses glob pattern to include all PNG files in the current directory
929
- # 3. Optionally limits the number of input images based on the --max argument
930
- # 4. Scales the output video to 1024x1024 resolution
931
- # 5. Sets the Constant Rate Factor (CRF) to 28 for good compression
932
- # 6. Uses the libx264 codec for H.264 encoding
933
- # 7. Sets the pixel format to yuv420p for compatibility
934
- # 8. Outputs the result as 'out.mp4' in the current directory
935
- #
936
- # Notes:
937
- # - Requires ffmpeg to be installed and accessible in the system path
938
- # - PNG files should be in the current directory
939
- # - Output video will be named 'out.mp4' and placed in the current directory
940
- # - Adjust the framerate, scale, or CRF value as needed for different results
941
- # - Use the --max argument to limit the number of input images
942
- png2mp4() {
943
- conda deactivate
944
- local max_images=""
945
- local step_multiplier=1
946
- local prefix=""
947
- local repeat=1
948
- local temp_dir="/home/kade/.local/tmp"
949
-
950
- while [[ "$#" -gt 0 ]]; do
951
- case $1 in
952
- --max) max_images="$2"; shift ;;
953
- --step) step_multiplier="$2"; shift ;;
954
- --repeat) repeat="$2"; shift ;;
955
- *) echo "Unknown parameter passed: $1"; return 1 ;;
956
- esac
957
- shift
958
- done
959
-
960
- mkdir -p "$temp_dir"
961
-
962
- # Extract the prefix from the first image filename
963
- prefix=$(/usr/bin/env ls *.png | head -n 1 | cut -d'-' -f1 | tr -d '[:cntrl:]' | tr -d '[]')
964
-
965
- # Create repeated images
966
- for img in *.png; do
967
- for i in $(seq 1 $repeat); do
968
- cp "$img" "$temp_dir/${img%.*}_${i}.png"
969
- done
970
- done
971
-
972
- if [[ -n "$max_images" ]]; then
973
- ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,select='not(mod(n\,$max_images))',drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" -crf 28 \
974
- -c:v libx264 -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
975
- else
976
- ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" -crf 28 \
977
- -c:v libx264 -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
978
- fi
979
-
980
- # Add 3 seconds of the last frame, then 5 seconds delay, and then fade out smoothly for 5 seconds
981
- duration=$(ffmpeg -i "$temp_dir/temp.mp4" 2>&1 | grep 'Duration' | awk '{print $2}' | tr -d , | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}')
982
- fade_start=$(echo "$duration + 3" | bc)
983
- ffmpeg -i "$temp_dir/temp.mp4" -vf "tpad=stop_mode=clone:stop_duration=8,fade=t=out:st=$fade_start:d=5" -c:v libx264 -pix_fmt yuv420p -y "${prefix}.mp4"
984
-
985
- # Clean up temporary files
986
- rm -rf "$temp_dir"
987
-
988
- conda activate
989
- }
990
 
991
  # Function: c
992
  # Description:
@@ -1022,10 +949,6 @@ c() {
1022
  conda activate comfyui
1023
  python main.py --listen 0.0.0.0 --preview-method taesd --use-pytorch-cross-attention --disable-xformers --front-end-version Comfy-Org/ComfyUI_frontend@latest --fast
1024
  }
1025
-
1026
- # Function: conda_prompt_info
1027
- # Description:
1028
- # This function displays information about the currently active Conda environment.
1029
  #
1030
  # Usage:
1031
  # conda_prompt_info
 
913
  print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found')))"
914
  }
915
 
916
+ source ~/toolkit/zsh/png2mp4.zsh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
917
 
918
  # Function: c
919
  # Description:
 
949
  conda activate comfyui
950
  python main.py --listen 0.0.0.0 --preview-method taesd --use-pytorch-cross-attention --disable-xformers --front-end-version Comfy-Org/ComfyUI_frontend@latest --fast
951
  }
 
 
 
 
952
  #
953
  # Usage:
954
  # conda_prompt_info
zsh/png2mp4.zsh CHANGED
@@ -1,8 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  png2mp4() {
2
  conda deactivate
3
  local max_images=""
4
  local step_multiplier=1
5
- local prefix=""
6
  local repeat=1
7
  local temp_dir="/home/kade/.local/tmp"
8
 
@@ -26,9 +144,9 @@ png2mp4() {
26
  return 1
27
  fi
28
 
29
- echo "Extracting prefix..."
30
- prefix=$(echo "${png_files[0]}" | cut -d'-' -f1 | tr -d '[:cntrl:]' | tr -d '[]')
31
- echo "Prefix: $prefix"
32
 
33
  echo "Creating repeated images..."
34
  for img in "${png_files[@]}"; do
@@ -39,10 +157,10 @@ png2mp4() {
39
 
40
  echo "Running ffmpeg..."
41
  if [[ -n "$max_images" ]]; then
42
- ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,select='not(mod(n\,$max_images))',drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" -crf 28 \
43
  -c:v libx264 -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
44
  else
45
- ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" -crf 28 \
46
  -c:v libx264 -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
47
  fi
48
 
@@ -55,7 +173,7 @@ png2mp4() {
55
  echo "Processing final video..."
56
  duration=$(ffmpeg -i "$temp_dir/temp.mp4" 2>&1 | grep 'Duration' | awk '{print $2}' | tr -d , | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}')
57
  fade_start=$(echo "$duration + 3" | bc)
58
- ffmpeg -i "$temp_dir/temp.mp4" -vf "tpad=stop_mode=clone:stop_duration=8,fade=t=out:st=$fade_start:d=5" -c:v libx264 -pix_fmt yuv420p -y "${prefix}.mp4"
59
 
60
  if [ $? -ne 0 ]; then
61
  echo "Error: Final ffmpeg processing failed."
 
1
+ # png2mp4_x265()
2
+ # Converts a series of PNG images to an MP4 video using x265 encoding
3
+ #
4
+ # Usage: png2mp4_x265 [--max <number>] [--step <number>] [--repeat <number>]
5
+ #
6
+ # Options:
7
+ # --max <number> : Maximum number of images to process
8
+ # --step <number> : Multiplier for step count in overlay text (default: 1)
9
+ # --repeat <number> : Number of times to repeat each image (default: 1)
10
+ #
11
+ # This function:
12
+ # 1. Deactivates conda environment
13
+ # 2. Creates a temporary directory for processing
14
+ # 3. Finds all PNG files in the current directory
15
+ # 4. Uses the current directory name as the output filename prefix
16
+ # 5. Copies and optionally repeats images to the temp directory
17
+ # 6. Uses ffmpeg to create an MP4 with x265 encoding, including:
18
+ # - Frame rate of 60 fps
19
+ # - Image scaling to 1024x1024
20
+ # - Step count overlay text (divided by 1,000,000 to remove 6 zeros)
21
+ # - High-quality encoding settings
22
+ # 7. Adds padding and fade-out effect to the final video
23
+ # 8. Cleans up temporary files
24
+ # 9. Reactivates conda environment
25
+ #
26
+ # Requirements:
27
+ # - ffmpeg with libx265 support
28
+ # - bc (basic calculator)
29
+ # - Inconsolata-Light.ttf font in /usr/share/fonts/TTF/
30
+ png2mp4_x265() {
31
+ conda deactivate
32
+ local max_images=""
33
+ local step_multiplier=1
34
+ local repeat=1
35
+ local temp_dir="/home/kade/.local/tmp"
36
+ while [[ "$#" -gt 0 ]]; do
37
+ case $1 in
38
+ --max) max_images="$2"; shift ;;
39
+ --step) step_multiplier="$2"; shift ;;
40
+ --repeat) repeat="$2"; shift ;;
41
+ *) echo "Unknown parameter passed: $1"; return 1 ;;
42
+ esac
43
+ shift
44
+ done
45
+ echo "Creating temporary directory..."
46
+ mkdir -p "$temp_dir"
47
+ echo "Checking for PNG files..."
48
+ png_files=($(/usr/bin/env ls *.png 2>/dev/null))
49
+ if [ ${#png_files[@]} -eq 0 ]; then
50
+ echo "Error: No PNG files found in the current directory."
51
+ return 1
52
+ fi
53
+ echo "Setting output filename..."
54
+ output_filename="$(basename "$(pwd)")_x265.mp4"
55
+ echo "Output filename: $output_filename"
56
+ echo "Creating repeated images..."
57
+ for img in "${png_files[@]}"; do
58
+ for i in $(seq 1 $repeat); do
59
+ cp "$img" "$temp_dir/${img%.*}_${i}.png"
60
+ done
61
+ done
62
+ echo "Running ffmpeg with x265 encoding..."
63
+ if [[ -n "$max_images" ]]; then
64
+ ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,select='not(mod(n\,$max_images))',drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat/1000000)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" \
65
+ -c:v libx265 -preset slower -x265-params "crf=18:qcomp=0.8:aq-mode=3:aq-strength=0.8:deblock=-1,-1" -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
66
+ else
67
+ ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat/1000000)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" \
68
+ -c:v libx265 -preset slower -x265-params "crf=18:qcomp=0.8:aq-mode=3:aq-strength=0.8:deblock=-1,-1" -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
69
+ fi
70
+ if [ $? -ne 0 ]; then
71
+ echo "Error: ffmpeg command failed."
72
+ rm -rf "$temp_dir"
73
+ return 1
74
+ fi
75
+ echo "Processing final video..."
76
+ duration=$(ffmpeg -i "$temp_dir/temp.mp4" 2>&1 | grep 'Duration' | awk '{print $2}' | tr -d , | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}')
77
+ fade_start=$(echo "$duration + 3" | bc)
78
+ ffmpeg -i "$temp_dir/temp.mp4" -vf "tpad=stop_mode=clone:stop_duration=8,fade=t=out:st=$fade_start:d=5" \
79
+ -c:v libx265 -preset slower -x265-params "crf=18:qcomp=0.8:aq-mode=3:aq-strength=0.8:deblock=-1,-1" -pix_fmt yuv420p -y "$output_filename"
80
+ if [ $? -ne 0 ]; then
81
+ echo "Error: Final ffmpeg processing failed."
82
+ rm -rf "$temp_dir"
83
+ return 1
84
+ fi
85
+ echo "Cleaning up temporary files..."
86
+ rm -rf "$temp_dir"
87
+ conda activate
88
+ echo "Process completed successfully."
89
+ }
90
+
91
+ # png2mp4()
92
+ # Converts a series of PNG images to an MP4 video using x264 encoding
93
+ #
94
+ # Usage: png2mp4 [--max <number>] [--step <number>] [--repeat <number>]
95
+ #
96
+ # Options:
97
+ # --max <number> : Maximum number of images to process
98
+ # --step <number> : Multiplier for step count in overlay text (default: 1)
99
+ # --repeat <number> : Number of times to repeat each image (default: 1)
100
+ #
101
+ # This function:
102
+ # 1. Deactivates conda environment
103
+ # 2. Creates a temporary directory for processing
104
+ # 3. Finds all PNG files in the current directory
105
+ # 4. Uses the current directory name as the output filename prefix
106
+ # 5. Copies and optionally repeats images to the temp directory
107
+ # 6. Uses ffmpeg to create an MP4 with x264 encoding, including:
108
+ # - Frame rate of 60 fps
109
+ # - Image scaling to 1024x1024
110
+ # - Step count overlay text (divided by 1,000,000 to remove 6 zeros)
111
+ # - CRF value of 28 for compression
112
+ # 7. Adds padding and fade-out effect to the final video
113
+ # 8. Cleans up temporary files
114
+ # 9. Reactivates conda environment
115
+ #
116
+ # Requirements:
117
+ # - ffmpeg with libx264 support
118
+ # - bc (basic calculator)
119
+ # - Inconsolata-Light.ttf font in /usr/share/fonts/TTF/
120
  png2mp4() {
121
  conda deactivate
122
  local max_images=""
123
  local step_multiplier=1
 
124
  local repeat=1
125
  local temp_dir="/home/kade/.local/tmp"
126
 
 
144
  return 1
145
  fi
146
 
147
+ echo "Setting output filename..."
148
+ output_filename="$(basename "$(pwd)").mp4"
149
+ echo "Output filename: $output_filename"
150
 
151
  echo "Creating repeated images..."
152
  for img in "${png_files[@]}"; do
 
157
 
158
  echo "Running ffmpeg..."
159
  if [[ -n "$max_images" ]]; then
160
+ ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,select='not(mod(n\,$max_images))',drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat/1000000)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" -crf 28 \
161
  -c:v libx264 -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
162
  else
163
+ ffmpeg -framerate 60 -pattern_type glob -i "$temp_dir/*.png" -vf "scale=1024x1024,drawtext=fontfile=/usr/share/fonts/TTF/Inconsolata-Light.ttf:text='Steps\: %{expr\:trunc(n*$step_multiplier/$repeat/1000000)}':x=10:y=h-th-10:fontsize=24:fontcolor=white" -crf 28 \
164
  -c:v libx264 -pix_fmt yuv420p -y "$temp_dir/temp.mp4"
165
  fi
166
 
 
173
  echo "Processing final video..."
174
  duration=$(ffmpeg -i "$temp_dir/temp.mp4" 2>&1 | grep 'Duration' | awk '{print $2}' | tr -d , | awk -F: '{print ($1 * 3600) + ($2 * 60) + $3}')
175
  fade_start=$(echo "$duration + 3" | bc)
176
+ ffmpeg -i "$temp_dir/temp.mp4" -vf "tpad=stop_mode=clone:stop_duration=8,fade=t=out:st=$fade_start:d=5" -c:v libx264 -pix_fmt yuv420p -y "$output_filename"
177
 
178
  if [ $? -ne 0 ]; then
179
  echo "Error: Final ffmpeg processing failed."