update
This commit is contained in:
parent
d2db6d0376
commit
f77dad143c
|
|
@ -5,7 +5,8 @@
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// Define settings file path - save in same directory as this file
|
// 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
|
||||||
$default_settings = [
|
$default_settings = [
|
||||||
|
|
@ -55,10 +56,74 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$settings['frame_rate'] = $_POST['frame_rate'] ?? $settings['frame_rate'];
|
$settings['frame_rate'] = $_POST['frame_rate'] ?? $settings['frame_rate'];
|
||||||
$settings['gop'] = $_POST['gop'] ?? $settings['gop'];
|
$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
|
// Save settings to JSON file
|
||||||
$settings_json = json_encode($settings, JSON_PRETTY_PRINT);
|
$settings_json = json_encode($settings, JSON_PRETTY_PRINT);
|
||||||
if (file_put_contents($settings_file, $settings_json) !== false) {
|
if (file_put_contents($settings_file, $settings_json) !== false) {
|
||||||
$message = "Settings saved successfully!";
|
$message .= " Settings saved successfully!";
|
||||||
} else {
|
} else {
|
||||||
$message = "Error saving settings!";
|
$message = "Error saving settings!";
|
||||||
}
|
}
|
||||||
|
|
@ -489,6 +554,95 @@ $_SESSION['settings'] = $settings;
|
||||||
.btn-container {
|
.btn-container {
|
||||||
margin-top: 20px;
|
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;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -512,6 +666,34 @@ $_SESSION['settings'] = $settings;
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="logo-container">
|
||||||
|
<h3><i class="fas fa-image"></i> Logo Management</h3>
|
||||||
|
<br>
|
||||||
|
<div class="logo-preview">
|
||||||
|
<?php if (file_exists($logo_file)): ?>
|
||||||
|
<img src="<?php echo htmlspecialchars($logo_file); ?>?v=<?php echo time(); ?>" alt="Logo Preview" id="logo-preview">
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="no-logo">No logo uploaded</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="logo-actions">
|
||||||
|
<form method="POST" action="" enctype="multipart/form-data" style="display: inline;">
|
||||||
|
<input type="file" name="logo" id="logo" accept="image/png" style="display: none;" onchange="this.form.submit()">
|
||||||
|
<button type="button" class="upload-btn" onclick="document.getElementById('logo').click()">
|
||||||
|
<i class="fas fa-upload"></i> Upload Logo
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php if (file_exists($logo_file)): ?>
|
||||||
|
<form method="POST" action="" style="display: inline;">
|
||||||
|
<input type="hidden" name="remove_logo" value="1">
|
||||||
|
<button type="submit" class="remove-btn">
|
||||||
|
<i class="fas fa-trash"></i> Remove Logo
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="format-note">
|
<div class="format-note">
|
||||||
<h3><i class="fas fa-info-circle"></i> Format Restrictions</h3>
|
<h3><i class="fas fa-info-circle"></i> Format Restrictions</h3>
|
||||||
<p><i class="fas fa-video"></i> Video format is limited to: MPEG-2, H.264, H.265, VP9, and AV1</p>
|
<p><i class="fas fa-video"></i> Video format is limited to: MPEG-2, H.264, H.265, VP9, and AV1</p>
|
||||||
|
|
@ -582,5 +764,21 @@ $_SESSION['settings'] = $settings;
|
||||||
<p>Made with <i class="fas fa-heart"></i> from ShreeBhattJi</p>
|
<p>Made with <i class="fas fa-heart"></i> from ShreeBhattJi</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Ensure logo preview works properly
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const logoPreview = document.getElementById('logo-preview');
|
||||||
|
if (logoPreview) {
|
||||||
|
// Add error handling for image loading
|
||||||
|
logoPreview.addEventListener('error', function() {
|
||||||
|
console.log('Logo preview failed to load');
|
||||||
|
// Show fallback message
|
||||||
|
const container = logoPreview.parentElement;
|
||||||
|
container.innerHTML = '<div class="no-logo">Logo failed to load</div>';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"video_format": "mpeg2",
|
"video_format": "h264",
|
||||||
"audio_format": "mp3",
|
"audio_format": "mp2",
|
||||||
"video_bitrate": "1000k",
|
"video_bitrate": "2000k",
|
||||||
"audio_bitrate": "128k",
|
"audio_bitrate": "128k",
|
||||||
"resolution": "1280x720",
|
"resolution": "720x576",
|
||||||
"frame_rate": "30",
|
"frame_rate": "30",
|
||||||
"gop": "30"
|
"gop": "30"
|
||||||
}
|
}
|
||||||
6
setup.sh
6
setup.sh
|
|
@ -27,6 +27,7 @@ EOF
|
||||||
sudo systemctl restart smbd nmbd
|
sudo systemctl restart smbd nmbd
|
||||||
sudo systemctl enable smbd nmbd
|
sudo systemctl enable smbd nmbd
|
||||||
|
|
||||||
|
cp transcode.sh /var/www/transcode.sh
|
||||||
cat << EOF | sudo tee -a /etc/systemd/system/transcode.service
|
cat << EOF | sudo tee -a /etc/systemd/system/transcode.service
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
|
|
@ -38,7 +39,7 @@ Type=simple
|
||||||
User=www-data
|
User=www-data
|
||||||
Group=www-data
|
Group=www-data
|
||||||
WorkingDirectory=/var/www/
|
WorkingDirectory=/var/www/
|
||||||
ExecStart=/usr/bin/python3 /var/www/transcode.sh
|
ExecStart=/bin/bash /var/www/transcode.sh
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
StandardOutput=journal
|
StandardOutput=journal
|
||||||
|
|
@ -46,5 +47,4 @@ StandardError=journal
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -5,6 +5,7 @@ QUEUE_DIR="/var/www/download/queue"
|
||||||
READY_DIR="/var/www/download/ready"
|
READY_DIR="/var/www/download/ready"
|
||||||
SETTINGS_FILE="/path/to/settings/settings.json"
|
SETTINGS_FILE="/path/to/settings/settings.json"
|
||||||
LOG_FILE="/var/log/convert.log"
|
LOG_FILE="/var/log/convert.log"
|
||||||
|
LOGO_FILE="/var/www/settings/logo.png"
|
||||||
|
|
||||||
# Create directories if they don't exist
|
# Create directories if they don't exist
|
||||||
mkdir -p "$QUEUE_DIR"
|
mkdir -p "$QUEUE_DIR"
|
||||||
|
|
@ -40,6 +41,32 @@ sanitize_filename() {
|
||||||
echo "$sanitized"
|
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
|
# Main processing loop
|
||||||
while true; do
|
while true; do
|
||||||
# Load settings at start of each loop
|
# Load settings at start of each loop
|
||||||
|
|
@ -62,22 +89,52 @@ while true; do
|
||||||
# Set output path
|
# Set output path
|
||||||
output_file="$READY_DIR/$sanitized_name"
|
output_file="$READY_DIR/$sanitized_name"
|
||||||
|
|
||||||
# Convert file with ffmpeg using settings from JSON
|
# Check if logo file exists
|
||||||
if ffmpeg -i "$file" \
|
if [ -f "$LOGO_FILE" ]; then
|
||||||
-c:v "$VIDEO_FORMAT" \
|
# Get video resolution
|
||||||
-b:v "$VIDEO_BITRATE" \
|
video_res=$(get_video_resolution "$file")
|
||||||
-c:a "$AUDIO_FORMAT" \
|
video_width=$(echo "$video_res" | cut -d'x' -f1)
|
||||||
-b:a "$AUDIO_BITRATE" \
|
video_height=$(echo "$video_res" | cut -d'x' -f2)
|
||||||
-s "$RESOLUTION" \
|
|
||||||
-r "$FRAME_RATE" \
|
# Calculate logo size
|
||||||
-g "$GOP" \
|
logo_size=$(calculate_logo_size "$video_width" "$video_height")
|
||||||
"$output_file" 2>>"$LOG_FILE"; then
|
|
||||||
# If conversion successful, remove original file
|
# Convert file with ffmpeg using settings from JSON and logo overlay
|
||||||
rm "$file"
|
if ffmpeg -i "$file" \
|
||||||
echo "$(date): Successfully converted $original_name to $sanitized_name" >> "$LOG_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
|
else
|
||||||
# If conversion failed, log error
|
# Convert file without logo if logo file doesn't exist
|
||||||
echo "$(date): Failed to convert $original_name" >> "$LOG_FILE"
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue