Looks like everyone here has their scripts to automate the routine tasks.
I have never wrote any scipt but having s set of them definitely seems as a better idea compare to running exiftool / ffmpeg / whatever commands in terminal.
As you can see in.mp4 is in the beginning of the command and out.mp4 is at the end of the command which makes drag’n’drop files to terminal a pain in the neck.
What I would like to do is to select files in Dolphin - Right Click and select a script I want from the menu.
For this particular command it would use selected files as inputs and save the output files in the same directory while adding codec name to the end of the file name. For example:
/home/user/video_file_1.mp4 would be converted and saved as /home/user/video_file_1_x264.mp4
I was wondering if anyone has a similar script already written that could be shared or if there is any good documentation on the web that would help me start writing my scripts.
Since there are many languages out there (bash, python, etc.) and I am not familiar with any of them I would start with the one that is:
Easy to learn (faster to start writing)
Linux Desktop Environment undependable (I am on KDE at the moment but I don’t want to lock myself into it).
If you want to right click in dolphin, you’ll likely end up with a solution that is desktop dependant, which is at odds with what you asked for near the end of the post.
For a first scripting language, I always say bash, it’ll get you most of what you need in the beginning, despite being a little quirky. It’ll also just let you run commands that you’d run in the normal terminal.
For your script, I’d just run it from the terminal, not from dolphin, and I’d replace in.mp4 and out.mp4 with $1 and $2 and put it all in a shell script. Then you can call scriptName.sh in.mp4 out.mp4 and it’ll use the command in the script, subbing $1 and $2 from the script with what you’ve specified.
Code - Description
%f - A single file name (including the path), even if multiple files are selected. The system reading the desktop entry should recognize that the program in question cannot handle multiple file arguments, and it should should probably spawn and execute multiple copies of a program for each selected file if the program is not able to handle additional file arguments. If files are not on the local file system (i.e. are on HTTP or FTP locations), the files will be copied to the local file system and %f will be expanded to point at the temporary file. Used for programs that do not understand the URL syntax.
%F - A list of files. Use for apps that can open several local files at once. Each file is passed as a separate argument to the executable program.
%u - A single URL. Local files may either be passed as file: URLs or as file path.
My script is now working but it tries to convert all files in the folder to mp4 e.g. jpegs and creates mp4-named copies of the jpegs. I am using
For ‘ls’ in filename
And then
ffmpeg -i $filename …
I am wondering if there is a better way to search for files by extension and export the output to an argument. I could not make “find” command working for me. Been googling for last 2 hours.
Any ideas?
Hello Morgan,
Thank you very much for taking the time to look into this.
I wish I saw your script before writing mine.
The script works just fine but what I what I found out is that actually some metadata gets lost/changed during the ffmpeg conversion even though the -map_metadata 0 option is activated.
Bento4 SDK Suit can copy the atoms containing the metadata from the original file to the compressed one.
So I am trying to add the following actions to the script:
First of all, download bento4 SDK and add the arguments to the script: (I guess you can skip this step if you compiled it from sources.) mp4extract="/path/to/static/build/mp4extract" mp4edit="/path/to/static/build/mp4edit"
Then # Do the conversion. count="1" for f in "$@"; do
Step 1 - Extraction of the udta atom from each video file (filename.mp4) to a corresponding txt file (filename.txt): mp4extract moov/udta "${f}" ${f%.*}.txt
Step 2 - Compression of each original video file (filename.mp4) to filename_suffix.mp4 using ffmpeg: ffmpeg -i "${f}" -y -f mp4 -c:a "${ca}" -b:a "${ba}" -c:v "${cv}" -crf "${crf}" -preset "${preset}" -map_metadata 0 "${f%.*}_${cv}_${crf}_${preset}.mp4" || exit 1
Step 3 - Import the metadata from the txt files (filename.txt) to the compressed mp4 videos (filename_suffix.mp4).
Here is the code I wrote for this: for FILE in *.txt; do BASE=${FILE%.txt} if [ -e "$BASE.txt" ]; then echo -e "\033[1;34m Importing metadata from "$BASE.txt" to "$BASE.mp4" / "$BASE_gps.mp4"\033[0m" mp4edit --insert moov:"$BASE.txt" "$BASE.mp4" "$BASE_gps.mp4" fi done
but I don’t know if the code actually works. I simply don’t get to the step 3 because the step 1 does not work.
The command works just fine when I run it in the terminal and drag a file there, e.g. /path/to/Bento4-SDK-1-5-0-614.x86_64-unknown-linux/bin/mp4extract moov/udta '/path/to/filename.mp4' '/path/to/filename.txt'
but if mp4extract being called via a script I get this error: Open: open(moov/udta) failed (src/mp4file.cpp,398)
I am wondering why there is a difference between running mp4extract in the terminal and calling it via a bash script. Any ideas? https://www.bento4.com/
@Morgan_Hardwood I just finished working on version 1.0 of the script and wondering what is the right way to publish it on GitHub. I created a repository but not sure how I can upload a file there. Also I can create a gist but I don’t know what gist is. Gists are a pain in the neck to find from mobile device as well. Can you advise ?