I recently discovered youtube-dl and I wanted to make a batch file within the folder of the youtube-dl executable that asks for a url and uses that url in the
youtube-dl --extract-audio --audio-format mp3 -i -o songs\%(title)s.%(ext)s <video URL>
command, which saves the video as an mp3 file in the \songs\ folder in the same filepath as the executable. The command works fine if I copy-paste it into a command prompt and replace <video url> with the actual url, but when I try to put this in a batch file (e.g. with set var1="") it uses the variable's name in the command (youtube-dl --extract-audio --audio-format mp3 -i -o songs\%(title)s.%(ext)s var1).
I've found this, and it seems to be what I'm looking for, but it didn't make any sense.
When copying the command into a batch file, you'll need to replace % with %%, so that the output template parameter to the -o option will be interpreted correctly (i.e. as the string %(title)s.%(ext)s).
If you prefer to be prompted to enter the link, batch file may look like this:
set /p var1= "Enter youtube link: "
youtube-dl --extract-audio --audio-format mp3 -i -o songs\%%(title)s.%%(ext)s %var1%
Or, just set var1 before calling the script (set var1=youtube-link), or in the script itself.
Related
I am writing a shell script to download audio.
I used youtube-dl -f 'bestaudio[ext=m4a]' <myurl>
The resulting file is the title along with-mSc76Q90C4.m4a where m4a is the format
I would like to set the filename during download and also have it in .wav format
PS: To covert to .wav, I tried youtube-dl -f 'bestaudio[ext=wav]' <myurl> but it did not seem to work. Error thrown is basically - cannot use specified format.
Here is the relavent part of my shell script
`read -p "Copy and paste the YouTube url" URL
echo $URL
read -p "Enter the song name" SONG
youtube-dl -f 'bestaudio[ext=m4a]' $URL`
I would like the string in $SONG to be the filename.
So if $SONG = "mysongname"
I want the file to be mysongname.wav
In the documentation of youtube-dl you'll find a --output option that lets you set the filename directly:
youtube-dl -f 'bestaudio[ext=m4a]' -o "$SONG" "$URL"
There's also a --audio-format option that seems to convert the extracted audio stream from a video to a given audio format but I'm not sure that it'll work for non-video files.
I am concatenating a bunch of files on a windows 10 box into a single file using "ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4". This works fine when I generate list.txt in the required format.
What I am wanting is to not have to generate the file first and instead pipe the filenames in as the examples here show for *nix.
I have tried as follows "ffmpeg -f concat safe 0 -i <(for %i in (*.ts) do #echo file '%i') -c copy output.mp4" but I get "The system cannot find the file specified.".
Any idea's how to make this work?
Command substitution on Unix...
ffmpeg -i $(some-command-that-generates-an-url/path) [...]
...is possible on Windows through a for-loop:
FOR /F "delims=" %A IN ('some-command-that-generates-an-url/path') DO ffmpeg -i %A
Process substitution on the other hand, as you describe, isn't possible on Windows. Temporary files are inevitable.
I'm trying to execute a script that runs a Handbrake video conversion.
If I run the following command from the terminal, it works fine:
HandbrakeCLI -i inputtestfile.mp4 -o outputtestfile.mp4 -z "Preset"
If I put this into a .sh script (and give the script execution rights using chmod a+x), I get the following error:
HandbrakeCLI: Command not found
If I then put the full path to HandbrakeCLI, it then works, for example:
/usr/local/Cellar/handbrake/1.2.0/bin/HandBrakeCLI -i inputtestfile.mp4 -o outputtestfile.mp4 -z "Preset"
However, the above method is inconvenient because every time I update Handbrake to a new version, I'll have to update the script.
How can I add Path (I think this is right), to the script, so I can just use:
HandbrakeCLI -i inputtestfile.mp4 -o outputtestfile.mp4 -z "Preset"
Thanks
You can begin the .sh script with:
PATH=$PATH:/usr/local/Cellar/handbrake/1.2.0/bin
path is an environment variable that affects where sh would look unqualified files names (commands) from.
And for the changing version you can parse HandBrake --version output and use it as a variable instead of 1.2.0 string in PATH.
I have a Mac computer. Usually all my batch programming is done on my PC. So I tried to create what I assumed would be a simple equivalent using a Mac shell. Obviously as you all know that was foolish of me to think that. After 2 days of scowering the web I found the closest thing I could to what I was looking for. But no, this doesn't work either.
All I'd like to do is throw a multimedia file onto the script, and have the terminal give me the ffmpeg info output. In my searching I did find this "$#" which as far as I can tell is the windows bat equivalent of %*. Meaning you can throw files on the script and the script refers to those files as variables which can be processed. So I believe what I want to do is possible.
Again the code at the bottom is just to look through the current directory of all .mov files and run ffmpeg. It doesn't work. But.. if no one can help me figure out the actual thing I'd like to do then I'd settle with something like below that does actually work.
#!/bin/bash
FFMPEG=/Applications/ffmpeg
FIND=/usr/bin/find
FILES=$(${FIND} . -type f -iname "*.mov")
if [ "$FILES" == "" ]
then
echo "There are no *.mov file in $(pwd) directory"
exit 1
fi
for f in *.mov
do
$FFMPEG -i "$f"
done
If someone can please help me figure this out I'd really appreciate it. Thank you in advance! Jules
I just found this solution from the "similar questions" sidebar, which is similar to the script above, so again, not completely what I wanted but.. didn't matter, didn't work for me. How to batch convert mp4 files to ogg with ffmpeg using a bash command or Ruby
.command files don't receive dropped files as input.
You might just open a Terminal window, type for f in, drop the files on the window, and type ; do ffmpeg -i "$f"; done.
Or save a script like this as an application in AppleScript Editor:
on open argv
set paths to ""
repeat with f in argv
set paths to paths & quoted form of POSIX path of f & " "
end repeat
tell application "Terminal"
do script "for f in " & paths & "; do ffprobe -i \"$f\"; done"
activate
end tell
end open
ffprobe -i is like ffmpeg -i but it doesn't show an error like At least one output file must be specified.
Edit: you could also use Platypus:
Set the script to something like for f; do ffprobe -i "$f"; done.
This might do it:
for FILE in "${#}"
do
/Applications/ffmpeg -i "$FILE"
done
Situation:
AVI files sometimes come in two files filename-cd1.avi and filename-cd2.avi.
I use the following line in a bash script on my iMac to copy the two cd files into a single AVI file:
MENCODER -ovc copy -oac copy *CD1.avi *CD2.avi -o "Joined Movie.avi" > /dev/null 2>&1
What I'd like to do is retain the base file name. So:
of file name with '-cd2' is found, like say: OldMovie-cd2.avi
What I'm wanting to do is store "OldMovie" as a variable so that I can tell mencoder to perform the copy on the two files and… Here's the kicker - I'd LOVE to have resulting file be "OldMovie.avi" which is the base name of the two cd sub files.
Make sense? Geez I hope so.
Appreciate the help, I've googled for hours without a solution.
Randy
for avi in *-cd2.avi; do
base=`echo $avi | sed 's+-cd2\.avi+$\.avi+g'`
echo base is $base
echo looking for ${base}-cd1.avi
if [ -f "${base}-cd1.avi" ]; then
echo Found ${base}-cd1.avi
MENCODER -ovc copy -oac copy ${base}-cd1.avi ${base}-cd2.avi -o "${base}.avi" > /dev/null 2>&1
else
echo Did not find ${base}-cd1.avi
fi
done