From a30d678c082c0f196d76a313a9938ce8c75a7dde Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sun, 7 Jul 2024 18:24:13 +0200 Subject: [PATCH] Various updates --- src/center_video.cpp | 177 ---------------------------------------- src/images_to_video.sh | 6 +- src/mscz_to_mp3.py | 2 + src/recording.sh | 6 -- src/superpose_audios.sh | 3 +- 5 files changed, 7 insertions(+), 187 deletions(-) delete mode 100644 src/center_video.cpp delete mode 100755 src/recording.sh diff --git a/src/center_video.cpp b/src/center_video.cpp deleted file mode 100644 index b8f2c5f..0000000 --- a/src/center_video.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include - -#define WIDTH 1920 -#define HEIGHT 1080 -#define ACCEPTED_BLANK 20 -#define ACCEPTED_NON_BG 10 -#define SHOW_PROGRESS - -using namespace std; - -cv::Scalar backgroundColor(255, 255, 255); -cv::Scalar blue(249, 0, 0); - - -bool is_background (const cv::Vec3b& pixel) { - // Upper bound: 195075 - return abs((pixel[0] - backgroundColor[0])*(pixel[1] - backgroundColor[1])*(pixel[2] - backgroundColor[2])) < 5000; -}; - -cv::Rect get_pos(const cv::Mat& frame) { - bool no_break = true; - int left_margin = -1; - int right_margin = -1; - - for (int i=0; i < frame.cols; i++) { - bool contains_non_white = false; - for (int j=0; j < frame.rows; j++) { - int non_bg = 0; - if (!is_background(frame.at(j, i))) { - contains_non_white = true; - break; - } - } - - if (no_break && !contains_non_white) { - left_margin += 1; - } else if (contains_non_white) { - no_break = false; - } - - if (contains_non_white) { - right_margin = i+1; - } - } - - right_margin = min(right_margin, frame.cols-1); - - // Iterate over the lines and find the tallest block of non-white lines, this will give us - // the vertical size of the rectangle, i.e the top and bottom margins - int top_margin = -1; - int bottom_margin = -1; - int max_height = 0; - - int cur_height = -1; - int cur_top_margin = 0; - - int echecs = 0; - - for (int i=0; i < frame.rows; i++) { - bool contains_non_white = false; - int non_bg = 0; - for (int j=0; j < frame.cols; j++) { - if (!is_background(frame.at(i, j))) { - if (++non_bg >= ACCEPTED_NON_BG) { - contains_non_white = true; - break; - } - } - } - - if (!contains_non_white) { - if (++echecs >= ACCEPTED_BLANK) { - if (cur_height >= max_height) { - max_height = cur_height; - top_margin = cur_top_margin; - bottom_margin = cur_top_margin + cur_height; - } - - cur_height = -1; - } - } else { - cur_height += 1; - if (cur_height == 0) { - cur_top_margin = i; - } - echecs = 0; - } - } - - if (cur_height >= max_height) { - max_height = cur_height; - top_margin = cur_top_margin; - bottom_margin = cur_top_margin + cur_height; - } - - //cout << "top: " << top_margin << ", bottom: " << bottom_margin << ", height: " << max_height << endl; - bottom_margin = min(bottom_margin, frame.rows-1); - - - cv::Rect rect = cv::Rect(left_margin, top_margin, right_margin-left_margin, bottom_margin-top_margin); - // Return a rectangle covering all the frame except the left margin - //cv::Rect rect = cv::Rect(left_margin, 0, right_margin-left_margin, frame.rows-1); - //cout << rect << endl; - return rect; -} - -int main(int argc, char** argv) { - if (argc != 3) { - cerr << "Usage: " << argv[0] << " " << endl; - return 1; - } - - // Open the input video file - cv::VideoCapture inputVideo(argv[1]); - if (!inputVideo.isOpened()) { - cerr << "Error: Could not open input video file." << endl; - return 1; - } - - // Get input video properties - int inputWidth = inputVideo.get(cv::CAP_PROP_FRAME_WIDTH); - int inputHeight = inputVideo.get(cv::CAP_PROP_FRAME_HEIGHT); - int totalFrames = static_cast(inputVideo.get(cv::CAP_PROP_FRAME_COUNT)); - - // Create video writer for the output video - cv::VideoWriter outputVideo(argv[2], cv::VideoWriter::fourcc('X', '2', '6', '4'), inputVideo.get(cv::CAP_PROP_FPS), - cv::Size(WIDTH, HEIGHT), true); - - if (!outputVideo.isOpened()) { - cerr << "Error: Could not open output video file for writing." << endl; - return 1; - } - - // Process each frame - cv::Mat frame; - int currentFrame = 0; - int last_progress = -1; - while (inputVideo.read(frame)) { - // Get the rectangle to keep using the get_pos function - cv::Rect roi = get_pos(frame); - - cv::Mat resizedFrame(HEIGHT, WIDTH, frame.type(), blue); - frame(roi).copyTo(resizedFrame(cv::Rect((WIDTH - roi.width) / 2, (HEIGHT - roi.height) / 2, roi.width, roi.height))); - - // Write the modified frame to the output video - outputVideo.write(resizedFrame); - - // Update and display progress bar - currentFrame++; - - #ifdef SHOW_PROGRESS - float progress = static_cast(currentFrame) / totalFrames; - int barWidth = 50; - int pos = static_cast(barWidth * progress); - - int progress_percent = static_cast(progress * 100.0); - if (progress_percent != last_progress) { - cout << "["; - for (int i = 0; i < barWidth; ++i) { - if (i < pos) cout << "="; - else if (i == pos) cout << ">"; - else cout << " "; - } - cout << "] " << int(progress * 100.0) << "% " << roi << "\r"; - cout.flush(); - } - #endif - } - - // Release video capture and writer objects - inputVideo.release(); - outputVideo.release(); - - cout << "Video processing complete. Output saved to: " << argv[2] << endl; - - return 0; -} diff --git a/src/images_to_video.sh b/src/images_to_video.sh index 9979313..b2f40c3 100755 --- a/src/images_to_video.sh +++ b/src/images_to_video.sh @@ -15,8 +15,8 @@ echo $WIDTH x $HEIGHT # Center all the images and pad them to the larger width and height # Set the border color to the dominant color of the image for f in $FILES; do - BORDER_COLOR=$(convert $f -format "%[pixel:p{0,0}]" info:) + BORDER_COLOR=$(magick $f -format "%[pixel:p{0,0}]" info:) + #BORDER_COLOR="srgb(255,255,255)" echo "Border color: $BORDER_COLOR" - # BORDER_COLOR="srgb(255,255,255)" - convert $f -gravity center -background none -extent ${WIDTH}x${HEIGHT} -bordercolor $BORDER_COLOR -border 0x0 $f + magick $f -gravity center -background none -extent ${WIDTH}x${HEIGHT} -bordercolor $BORDER_COLOR -border 0x0 $f done \ No newline at end of file diff --git a/src/mscz_to_mp3.py b/src/mscz_to_mp3.py index 2c3e4e7..3864d61 100644 --- a/src/mscz_to_mp3.py +++ b/src/mscz_to_mp3.py @@ -121,6 +121,8 @@ if __name__ == "__main__": instrument = music21.instrument.Piano() case "organ": instrument = music21.instrument.Organ() + case "electric_organ": + instrument = music21.instrument.ElectricOrgan() case "flute": instrument = music21.instrument.Flute() case _: diff --git a/src/recording.sh b/src/recording.sh deleted file mode 100755 index 3fcbf42..0000000 --- a/src/recording.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -SURFACE=$(slurp) - -sleep 5 -wlrctl pointer click -wf-recorder -g "$SURFACE" \ No newline at end of file diff --git a/src/superpose_audios.sh b/src/superpose_audios.sh index a24488e..dbdf47d 100755 --- a/src/superpose_audios.sh +++ b/src/superpose_audios.sh @@ -3,6 +3,7 @@ AUDIOS=out BASE_NAME="instrument_" BASE_OUT_NAME="combined_" +VOLUME_1="1.5" VOLUME_2="0.3" ADDITIONAL=$1 @@ -19,7 +20,7 @@ combine () { -i $1 \ -i $2 \ -filter_complex \ - "[0:a]volume=1.0[a1];[1:a]volume=${VOLUME_2}[a2];[a1][a2]amix=inputs=2:duration=first" \ + "[0:a]volume=${VOLUME_1}[a1];[1:a]volume=${VOLUME_2}[a2];[a1][a2]amix=inputs=2:duration=first" \ $3 }