Closed joeynotjoe closed 6 years ago
At a glance, I think your snippet should be working, I'll try to see why it wouldn't.
Regarding the extensibility suggestion, we could make the ffmpeg command configurable. Let's say we create the following simple shell script encode.sh
:
#!/bin/sh
ffmpeg "$@"
noti
we'd set ffmpeg_command=/path/to/encode.sh
in encode.conf and enjoy notifications when encoding without touching any lua.
Unfortunately, with this approach you can't use the builtin variables. But at least it's simple and adresses some use-cases. It's also not very flexible since the script just gets the ffmpeg arguments as-is, but if your needs are more elaborate, you're probably better serviced by modifying the script directly.
Sorry, my original message wasn't clear. The snippet I shared above is indeed working, but if I try and add in more commands or parameters, it fails. For instance, I was trying to use terminal-notifier to generate a more rich notification than what Noti offers. When I try and cut a clip, it shows the notification properly, but the clip doesn't encode. Here is my snippet for this code that's failing:
local args = {
"terminal-notifier",
"-title", 'IINA',
"-message", 'Encoding Complete',
"-subtitle", mp.get_property("filename/no-ext"),
"-appIcon", 'https://cl.ly/rZzd/iina.png',
"ffmpeg",
"-loglevel", "panic", "-hide_banner", --stfu ffmpeg
"-ss", seconds_to_time_string(from, false),
"-i", input_path,
"-to", tostring(to-from),
}
The part that confuses me is that I am getting the terminal-notifier message perfectly, but if I check the code from the log, that code is different. I can run the ffmpeg portion in terminal successfully, but I must be missing something. I'm talking about this portion specifically:
terminal-notifier Encoding Complete -subtitle Big Buck Bunny -appIcon https://cl.ly/rZzd/iina.png ffmpeg -loglevel panic -hide_banner -ss 00:56.000 -i "/Users/jmurphy/Movies/TV/Big Buck Bunny.mkv" -to 10.020833333333 -map 0 -c copy "/Users/jmurphy/Movies/Clips/Big Buck Bunny [RAW] - 0:00:56.000 - 0:01:06.020.mp4"
Thanks for looking into this!
That's because terminal-notifier
behaves differently from noti
.
noti
treats the trailing arguments (after the ones it recognizes) as a command to run, takes care of running ffmpeg itself and prints the message after the command is finished.
On the other hand, terminal-notifier
doesn't do that, and I'm guessing it just ignores anything it doesn't recognize (so all args after your .png) which is why nothing happens. This means that you cannot run both ffmpeg
and terminal-notifier
in the same subprocess without using a wrapper script.
🤦♂️ That makes a whole lot of sense, haha. So I have to do some research on wrapper scripts!
Thanks a bunch for adding this!
If you have a super basic example of a wrapper script that could work, that would be really helpful. I'm not sure how to call ffmpeg properly.
If I figure it out, I'll post something here.
Yes actually that's what I mentioned in my first comment. Basically the shell script encode.sh
receives the ffmpeg arguments and takes care of calling ffmpeg itself (it simply forwards the arguments using "$@"
), followed by a call to noti once ffmpeg returns. A more elaborate version could use the last argument (i.e. the output filepath) in the noti invocation for a more elaborate notification.
You need to make sure that the script is executable, and that ffmpeg_command
is set to the full path of the script (or that the script is part of your PATH).
Hello there @occivink - sorry to jump back into this closed thread, but I figured I might be missing something. If there's a new issue in the code, I can create a new issue.
I was wondering- I'm trying to reference my Home folder in the encode.conf > ffmpeg_command section, and I noticed that I have to put the full path in order for it to work. But just a couple lines up, in the Output directory, I don't need to use the full path - I can use a home directory shortcut, such as ~/. This is beneficial, because I can use the script on other machines without needing the full path of the home folder.
I tried using $HOME, ${HOME}, and ~/ but none of them seem to work. I tried checking the logs, but it just says subprocess failed, init.
Do you have any ideas?
Thanks so much!
Here is my .conf file:
only_active_tracks=no
preserve_filters=no
append_filter=
codec=-c copy
output_format=$f - $s - $e.$x
output_directory=~/Movies/Clips/
detached=yes
ffmpeg_command=/Users/joeynotjoe/Config/shell/encode_raw.sh
print=yes
Yes, that's because I implemented special handling for ~
in output_directory, but not for ffmpeg_command. You could either
Users/joeynotjoe/Config/shell
to your PATH (I presume that exists too on macos), and use ffmpeg_command=encode_raw.sh
~
handling when I have the time (it's as trivial as doing this)Wow, awesome. Thanks so much for the quick response! I think that implementing the same ~
handling would be ideal, as it would again prevent the need to make any special edits or changes when going from one machine to the next.
Thanks again, Olivier!
Hello, I have been modifying encode.lua in an effort to include some custom commands before the encode command, such as running Noti. I have been successful in getting that one to work by itself, but if I try and add in other commands in the Args section, I run into problems. I don't see much info in the logs, just the line of the command that was run, but no mention of the failures.
Is there a better way to include these types of commands? Maybe a better spot in the code than the args?
This is what I have now, which is indeed working (however, I could not get the timestamp of the encode to work in the -m flag portion, but it did work with -t... but I am also very much an amateur when it comes to Lua)
It would be cool if there was a place in the config, preferably in the profile .conf settings, where you could define any other commands to be run before or after the script. Bonus points if those commands can reference the variables like
$t
or$s
, as that would be super beneficial.Thanks so much for your invaluable script!