This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Desktop entry to convert audio/video files (Dolphin)

Tags: dolphin, servicemenu dolphin, servicemenu dolphin, servicemenu
(comma "," separated)
benjamind
Registered Member
Posts
9
Karma
0
My question: I'd like to create a desktop entry in (kde dolphins servicemenu) to convert audio/video files.

I have tried it with the following:

Code: Select all
[Desktop Entry]
Actions=Convertwav2Mp3
Icon=audio-x-flac
MimeType=audio/*
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel

[Desktop Action Convertwav2Mp3]
Exec=ffmpeg -i %f -codec:a libmp3lame -b:a 320k .out.mp3 && mv .out.mp3 %f
Icon=audio-x-flac
Name=Convertwav2Mp3


Works like a charm when put in /usr/share/kservices5/ServiceMenus/.

BUT: The mv command renames the output file to the original filename with its file extension (which is wav but should be mp3).

How can i change the command as to rename it from file.wav to file.mp3 within the Exec field?
airdrik
Registered Member
Posts
1854
Karma
5
OS
There are several user-contributed service menus on the kde store such as this one for converting to mp3/ogg that you can look at to see how to others have set these service menus up.
(though, depending on what the tool does with file names, you may need to use a little more shell magic to replace the extension; it looks like that mp3/ogg converter just tacks the new extension onto the end of the file name)

btw, the per-user directory for service menus is ~/.local/share/kservices5/ServiceMenus/


airdrik, proud to be a member of KDE forums since 2008-Dec.
benjamind
Registered Member
Posts
9
Karma
0
Thanks for the reply but i have already checked some scripts from the kde store and still i face the problem, that the file extension is doubled. Means after conversion the name is file.wav.mp3 what is quite annoying. Any hints how to solve this?
User avatar
cipricuscprq
Registered Member
Posts
23
Karma
0
Here's the command from a service menu that I have to extract audio from mp4 video. It might be helpful for the naming part.

Code: Select all

bash -c 'ffmpeg -i "$0" -map 0:1 -c:a copy "${0%%.*}".m4a' %f

User avatar
scooob
Registered Member
Posts
2
Karma
0
You don't have to use the bash command, do you? After all, you can call the library and immediately write all the actions that need to be performed with the file.
Code: Select all
$ ffmpeg -i "$0" -map 0:1 -c:a copy "${0%%.*}". m4a'%f
and everything should work the same way.
User avatar
kingboob
Registered Member
Posts
1
Karma
0
And if i don't know much about console commands and these libraries? It's just that, for example, I didn't work with the console at all, if I do something wrong, there won't be any problems, will there? No system files will be damaged?
User avatar
scooob
Registered Member
Posts
2
Karma
0
Here you do not work with system files, you only specify the name of the file you want to change. If you really don't want to understand everything, there are many programs with a free trial period. So that you can convert video and audio files.
dzon
Registered Member
Posts
493
Karma
3
As mentioned here before, there are plenty of convert service menus available. Just out of curiosity though, what happens when you use the kdemv5 command instead of mv ?
But frankly, if you want to move the converted file, you'd need to add a destination directory, either fixed or by a zenity command.
If you just want to convert to mp3, you might use: ffmpeg -i %u -y %u.mp3


This realm's name is Maya. And she speaks Hertz. But Ahamkara makes a fuzz about it.
dzon
Registered Member
Posts
493
Karma
3
I made a single service menu for all kinds of converting. If you want it...

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=video/*;audio/*
Actions=convert-webm;convert-mp4;convert-avi;convert-ogg;convert-mkv;convert-mp3;convert-wav;convert-flac
X-KDE-Submenu=Convert
Icon=video-mp4

[Desktop Action convert-webm]
Name=Convert to webm
Icon=video-webm
Exec=ffmpeg -i %u -y %u.webm

[Desktop Action convert-mp4]
Name=Convert to mp4
Icon=video-mp4
Exec=ffmpeg -i %u -y %u.mp4

[Desktop Action convert-avi]
Name=Convert to avi
Icon=video-mp4
Exec=ffmpeg -i %u -y %u.avi

[Desktop Action convert-ogg]
Name=Convert to ogg
Icon=video-x-ogm+ogg
Exec=ffmpeg -i %u -y %u.ogg

[Desktop Action convert-mkv]
Name=Convert to mkv
Icon=video-mp4
Exec=file=%f; ffmpeg -i %f -codec copy -strict -2 "${file%.*}.mkv"

[Desktop Action convert-mp3]
Name=Convert to mp3
Icon=audio-mp3
Exec=ffmpeg -i %u -y %u.mp3

[Desktop Action convert-wav]
Name=Convert to wav
Icon=audio-x-wav
Exec=ffmpeg -i %u -y %u.wav

[Desktop Action convert-flac]
Name=Convert to flac
Icon=audio-flac
Exec=ffmpeg -i %u -y %u.flac


This realm's name is Maya. And she speaks Hertz. But Ahamkara makes a fuzz about it.
ofericsims
Registered Member
Posts
3
Karma
0
Don't you think it's an extra problem in vain as long as there are so many free converters on the internet? But if you still want to create something for yourself, there are several user-contributed service menus on the kde store such as this one for converting to mp3 / ogg that you can look at to see how others have set these service menus. I tried this a while ago to convert mp4 to avi, and I called the library and immediately wrote all the actions that needed to be performed with the file.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]