1

I use this script to cut media files at selected time:

#!/bin/bash

INPUT=$(yad --width=600 --height=400 --file-selection --file-filter='.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"

I have found it HERE initially and only changed the last line (to cut/copy without conversion).

But I am in KDE and would like to use kdialog for a better interaction.

The first part, starting with INPUT=$(yad can be adjusted like so, I guess:

INPUT=$(kdialog --getopenfilename ~/Videos/ '*.m4a *.ogg *.mp3 *.mp4 *.avi *.aac *.flac *.avi *.mkv *.mp4')

But then I don't find an alternative in kdialog to the second part (starting with eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" ...) so that it shows a window where the timestamp start and end could be entered:

enter image description here


(In case this is possible I would also like to have a progress bar or message and a "ok" message at the end. - Please feel free to suggest other solutions than kdialog if available for KDE.)

cipricus
  • 1,529
  • 2
    serious question, if you're on KDE and want good KDE integration, why do a shell script? PyQt5 is pretty usable, and the thing you're trying to write would be a relatively short Python script, without dependeny on yad. – Marcus Müller Apr 24 '23 at 14:11
  • 3
    I'm going to roll back your replacement of the source code with the image. I can read your source code just fine, some of us can't read pictures (e.g. because they have bad vision and that thing just won't scale), and atop of that, I can't copy and paste text from an image – Marcus Müller Apr 24 '23 at 14:12

1 Answers1

0

I don't know if my question was explicit enough, but the whole problem was in this sentence:

I am in KDE and would like to use kdialog for a better interaction.

But the only thing that was "no good" KDE-interaction-wise was the GTK UI of the file picker and of the timestamp window. The former was more important than the latter: the file picker was also stuck at $HOME level and I was not able to find a yad --file option to specify another location in the way kdialog --getopenfilename has.

My solution here only goes as far: using kdialog for the file picker and leaving yad for the timestamp window (which I don't know how to create with kdialog); I wasn't able to make a progress bar with kdialog, so I have found a way to make one with zenity (not really showing the percentual progress, just the fact that action is underway); end-message was easy to create with kdialog.

#!/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

(I realize this way of mixing kdialog, zenity and yad is odd, and i am waiting for a cleaner solution, preferably with just kdialog, but I don't know how to make a progressbar and a timestamp window with that.)

cipricus
  • 1,529