I have found here here a script that provides a GUI interaction in order to trim/cut media files. I have tried to improve it a bit. Now it involves a file picker to select the file, a timestamp window to set the start and end points, a progress bar during the process, and a confirmation message at the end of the process.
But because I am in KDE/Kubuntu I have also tried to use only kdialog
instead of yad
or zenity
, without much success. I have succeeded in using kdialog
for the file picker and the end message, but the timestamp window is created with yad
(a zenity
fork) and for the progress bar I have used zenity
.
This is the script:
#!/bin/bash
INPUT=$(kdialog --getopenfilename ~/Videos/ '*.m4a *.ogg *.mp3 *.mp4 *.avi *.aac *.flac *.avi *.mkv *.mp4')
eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" "${INPUT/%.*}-out.${INPUT##*.}" | awk -F'|' '{printf "START=%s\nEND=%s\nOUTPUT=\"%s\"\n", $1, $2, $3}')
[[ -z $START || -z $END || -z $OUTPUT ]] && exit 1
DIFF=$(($(date +%s --date="$END")-$(date +%s --date="$START")))
OFFSET=""$(($DIFF / 3600)):$(($DIFF / 60 % 60)):$(($DIFF % 60))
ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -c copy "$OUTPUT" | zenity --progress --pulsate --text="Running" --percentage=1 --auto-close --auto-kill
if [ $? -eq 0 ]; then
kdialog --msgbox "Process completed successfully!"
else
kdialog --msgbox "SOMETHING WENT WRONG!"
fi
Looking into kdialog
help, it seems there isn't a way to make a timestamp window with kdialog
(but that is another question that I'm not asking here: I want to ask these questions separately).
What I want to ask here is how to create a progressbar dialog with kdialog
for the ffmpeg
process, given that kdialog --help all
says:
--progressbar <text> Progress bar dialog, returns a D-Bus
reference for communication
I gather that means the use of qdbus
/dbus
options like these here:
dbusRef=`kdialog --progressbar "Initializing" 4`
qdbus $dbusRef Set "" value 1
qdbus $dbusRef setLabelText "Thinking really hard"
sleep 2
qdbus $dbusRef Set "" value 2
sleep 2
qdbus $dbusRef setLabelText "Thinking some more"
qdbus $dbusRef Set "" value 3
sleep 2
qdbus $dbusRef Set "" value 4
sleep 2
qdbus $dbusRef close
But I don't know how to adjust/integrate such options with that script so that it relates to the ffmpeg
process.
With a line like kdialog --progressbar "Running"
I can make kdbus
show a "dead" window during the process, which doesn't even close when that's over and nothing more. (No "progress" seems to be represented there.)
