#!/bin/bash # Set the $FILE variable to act on. Varies with file manager, but Dolphin's servicemenus and CLI both use $1 if ! [ -z $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ]; then echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" > ~/.nautilus_script_selected_file_paths if (( $(grep -c . <<<"$(cat ~/.nautilus_script_selected_file_paths)") > 1 )); then notify-send -u critical "Script error" "Selecting more than 1 file is not supported."; exit 1; fi rm ~/.nautilus_script_selected_file_paths INPUT_FILE="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" elif ! [ -z "$1" ]; then INPUT_FILE="$1" else echo "No file selected." exit 1 fi # Break up the input file's parts so we know the: # - absolute path (e.g. /home/user/Videos/MyVideo.mkv) # - file name (with extension) (e.g. MyVideo.mkv) # - file extension (e.g. mkv) # - file name (without extension) (e.g. MyVideo) # - composed output file absolute path (e.g. /home/user/Videos/MyVideo-clip.mp4) INPUT_FILE=$(realpath "$INPUT_FILE") FILE_PATH=$(dirname "$INPUT_FILE") FILE_NAME=$(basename "$INPUT_FILE") FILE_EXT="${FILE_NAME##*.}" FILE_NAME="${FILE_NAME%.*}" OUTFILE=$(echo "$FILE_PATH/$FILE_NAME.mp4") # Actual remuxing happens here: notify-send -t 2000 "Remux starting" "$FILE_NAME" ffmpeg -hide_banner -i "$INPUT_FILE" -map 0 -c:v copy -c:a copy "$OUTFILE" notify-send -t 4000 "Remux complete" "$FILE_NAME"