jbilcke-hf/media-server
8
1#!/bin/bash2 3# Make sure to provide your directories paths4INPUT_DIR=$WEBTV_VIDEO_STORAGE_PATH_CHANNEL_25OUTPUT_DIR=$WEBTV_VIDEO_STORAGE_PATH_CHANNEL_36TEMP_DIR=$(mktemp -d)7 8# Loop through all .mp4 files in input directory9for FILE_PATH in $INPUT_DIR*.mp4; do10 # get the base file name11 FILE_NAME=$(basename "$FILE_PATH")12 13 # Create a temp file path14 TEMP_FILE_PATH=$TEMP_DIR"/"$FILE_NAME15 16 # Check if file does not exist in output directory17 if [ ! -f "$OUTPUT_DIR$FILE_NAME" ]; then18 echo "Processing $FILE_NAME, output will be saved in $OUTPUT_DIR$FILE_NAME"19 20 # Run your node command21 if ! npm run batch:interpolate "$FILE_PATH" "$TEMP_FILE_PATH"22 then23 # The first attempt has failed, retrying24 echo "Attempt 1 failed for $FILE_NAME, retrying..."25 26 if ! npm run batch:interpolate "$FILE_PATH" "$TEMP_FILE_PATH"27 then28 # Both attempts have failed, skipping the file29 echo "Both attempts failed for $FILE_NAME, skipping the file..."30 continue31 fi32 fi33 34 # Running ffmpeg to resize and apply unsharp mask35 # Also we speed things up, and re-add the noise36 if ! ffmpeg -hide_banner -v fatal -nostats -loglevel 0 -i "$TEMP_FILE_PATH" -vf "setpts=0.35*PTS,scale=-1:576:lanczos,unsharp=5:5:0.2:5:5:0.2,noise=c0s=10:c0f=t+u" -r 24 "$OUTPUT_DIR$FILE_NAME"37 then38 # ffmpeg command failed39 echo "ffmpeg command failed for $FILE_NAME, skipping the file..."40 fi41 42 else43 echo "File $FILE_NAME already exists in the output directory, skipping."44 fi45done46 47# Remove temp folder48rm -r "$TEMP_DIR"