diff --git a/Readme.md b/Readme.md old mode 100644 new mode 100755 diff --git a/settings/index.php b/settings/index.php index 5c3e00b..969a60e 100755 --- a/settings/index.php +++ b/settings/index.php @@ -5,7 +5,8 @@ session_start(); // Define settings file path - save in same directory as this file -$settings_file = __DIR__ . '/settings.json'; +$settings_file = 'settings.json'; +$logo_file = 'logo.png'; // Default settings $default_settings = [ @@ -55,10 +56,74 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $settings['frame_rate'] = $_POST['frame_rate'] ?? $settings['frame_rate']; $settings['gop'] = $_POST['gop'] ?? $settings['gop']; + // Handle logo upload + if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) { + // Check if GD library is available + if (!extension_loaded('gd')) { + $message = "GD library not available for image processing!"; + } else { + $allowed_types = ['image/png']; + $file_type = mime_content_type($_FILES['logo']['tmp_name']); + + if (in_array($file_type, $allowed_types)) { + // Move uploaded file + $target_path = $logo_file; + if (move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)) { + // Process image with GD library to make it square + $image = imagecreatefrompng($target_path); + if ($image !== false) { + $width = imagesx($image); + $height = imagesy($image); + + // Calculate square dimensions (use smaller dimension) + $size = min($width, $height); + + // Create square canvas + $square = imagecreatetruecolor(128, 128); + + // Fill with transparent background + $transparent = imagecolorallocatealpha($square, 0, 0, 0, 127); + imagefill($square, 0, 0, $transparent); + + // Calculate position to center the image + $x = ($width - $size) / 2; + $y = ($height - $size) / 2; + + // Copy and resize to square + imagecopyresampled($square, $image, 0, 0, $x, $y, 128, 128, $size, $size); + + // Save the processed image + imagepng($square, $target_path); + + // Free memory + imagedestroy($image); + imagedestroy($square); + + $message = "Logo uploaded and processed successfully!"; + } else { + $message = "Error processing image with GD library!"; + } + } else { + $message = "Error uploading logo!"; + } + } else { + $message = "Only PNG images are allowed!"; + } + } + } + + // Handle logo removal + if (isset($_POST['remove_logo']) && $_POST['remove_logo'] == '1') { + if (file_exists($logo_file)) { + unlink($logo_file); + $message = "Logo removed successfully!"; + } + } + // Save settings to JSON file $settings_json = json_encode($settings, JSON_PRETTY_PRINT); if (file_put_contents($settings_file, $settings_json) !== false) { - $message = "Settings saved successfully!"; + $message .= " Settings saved successfully!"; } else { $message = "Error saving settings!"; } @@ -489,6 +554,95 @@ $_SESSION['settings'] = $settings; .btn-container { margin-top: 20px; } + + .logo-container { + text-align: center; + margin: 20px 0; + } + + .logo-preview { + width: 128px; + height: 128px; + margin: 0 auto; + border-radius: 0; /* Changed from 50% to 0 for square shape */ + overflow: hidden; + border: 2px solid rgba(92, 107, 192, 0.5); + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); + background: rgba(13, 19, 33, 0.7); + display: flex; + justify-content: center; + align-items: center; + position: relative; + margin-bottom: 15px; + } + + .logo-preview img { + width: 100%; + height: 100%; + object-fit: contain; + display: block; + } + + .logo-preview .no-logo { + color: #4facfe; + font-size: 0.9rem; + text-align: center; + padding: 10px; + } + + .logo-actions { + display: flex; + justify-content: center; + gap: 10px; + margin-top: 10px; + } + + .logo-actions button { + padding: 8px 15px; + border: none; + border-radius: 8px; + cursor: pointer; + font-size: 0.9rem; + transition: all 0.3s; + } + + .upload-btn { + background: rgba(92, 107, 192, 0.3); + color: #4facfe; + } + + .remove-btn { + background: rgba(231, 76, 60, 0.3); + color: #e74c3c; + } + + .logo-actions button:hover { + transform: translateY(-2px); + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); + } + + .logo-preview::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + border: 2px dashed rgba(92, 107, 192, 0.3); + border-radius: 50%; + pointer-events: none; + } + + /* Fix for logo preview */ + .logo-preview img { + display: block; + max-width: 100%; + max-height: 100%; + } + + .logo-preview img[src=""] { + display: none; + } @@ -512,6 +666,34 @@ $_SESSION['settings'] = $settings;

+
+

Logo Management

+
+
+ + Logo Preview + + + +
+
+
+ + +
+ +
+ + +
+ +
+
+

Format Restrictions

Video format is limited to: MPEG-2, H.264, H.265, VP9, and AV1

@@ -582,5 +764,21 @@ $_SESSION['settings'] = $settings;

Made with from ShreeBhattJi

+ + \ No newline at end of file diff --git a/settings/logo.png b/settings/logo.png new file mode 100755 index 0000000..5ed0dbf Binary files /dev/null and b/settings/logo.png differ diff --git a/settings/settings.json b/settings/settings.json old mode 100644 new mode 100755 index edd2db1..df08af9 --- a/settings/settings.json +++ b/settings/settings.json @@ -1,9 +1,9 @@ { - "video_format": "mpeg2", - "audio_format": "mp3", - "video_bitrate": "1000k", + "video_format": "h264", + "audio_format": "mp2", + "video_bitrate": "2000k", "audio_bitrate": "128k", - "resolution": "1280x720", + "resolution": "720x576", "frame_rate": "30", "gop": "30" } \ No newline at end of file diff --git a/setup.sh b/setup.sh index 93ddab0..24a86b0 100755 --- a/setup.sh +++ b/setup.sh @@ -27,6 +27,7 @@ EOF sudo systemctl restart smbd nmbd sudo systemctl enable smbd nmbd +cp transcode.sh /var/www/transcode.sh cat << EOF | sudo tee -a /etc/systemd/system/transcode.service [Unit] @@ -38,7 +39,7 @@ Type=simple User=www-data Group=www-data WorkingDirectory=/var/www/ -ExecStart=/usr/bin/python3 /var/www/transcode.sh +ExecStart=/bin/bash /var/www/transcode.sh Restart=always RestartSec=10 StandardOutput=journal @@ -46,5 +47,4 @@ StandardError=journal [Install] WantedBy=multi-user.target -EOF - +EOF \ No newline at end of file diff --git a/transcode.sh b/transcode.sh old mode 100644 new mode 100755 index adeab3c..4a23550 --- a/transcode.sh +++ b/transcode.sh @@ -5,6 +5,7 @@ QUEUE_DIR="/var/www/download/queue" READY_DIR="/var/www/download/ready" SETTINGS_FILE="/path/to/settings/settings.json" LOG_FILE="/var/log/convert.log" +LOGO_FILE="/var/www/settings/logo.png" # Create directories if they don't exist mkdir -p "$QUEUE_DIR" @@ -40,6 +41,32 @@ sanitize_filename() { echo "$sanitized" } +# Function to get video resolution +get_video_resolution() { + local input_file="$1" + ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$input_file" +} + +# Function to calculate logo size based on video resolution +calculate_logo_size() { + local video_width="$1" + local video_height="$2" + + # Calculate 10% of video width/height for logo size + local logo_width=$((video_width / 10)) + local logo_height=$((video_height / 10)) + + # Ensure minimum size of 64x64 + if [ "$logo_width" -lt 64 ]; then logo_width=64; fi + if [ "$logo_height" -lt 64 ]; then logo_height=64; fi + + # Ensure maximum size of 128x128 + if [ "$logo_width" -gt 128 ]; then logo_width=128; fi + if [ "$logo_height" -gt 128 ]; then logo_height=128; fi + + echo "${logo_width}x${logo_height}" +} + # Main processing loop while true; do # Load settings at start of each loop @@ -62,22 +89,52 @@ while true; do # Set output path output_file="$READY_DIR/$sanitized_name" - # Convert file with ffmpeg using settings from JSON - if ffmpeg -i "$file" \ - -c:v "$VIDEO_FORMAT" \ - -b:v "$VIDEO_BITRATE" \ - -c:a "$AUDIO_FORMAT" \ - -b:a "$AUDIO_BITRATE" \ - -s "$RESOLUTION" \ - -r "$FRAME_RATE" \ - -g "$GOP" \ - "$output_file" 2>>"$LOG_FILE"; then - # If conversion successful, remove original file - rm "$file" - echo "$(date): Successfully converted $original_name to $sanitized_name" >> "$LOG_FILE" + # Check if logo file exists + if [ -f "$LOGO_FILE" ]; then + # Get video resolution + video_res=$(get_video_resolution "$file") + video_width=$(echo "$video_res" | cut -d'x' -f1) + video_height=$(echo "$video_res" | cut -d'x' -f2) + + # Calculate logo size + logo_size=$(calculate_logo_size "$video_width" "$video_height") + + # Convert file with ffmpeg using settings from JSON and logo overlay + if ffmpeg -i "$file" \ + -c:v "$VIDEO_FORMAT" \ + -b:v "$VIDEO_BITRATE" \ + -c:a "$AUDIO_FORMAT" \ + -b:a "$AUDIO_BITRATE" \ + -s "$RESOLUTION" \ + -r "$FRAME_RATE" \ + -g "$GOP" \ + -vf "scale=iw:ih,overlay=W-w-10:10" \ + "$output_file" 2>>"$LOG_FILE"; then + # If conversion successful, remove original file + rm "$file" + echo "$(date): Successfully converted $original_name to $sanitized_name" >> "$LOG_FILE" + else + # If conversion failed, log error + echo "$(date): Failed to convert $original_name" >> "$LOG_FILE" + fi else - # If conversion failed, log error - echo "$(date): Failed to convert $original_name" >> "$LOG_FILE" + # Convert file without logo if logo file doesn't exist + if ffmpeg -i "$file" \ + -c:v "$VIDEO_FORMAT" \ + -b:v "$VIDEO_BITRATE" \ + -c:a "$AUDIO_FORMAT" \ + -b:a "$AUDIO_BITRATE" \ + -s "$RESOLUTION" \ + -r "$FRAME_RATE" \ + -g "$GOP" \ + "$output_file" 2>>"$LOG_FILE"; then + # If conversion successful, remove original file + rm "$file" + echo "$(date): Successfully converted $original_name to $sanitized_name" >> "$LOG_FILE" + else + # If conversion failed, log error + echo "$(date): Failed to convert $original_name" >> "$LOG_FILE" + fi fi done