LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-09-2020, 11:26 AM   #1
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Rep: Reputation: 11
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.
 
Old 06-09-2020, 11:56 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
%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

Last edited by shruggy; 06-09-2020 at 02:28 PM.
 
1 members found this post helpful.
Old 06-09-2020, 03:15 PM   #3
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Original Poster
Rep: Reputation: 11
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
 
Old 06-09-2020, 03:25 PM   #4
cordx
Member
 
Registered: Oct 2018
Location: texas
Distribution: bodhi 5.1.0
Posts: 797

Rep: Reputation: 184Reputation: 184
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

Last edited by cordx; 06-09-2020 at 03:28 PM. Reason: clarity
 
1 members found this post helpful.
Old 06-09-2020, 03:54 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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?

Last edited by shruggy; 06-09-2020 at 04:01 PM.
 
Old 06-09-2020, 04:15 PM   #6
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Original Poster
Rep: Reputation: 11
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.
 
Old 06-09-2020, 04:35 PM   #7
cordx
Member
 
Registered: Oct 2018
Location: texas
Distribution: bodhi 5.1.0
Posts: 797

Rep: Reputation: 184Reputation: 184
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;

Last edited by cordx; 06-09-2020 at 04:35 PM. Reason: wording
 
Old 06-10-2020, 07:20 AM   #8
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Original Poster
Rep: Reputation: 11
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)
 
1 members found this post helpful.
Old 06-10-2020, 05:18 PM   #9
cordx
Member
 
Registered: Oct 2018
Location: texas
Distribution: bodhi 5.1.0
Posts: 797

Rep: Reputation: 184Reputation: 184
i don't see anything that seems particularly helpful there unfortunately.
 
Old 06-13-2020, 07:37 AM   #10
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Original Poster
Rep: Reputation: 11
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

Last edited by michaelsavage; 06-13-2020 at 08:36 AM.
 
Old 06-13-2020, 08:42 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,701

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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

Last edited by michaelk; 06-13-2020 at 10:24 AM.
 
Old 06-13-2020, 10:57 AM   #12
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Original Poster
Rep: Reputation: 11
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
 
Old 06-13-2020, 11:49 AM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,701

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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
 
1 members found this post helpful.
Old 06-13-2020, 11:52 AM   #14
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Original Poster
Rep: Reputation: 11
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
 
Old 06-13-2020, 12:02 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,701

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
x11vnc: clipboard and right click menu(context menu) "Paste" item not in sync Vilius Linux - Desktop 0 11-17-2017 11:46 PM
When right/left clicking for a context menu to appear, it display a pitch black menu pupuela Linux - Newbie 4 08-07-2014 06:54 AM
How to modify the library path variable?modify the Electronkz Linux - Newbie 1 04-13-2004 06:18 AM
modify file access & modify timestamps i2itstud Linux - General 1 05-20-2003 03:34 AM
Help with icewm - Remove RightClick context menu from taskbar Glenn Albrecht Linux - Software 2 11-15-2002 01:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration