NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public NextPVR Support Docker amd64 v
« Previous 1 2 3 4 5 … 9 Next »
Docker postprocessing script

 
  • 0 Vote(s) - 0 Average
Docker postprocessing script
aTF6i
Offline

Member

UK
Posts: 136
Threads: 11
Joined: Dec 2021
#11
2024-11-07, 02:18 AM (This post was last modified: 2024-11-07, 02:48 AM by aTF6i.)
OK, yes so it was a combination of trying different folders. (it isn't /app/data/scripts (there is a file that says it is)), case sensitivity, script errors, cancelling early etc

For future use:

The folder to use is /config/scripts/
As stated above, cancelling a recording triggers PostCancel.sh. (You will want this one for testing) (NOTE CASE ON FILE - ALSO CHMOD +X)
Completed recordings trigger PostProcessing.sh (NOTE CASE ON FILE - ALSO CHMOD +X)

Here is my script to process differently based on resolution

Code:
#!/bin/bash

RECORDING_PATH="$1"
OUTPUT_PATH="$(dirname "$RECORDING_PATH")"

LOG()
{
    logLoc=/config/scripts/script.log
    echo "$(date '+%d-%m-%Y %H:%M:%S') - $1" >> $logLoc
}

LOG "Post-processing started for file: $RECORDING_PATH"

# Get video resolution width
WIDTH=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "$RECORDING_PATH" | head -n 1)
LOG "Resolution width: $WIDTH"

# Define output file path
OUTPUT_FILE="$OUTPUT_PATH/$(basename "${RECORDING_PATH%.*}").mkv"
LOG "OUTPUT FILE: $OUTPUT_FILE"

# Remove commercials
comskip "$RECORDING_PATH"

# Check resolution width and apply different processing
if [[ "$WIDTH" -eq 1920 ]]; then
    LOG "Processing HD video"
    ffmpeg -i "$RECORDING_PATH" -c:v libx264 -preset veryfast -crf 26 -c:a copy "$OUTPUT_FILE"
elif [[ "$WIDTH" -eq 1280 ]]; then
    LOG "Processing 720p video"
    ffmpeg -i "$RECORDING_PATH" -c:v libx264 -preset fast -crf 25 -c:a copy "$OUTPUT_FILE"
else
    LOG "Processing SD video"
    ffmpeg -i "$RECORDING_PATH" -c:v libx264 -preset medium -crf 24 -c:a copy "$OUTPUT_FILE"
fi

# Check if transcoding was successful
if [[ $? -eq 0 && -f "$OUTPUT_FILE" ]]; then
    LOG "Transcoding successful, removing original file"
    rm "$RECORDING_PATH"
else
    LOG "Transcoding failed, keeping original file"
fi

# Send notification
LOG "Recording processed: $(basename "$RECORDING_PATH")"

I have yet to test comskip - Any input appreciated on that
I will monitor transcode times/quality and adjust as needed

Your input is apprecated as always, Martin
aTF6i
Offline

Member

UK
Posts: 136
Threads: 11
Joined: Dec 2021
#12
2024-11-08, 01:45 AM (This post was last modified: 2024-11-08, 01:49 AM by aTF6i.)
...


Attached Files
.zip   adapter0-DVB-T-channels.zip (Size: 4.37 KB / Downloads: 1)
aTF6i
Offline

Member

UK
Posts: 136
Threads: 11
Joined: Dec 2021
#13
2024-11-17, 01:17 AM
updated script if anyone wants it

It seems to be working well

Code:
#!/bin/bash

RECORDING_PATH="$1"
OUTPUT_PATH="$(dirname "$RECORDING_PATH")"

LOG()
{
    logLoc=/config/scripts/script.log
    echo "$(date '+%d-%m-%Y %H:%M:%S') - $1"
    echo "$(date '+%d-%m-%Y %H:%M:%S') - $1" >> $logLoc
}

# Function to convert duration to seconds
duration_to_seconds() {
    local DURATION=$1
    local HOURS=$(echo $DURATION | cut -d':' -f1)
    local MINUTES=$(echo $DURATION | cut -d':' -f2)
    local SECONDS=$(echo $DURATION | cut -d':' -f3 | cut -d'.' -f1)
    local MILLISECONDS=$(echo $DURATION | cut -d':' -f3 | cut -d'.' -f2)
    echo $((10#$HOURS * 3600 + 10#$MINUTES * 60 + 10#$SECONDS))
}

# Function to calculate absolute difference
abs_diff() {
    local DIFF=$(( $1 - $2 ))
    if (( DIFF < 0 )); then
        DIFF=$(( -DIFF ))
    fi
    echo $DIFF
}


LOG "Post-processing started for file: $RECORDING_PATH"

# Get video resolution width
WIDTH=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "$RECORDING_PATH" | head -n 1)
LOG "Resolution width: $WIDTH"

# Define output file path
OUTPUT_FILE="$OUTPUT_PATH/$(basename "${RECORDING_PATH%.*}").mkv"
LOG "OUTPUT FILE: $OUTPUT_FILE"

START_TIME=$(date +%s)
# Check resolution width and apply different processing
if [[ "$WIDTH" -eq 1920 ]]; then
    LOG "Processing HD video"
    ffmpeg -i "$RECORDING_PATH" -c:v libx264 -preset veryfast -crf 26 -c:a copy -sn -y "$OUTPUT_FILE"
elif [[ "$WIDTH" -eq 1280 ]]; then
    LOG "Processing 720p video"
    ffmpeg -i "$RECORDING_PATH" -c:v libx264 -preset fast -crf 25 -c:a copy -sn -y "$OUTPUT_FILE"
else
    LOG "Processing SD video"
    ffmpeg -i "$RECORDING_PATH" -c:v libx264 -preset medium -crf 24 -c:a copy -sn -y "$OUTPUT_FILE"
fi
END_TIME=$(date +%s)

# Calculate and log the transcode time
TRANSCODE_TIME=$((END_TIME - START_TIME))
LOG "Transcoding time: $TRANSCODE_TIME seconds"

# Check if transcoding was successful
if [[ -f "$OUTPUT_FILE" ]]; then
    LOG "Transcoded file present"    
else
    LOG "Transcoding - File check failed,  keeping original file"
    exit
fi

# Verify the duration of the input and output files
INPUT_DURATION=$(ffmpeg -i "$RECORDING_PATH" 2>&1 | grep "Duration" | awk '{print $2}' | tr -d ,)
OUTPUT_DURATION=$(ffmpeg -i "$OUTPUT_FILE" 2>&1 | grep "Duration" | awk '{print $2}' | tr -d ,)

INPUT_SECONDS=$(duration_to_seconds $INPUT_DURATION)
OUTPUT_SECONDS=$(duration_to_seconds $OUTPUT_DURATION)

TOLERANCE=15 # Allowable difference in seconds
DIFF=$(abs_diff $INPUT_SECONDS $OUTPUT_SECONDS)

LOG "Input duration (seconds): $INPUT_SECONDS"
LOG "Transcode duration (seconds): $OUTPUT_SECONDS"
LOG "Duration difference (seconds): $DIFF"

if (( DIFF <= TOLERANCE )); then
    LOG "Transcoding successful, removing original file"
    rm "$RECORDING_PATH"
    
   #Remove commercials
    LOG "Processing comskip..."
    comskip --ini=/config/scripts/comskip.ini "$OUTPUT_FILE"

    # Send notification
    LOG "Recording processed: $(basename "$RECORDING_PATH")"
else
    LOG "Transcoding - Duration check failed, keeping original file"
    exit
fi
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): « Previous 1 2


Possibly Related Threads…
Thread Author Replies Views Last Post
  Migrating from Windows to Docker? boringgit 2 214 2025-06-09, 07:58 PM
Last Post: boringgit
  Comskip segfaults with comskip embedded in amd64 docker SickBoy 6 647 2025-02-24, 11:18 PM
Last Post: SickBoy
  Issues with Session Handling Behind Caddy Reverse Proxy in Docker: invalid session user001 5 626 2025-01-10, 08:23 PM
Last Post: sub
  Docker container becomes unresponsive overnight wapkaplet 6 855 2025-01-10, 04:47 PM
Last Post: wapkaplet
  Docker image upgrade ceejayemm 9 1,153 2025-01-07, 11:27 PM
Last Post: pkscout
  Current guide for NextPVR docker on Unraid? wapkaplet 1 953 2024-12-20, 02:40 AM
Last Post: wapkaplet
  NextPVR with Docker and Fritzbox icompas 9 868 2024-12-12, 02:50 PM
Last Post: icompas
  Can't get postprocessing.sh to run themarf 3 558 2024-11-18, 02:41 PM
Last Post: themarf
  XMLTV folder for Docker stevil 1 493 2024-09-25, 06:56 PM
Last Post: mvallevand
  Add Intel iHD Driver to Docker Image for NextPVR thelanofvilles 8 1,488 2024-06-16, 08:10 PM
Last Post: thelanofvilles

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode