Nautilus-Bash-Skript, wie lösche ich alte Dateien nach der FFMPEG-Konvertierung?

Nautilus-Bash-Skript, wie lösche ich alte Dateien nach der FFMPEG-Konvertierung?

Ich schreibe mein allererstes Nautilus-Skript, bin mir aber nicht sicher, wie ich weitermachen soll. Was muss ich diesem Nautilus-Skript hinzufügen, damit alle MP4-Dateien im Ordner gelöscht werden?nachFFMPEG schließt die Konvertierung in MOV ab?

#!/bin/bash

echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | find '*.mp4'

for i in *.mp4; do ffmpeg -i "$i" -c:v copy -c:a pcm_s16le -ar 48000 -ac 2 "$(echo "$i"|cut -d\. -f1).mov";done

Danke schön! :)

Antwort1

Entfernen Sie einfach die Datei (ich würde es mit aktivierter Erzwingungsoption bevorzugen) - $i:

#!/bin/bash

echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | find '*.mp4'

for i in *.mp4 
do 
    ffmpeg -i "$i" -c:v copy -c:a pcm_s16le -ar 48000 -ac 2 "$(echo "$i"|cut -d\. -f1).mov"
    rm -f "$i"
done
  • Wenn Sie möchten, können Sie die Zeilenumbrüche durch ein Semikolon ersetzen ;.

Eine weitere Möglichkeit besteht darin,Verschiebe die Datei in den Papierkorbanstatt es zu löschen:

    gvfs-trash "$i"

Darüber hinaus kann Ihr Skript folgendermaßen verbessert werden:

#!/bin/bash -e

# Get the items selected in Nautilus as an array
IFS_BAK=$IFS
IFS=$'\t\n'
FILE_LIST=($NAUTILUS_SCRIPT_SELECTED_FILE_PATHS)
IFS=$IFS_BAK

# For each item in the array $FILE_LIST
for ((i=0; i<${#FILE_LIST[@]}; i++))
do
    # Get the file extension
    FILE_EXT="${FILE_LIST[$i]##*.}"

    # If the item is a file and its extension is mp4 
    if [[ -f ${FILE_LIST[$i]} ]] && [[ $FILE_EXT == 'mp4' ]]
    then
        # Get the filename
        FILE_NAME="${FILE_LIST[$i]%.*}"
        # Compose the name of the new file
        THE_NEW_FILE="${FILE_NAME}.mov"

        # Do the conversion
        ffmpeg -i "${FILE_LIST[$i]}" -c:v copy -c:a pcm_s16le -ar 48000 -ac 2 "$THE_NEW_FILE"

        # Remove the item: rm -f "${FILE_LIST[$i]}"; or move it to the trash:
        gvfs-trash "${FILE_LIST[$i]}"

        # Output a message, note ##*/ will remove the path from the filename
        notify-send "mp4 to mov" "${THE_NEW_FILE##*/} - was created\n${FILE_LIST[$i]##*/} - was moved to the Тrash"
    fi
done

Hier ist eine damit zusammenhängende Frage:Skript zum Zusammenführen von Video und Untertiteln und anschließendem Löschen der vorhandenen Dateien

verwandte Informationen