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 … 10 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
  Current guide for NextPVR docker on Unraid? wapkaplet 2 3,176 2026-01-05, 07:22 PM
Last Post: guyinco6nito
  new build old docker techpro2004 11 1,696 2025-11-09, 09:01 PM
Last Post: mvallevand
  Docker image for arm64? Jack_Burton505 8 2,414 2025-09-11, 02:25 AM
Last Post: Jack_Burton505
  Docker options tom_tav 2 1,770 2025-07-27, 05:01 PM
Last Post: LiLao
  Migrating from Windows to Docker? boringgit 2 1,834 2025-06-09, 07:58 PM
Last Post: boringgit
  Comskip segfaults with comskip embedded in amd64 docker SickBoy 6 2,892 2025-02-24, 11:18 PM
Last Post: SickBoy
  Issues with Session Handling Behind Caddy Reverse Proxy in Docker: invalid session user001 5 2,670 2025-01-10, 08:23 PM
Last Post: sub
  Docker container becomes unresponsive overnight wapkaplet 6 3,159 2025-01-10, 04:47 PM
Last Post: wapkaplet
  Docker image upgrade ceejayemm 9 4,058 2025-01-07, 11:27 PM
Last Post: pkscout
  NextPVR with Docker and Fritzbox icompas 9 3,243 2024-12-12, 02:50 PM
Last Post: icompas

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

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

Linear Mode
Threaded Mode