LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Modify Nemo context menu (https://www.linuxquestions.org/questions/linux-newbie-8/modify-nemo-context-menu-4175676776/)

michaelsavage 06-09-2020 11:26 AM

Modify Nemo context menu
 
I'm running Linux Mint 19.3 and would like to add an action to the context menu. I want to be able to select multiple image files and convert them to a mp4 file.I know this is possible by creating a nemo_action file in the /home/$USER/.local/share/nemo/actions folder.

I'm able to do this action via the command line with this command

Code:

ffmpeg -framerate 1 -pattern_type glob -i '*.jpg' -vf scale=500:300 out.mp4
ffmpeg = software to convert files
-framerate 1 = this will change the image in the mp4 file every 1 second
-pattern_type glob = this to to be able to select multiple images
'*.jpg' = selects the files I want
-vf scale=500:300 = sets the video size to 500 by 300
out.mp4 = name of the output file

I created an action file to try to perform this task with this information

Code:


[Nemo Action]
Active=true
Name=Images to Video
Comment=Convert images to an MP4 format
Exec=ffmpeg -framerate 1 -pattern_type glob -i '%F' -vf scale=500:300 out.mp4
Icon-Name=gnome-mime-application-x-compress
Selection=m
Extensions=jpg;png;bmp;gif
Terminal=true

On the Exec line I changed the '*.jpg' part to '%F' so I could select the files via a GUI.

%F = insert path list of selection

The Nemo action does show up in the context menu and I can select images to convert. But the action does not create the out.mp4 file. I think its failing because of the %F but I not sure how to select the files with out using %F.

Thank you in advance for your help.

shruggy 06-09-2020 11:56 AM

%F is not a glob, it's a list of files separated by spaces. You probably should wrap the ffmpeg command in a shell script:
Code:

#!/bin/bash
exec ffmpeg -framerate 1 ${@/#/-i } -vf scale=500:300 out.mp4

Alternatively, you could directly invoke bash in the Exec key:
Code:

Exec=bash -c "'exec ffmpeg -framerate 1 \\${@/#/-i } -vf scale=500:300 out.mp4'" _ %F

michaelsavage 06-09-2020 03:15 PM

It looks like I'm half way there. I created a shell script and added your recommendations. The out.mp4 file does get created but none of the images reside in the out.mp4 file. Just a blank out.mp4 file.

My new nemo_action file

Code:


[Nemo Action]
Active=true
Name=Images to Video
Comment=Convert images to an MP4 format
Exec=<image-to-video.sh %F>
Icon-Name=image
Selection=m
Extensions=jpg;png;bmp;gif
Terminal=true

Do you know if I need to change something in the nemo_action file?

I also tried your 2nd sugestion but I was not able to create the out.mp4 file

cordx 06-09-2020 03:25 PM

in case your file names have spaces (from the arch wiki):
Quote:

By default, Nemo does not escape filenames. This means that actions for multiple files with some names containing spaces are broken. To fix this, use Quote=double.
also (from mint's github):
Quote:

# Quote type to use (if any) - enclose paths/urls with quotes. Optional - defaults
# to no quotes.
# Can be: single, double, backtick
#Quote=double

shruggy 06-09-2020 03:54 PM

Thanks to cordx I see now that Nemo actions are not the same as .desktop as I assumed first. So the weird quoting rules for Exec= in .desktop may not apply here. Try it like this
Code:

Exec=bash -c 'exec ffmpeg -framerate 1 ${@/#/-i } -vf scale=500:300 out.mp4' _ %F
I honestly don't know why the shell script didn't work though. Have you made it executable?

michaelsavage 06-09-2020 04:15 PM

Shruggy - the shell script works half way. It creates the out.mp4 file, but the file does not contain the images. Yes the script is executable.

Cordx - I verified there is not any spaces in the names of the image files, but I still added the Quote=double just in case I select files with spaces in the future. Still no joy. The out.mp4 is blank

I thank you both for your input. I'm not sure why it creates a blank out.mp4 file.

cordx 06-09-2020 04:35 PM

what about setting selection to Any?

it also looks like there might be a couple different ways to try and debug. mind you, i don't use mint or nemo so i can't test run them, but these are options from the sample action in the repo:
Quote:

#############################################
#### DEBUGGING:
####
#### Run Nemo in debug mode using with
### NEMO_DEBUG set to include 'Actions'
####
#### i.e. $ nemo --quit
#### $ NEMO_DEBUG=Actions nemo --debug
#############################################
and
Quote:

# Conditions - semicolon-separated array of special conditions:
# "desktop" current (parent) folder is desktop
# "removable" target (first selection) is removable
# "gsettings <schema> <boolean key>" is true
# "gsettings <schema> <key> <key-type> <[eq|ne|gt|lt]> <value>"
# "dbus <name>" exists
# "exec <program>" run program and check its exit code (0 is pass, non-0 is fail).
# Enclose in < > if the program resides in the action's folder.

#Conditions=desktop;

michaelsavage 06-10-2020 07:20 AM

Cordx

Below is the output I get when running the context action in debug mode

Code:

# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)
(nemo:85167): dconf-DEBUG: 08:12:50.280: watch_fast: "/org/cinnamon/desktop/applications/terminal/" (establishing: 0, active: 1)
(nemo:85167): dconf-DEBUG: 08:12:50.280: unwatch_fast: "/org/cinnamon/desktop/applications/terminal/" (active: 2, establishing: 0)
# Option “-x” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
# _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for ‘gio-vfs’
# _g_io_module_get_default: Found default implementation dconf (DConfSettingsBackend) for ‘gsettings-backend’
# watch_fast: "/org/gnome/terminal/legacy/" (establishing: 0, active: 0)
# unwatch_fast: "/org/gnome/terminal/legacy/" (active: 0, establishing: 1)
# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)


cordx 06-10-2020 05:18 PM

i don't see anything that seems particularly helpful there unfortunately.

michaelsavage 06-13-2020 07:37 AM

The shell script from shruggy will add one of the images to the out.mp4 file. Even though I select multiple images, only the last image selected gets inserted into the out.mp4 file. Does anyone know how to add all of the selected images to the out.mp4 file?

Code:

#!/bin/bash
exec ffmpeg -framerate 1 ${@/#/-i } -vf scale=500:300 out.mp4


michaelk 06-13-2020 08:42 AM

Untested but I think you may need to create a string with the files names so the command format is like:

exec ffmpeg -framerate 1 -i file1 -i file2 -vf scale=500:300 out.mp4

Code:

infile=""
for arg in "$@"; do
  infile=$infile"-i \"$arg\" "
done

exec ffmpeg -framerate 1 $infile -vf scale=500:300 out.mp4

Which what shruggy's ${} code is supposed to do...

When you select the files in nemo are they all highlighted?

You can add some debug code to see what files are actually being selected.
Code:

echo "$@" >> /home/username/selected_files.dat

michaelsavage 06-13-2020 10:57 AM

michaelk

I added your code and the out.mp4 file did not get created. But it did create the dat file with the below information.

Quote:

/home/mike/Videos/acaproni_maldives.jpg /home/mike/Videos/adeole_yosemite.jpg /home/mike/Videos/agucklhorn-lake_brienz.jpg /home/mike/Videos/amarttinen_argentina.jpg /home/mike/Videos/amazing_sunset.jpg

michaelk 06-13-2020 11:49 AM

Forget my loop code...

Well at least the action is working correctly and multiple files are being sent to your script. Lets try a few more tests

From your /home/mike/Videos directory (just to make things simple) does the basic ffmpeg command work from the command line?

ffmpeg -framerate 1 -i acaproni_maldives.jpg -i adeole_yosemite.jpg -i agucklhorn-lake_brienz.jpg -vf scale=500:300 out.mp4

If that does not work it is a ffmepg syntax error and we need to go back to the man page... If that works then try adding some more debug code to your script.

echo "${@/#/-i }" >> /home/mike/selected_files.dat

michaelsavage 06-13-2020 11:52 AM

I also added a | less after the out.mp4 and received an error in the open terminal. It gave the full path to the first file I selected then with the error of "No such file or directory" I wasn't able to copy the output. As soon as I clicked on the terminal it when blank.

Code:

exec ffmpeg -framerate 1 $infile -vf scale=500:300 out.mp4 | less


The error looked like this
/full/path/to/the/file/name.jpg No such file or directory


michaelk 06-13-2020 12:02 PM

Forget nemo for the moment. Lets see if ffmpeg works as expected.

From the terminal try running

Code:

cd ~/Videos

ffmpeg -framerate 1 -i acaproni_maldives.jpg -i adeole_yosemite.jpg -i agucklhorn-lake_brienz.jpg -vf scale=500:300 out.mp4



All times are GMT -5. The time now is 10:15 AM.