Automator, AppleScript, Finder - The passing of the file name is strange - terminal

I have the following problem. I want to write a service in Automator. It should pass a file to an AppleScript action. That works too. Strangely, the path exists twice.
Automator AppleScript Code:
on run {input, parameters}
tell application "Terminal"
activate
set f to (input as text)
set thisPOSIXPath to (the POSIX path of f)
do script "/Applications/HandBrakeCLI --format av_mp4 --optimize --align-av --encoder x265 --quality 21 --vfr --first-audio --mixdown stereo --ab 192 --first-subtitle -i " & thisPOSIXPath & " -o /Desktop/FERTIG.m4v"
return input
end tell
end run
Terminal Output:
% /Applications/HandBrakeCLI --format av_mp4 --optimize --align-av --encoder x265 --quality 21 --vfr --first-audio --mixdown stereo --ab 192 --first-subtitle -i /Users/testuser/Desktop/Sample Videos _ Dummy Videos For Demo Use.mp4Macintosh HD/Users/testuser/Desktop/Sample Videos _ Dummy Videos For Demo Use.mp4Macintosh HD/Users/testuser/Desktop/Sample Videos _ Dummy Videos For Demo Use.mp4 -o /Desktop/FERTIG.m4v
Where does it come from?

Related

Passing file name in youtube-dl post-process script without file extension suffix

The documentation for youtube-dl says I can run a post-process command with the --exec option.
Using Windows, here is an example I have tried:
youtube-dl --exec "ffmpeg -i {} -ac 2 -c:a libfdk_aac -cutoff 20000 -afterburner 1 -vbr 0 {}.m4a" https://www.youtube.com/watch?v=sw9DlMNnpPM
Note that {} passes the file name to the post-process command. For example filename.webm.
The problem is that {} includes the file extension.
How can I pass the file name to the post-process command without the file extension?
For example, if I were to convert the video, I would rather avoid getting an output name like filename.webm.m4a. Needless to say, I would rather want filename.m4a.

Including Youtube-dl in FFMPEG not working in Bash (OSX)

I am trying to download 5 second samples for a list of youtube video. The traditional approach is to download the entire file with "youtube-dl" and then use "ffmpeg" to split it however you want it.
I am trying to use the following method: https://github.com/ytdl-org/youtube-dl/issues/622#issuecomment-162337869
It does work when I include the variables in the command, for example:
ffmpeg -ss 0 -i $(youtube-dl -f best --get-url https://www.youtube.com/watch?v=ySVi-0RS5vI&t=5s) -t 10 -c:v copy -c:a copy title2.mp4
However, I am having issues trying to automate the system. Specifically, I would like ffmpeg and youtube-dl to read a file and use the values. I created the file "youtube.txt" which includes the following codes:
440.8,https://www.youtube.com/watch?v=0-4wOE_DNeA,661.2,881.6,0-4wOE_DNeA
330,https://www.youtube.com/watch?v=0-AMWW6tHzw,495,660,0-AMWW6tHzw
509.2,https://www.youtube.com/watch?v=0-Rmto2rgMw,763.8,1018.4,0-Rmto2rgMw
427.6,https://www.youtube.com/watch?v=0-U53qm45cA,641.4,855.2,0-U53qm45cA
320.4,https://www.youtube.com/watch?v=0-dja9Ys4Sg,480.6,640.8,0-dja9Ys4Sg
343.6,https://www.youtube.com/watch?v=0-g_PulsqtM,515.4,687.2,0-g_PulsqtM
415.6,https://www.youtube.com/watch?v=0-nniRyn7dU,623.4,831.2,0-nniRyn7dU
431.2,https://www.youtube.com/watch?v=006BQU3BFxw,646.8,862.4,006BQU3BFxw
I am using the following command:
parallel -j 6 --colsep ',' ffmpeg -ss {1} -i $(youtube-dl -f best --get-url {2}) --t 5 -c:v copy -c:a copy {5} :::: youtube.txt
However, I get the following errors:
ERROR: '{2}' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:{2}" ) to search YouTube
--t: No such file or directory
Would you mind helping me?
Thanks!
Here's a solution using python2, so this should work on the python version shipped with MacOS. My original bash script was choking on the csv line reading for some reason. Add this script to getvids.py in the same directory as your youtube.txt, then run chmod +x getvids.py and when you're ready to turn it loose ./getvids.py
#!/usr/bin/python
import csv, os
with open('youtube.txt') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
starttimes = [row[0], row[2], row[3]]
yturl = os.popen('youtube-dl -f best --get-url '+row[1]).read().strip()
for thistime in starttimes:
print(row[1] + ' #time='+thistime)
os.system('ffmpeg -hide_banner -loglevel panic -ss '
+thistime+' -i "'+yturl+'" -t 5 -c copy '+row[4]+'['+thistime+'s].mp4')

Windows Console Output from Waifu2x-caffe unintelligible

I am using Waif2x to upscale a series of images, but I am having a problem with the command I am running. I would try to troubleshoot it myself, yet I can't not make use of the error output. It reads:
âGâëü[: âéâfâïâtâ#âCâïé¬èJé»é▄é╣é±é┼é╡é╜
I think it is in Japanese as evidenced by Waifu2x's Github page. I also believe it is the same everytime, yet I cant know for sure. I am using a English Computer, and I am also a English speaker, so I really need to know what it is in English or something I can Google translate.
I have already tried the solution here as evidenced by looking at the regedit, where Name=00, Data=Consolas.
Regarding my specific problem, the Command I am typing into cmd is
waifu2x-caffe-cui -i "C:\Users\Christian\workspace\CodeLyokoUpscaleing\bin\480Frames" -e png -l png -m noise_scale -d 16 -h 1440 -n 1 -p cudnn -c 256 -b 1 --auto_start 1 --auto_exit 1 --no_overwrite 1 -y upconv_7_anime_style_art_rgb -o "C:\Users\Christian\workspace\CodeLyokoUpscaleing\bin\1440Frames"
I really think it should work as I converted it from another batch file I created that contained variables instead of file paths
waifu2x-caffe-cui -i "%~dp0480Frames" -e png -l png -m noise_scale -d 16 -h 1440 -n 1 -p cudnn -c 256 -o "%~dp01440Frames" --auto_start 1 --auto_exit 1 --no_overwrite 1 -y upconv_7_anime_style_art_rgb
But I still get the weird output.
How can I see what the error is?

mplayer fail to get stdin stream from golang

I want to write a simple command line m3u8 player for Linux. (Let me know if there already one.)
There are several ts file urls in m3u8 file. m3u8 file is dynamically changed from network. Usually, one ts file has only a few seconds. So I need to download m3u8 file and ts files in it again and again. Then I use mplayer to play the stream continuesly. I suppose this is a network radio.
Here is what I have done:
First, I lauch mplayer process and get the stdin:
mplayer_cmd := exec.Command("sh", "-c", "mplayer -msglevel all=9 -cache 80 -")
mplayer_writer, mplayer_err := mplayer_cmd.StdinPipe()
Then, I get m3u8 file and ts urls in it and wget content of ts file and write it to stdin of mplayer. And I do this step again and again:
out, err = exec.Command("sh", "-c", "wget " + m3u8_url + " -qO - | grep '.ts'").Output()
...
out, err = exec.Command("sh", "-c", "wget " + ts_url + " -qO -").Output()
...
n, err = mplayer_writer.Write(out)
fmt.Println("wrote ", n)
No sound come out from mplayer. Comparing to a successful running from command line, there is such related error messsage:
Cache empty, consider increasing -cache and/or -cache-min. [performance issue]
A suspect info is that - mplayer fork a child process when lauch. Will stdin/stdout pipe broken in this situation?
| | \-+- 03027 hgneng mplayer -msglevel all=9 -cache 80 -
| | \--- 03033 hgneng mplayer -msglevel all=9 -cache 80 -
Sorry, it's my fault. I get the stdout pipe of mplayer somewhere for debug. However, the code hangs there because there is no output. I found this with godebug.

Controlling psftp in a Windows Batch File

How do I write a batch file to control psftp, but with a dynamic filename? Overall I'm trying to convert a video file and then upload it to my Apple TV. Here's what I have, it generally works, but the commands don't control psftp, psftp just waits for user input:
echo Convert and Upload to Apple TV file Called %1.mkv
ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
psftp frontrow#192.168.1.50 -pw aaa
cd downloads/boxee
put %1.avi
quit
I know with the -b flag psftp can call it's own batch file, but I don't know how to get the %1 argument to it. I've seen solutions where a text file is redirected to psftp, but that suffers from the same problem. Also, I'd prefer to have just one file, but having to call a second file would be alright too.
I ended up creating a new batch file from the main one that I then told psftp to use:
echo cd downloads/boxee > psftp.bat
echo put "%1.avi" >> psftp.bat
echo quit >> psftp.bat
psftp frontrow#192.168.1.50 -pw aaa -b psftp.bat
Specify a file containing batch commands
In normal operation, PSFTP is an interactive program which displays a command line and accepts commands from the keyboard.
If you need to do automated tasks with PSFTP, you would probably prefer to specify a set of commands in advance and have them executed automatically. The -b option allows you to do this. You use it with a file name containing batch commands. For example, you might create a file called myscript.scr containing lines like this:
cd /home/ftp/users/jeff
del jam-old.tar.gz
ren jam.tar.gz jam-old.tar.gz
put jam.tar.gz
chmod a+r jam.tar.gz
quit
and then you could run the script by typing
psftp user#hostname -b myscript.scr
Credit to http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html#6.1.3
All in one file:
#echo off
echo Convert and Upload to Apple TV file Called %1.mkv
ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
(
echo cd downloads/boxee
echo put %1.avi
echo quit
) | psftp frontrow#192.168.1.50 -pw aaa -bc
If we need the precise port number:
psftp frontrow#192.168.1.50 -P 222 -pw aaa -bc
Why not use the built in FTP command that comes with windows?
you will need to write a script that will upload the file:
open 192.168.1.50
user
frontrow
aaa
put file.avi
quit
then call ftp -s:MyScript
You will need to generate the script per each file using echo and the >> redirector.
I was struggling to run a simple batch file/script to have an end user upload a file she had just edited to a secure FTP site.
Using This Script:
cd /outgoing
put Examplefile.txt
# chmod a+r Examplefile.txt
# ren Examplefile.txt Exam.ted
# rm Examplefile.txt
quit
and running PuTTY's sftp command from a standard Windows command prompt:
psftp user#ftp.address.com -pw password -b testscript.scr
I was able to quickly and (more importantly!!) easily upload a file from the company I am doing work for to a company we needed to transact business with. You can also see I am ready to rename the file if needed (ren) or delete a file if needed (rm). The hash symbol (#) sets the lines as remark lines.
This allowed me to create a complete batch file in Windows that the end user could simply click on to upload the files as she generated them. It was MUCH simpler than using some of the other "flavors" of sftp I found on the 'Net and I have used and trusted PuTTY for decades.
If all you're doing with ftp is uploading a single file, you can use pscp.
echo Convert and Upload to Apple TV file Called %1.mkv
ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
pscp -pw aaa -sftp %1.avi frontrow#192.168.1.50:/downloads/boxee

Resources