Skip to content

Instantly share code, notes, and snippets.

@alex5250
Created May 19, 2024 14:06
Show Gist options
  • Save alex5250/9cb013882171829104c5e37ce39fdf28 to your computer and use it in GitHub Desktop.
Save alex5250/9cb013882171829104c5e37ce39fdf28 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Directory containing the video files
VIDEO_DIR="/media/drive/Футажи/DJI FPV DVRS/DCIM/100MEDIA"
LOG_FILE="/var/log/video_processing/log.log"
PROGRESS_FILE="/var/log/video_processing/process"
PROCESSED_DIR="/media/drive/Футажи/DJI FPV DVRS/DCIM/100MEDIA/with_OSD"
# Ensure the processed directory exists
mkdir -p "$PROCESSED_DIR"
# Function to process video file
process_video() {
local video_file="$1"
local base_name=$(basename "$video_file")
local output_file="$PROCESSED_DIR/${base_name%.mp4}_processed.mp4"
local temp_output_file="${output_file%.mp4}_temp.mp4"
local subtitle_file="${video_file%.mp4}.srt"
echo "Processing $video_file with output $output_file" | tee -a "$LOG_FILE"
# Transcode video with OSD and compress using fpv cli
fpv transcode-video --osd "$video_file" "$temp_output_file" >> "$LOG_FILE"
if [[ $? -eq 0 ]]; then
if [[ -f "$subtitle_file" ]]; then
#ffmpeg -i "$temp_output_file" -i "$subtitle_file" -c copy -c:s mov_text "$output_file" >> "$LOG_FILE"
#ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4
echo "sayses bugs"
else
mv "$temp_output_file" "$output_file"
fi
if [[ $? -eq 0 ]]; then
echo "Processed $video_file successfully." | tee -a "$LOG_FILE"
echo "$video_file" >> "$PROGRESS_FILE"
else
echo "Failed to mux subtitles for $video_file." | tee -a "$LOG_FILE"
fi
else
echo "Failed to process $video_file." | tee -a "$LOG_FILE"
fi
# Clean up temporary file if it exists
[[ -f "$temp_output_file" ]] && rm "$temp_output_file"
}
# Main processing loop
while true; do
for video_file in "$VIDEO_DIR"/*.mp4; do
# Skip files that have already been processed
if grep -q "$video_file" "$PROGRESS_FILE"; then
continue
fi
process_video "$video_file"
done
# Sleep for a while before checking for new files
sleep 600 # 10 minutes
done
@alex5250
Copy link
Author

Do not forget to create all dirs and files before run

sudo mkdir -p /var/log/video_processing
sudo touch /var/log/video_processing/log.log
sudo mkdir -p "/media/drive/Футажи/DJI FPV DVRS/DCIM/100MEDIA/with_OSDs"
sudo touch /var/log/video_processing/process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment