2

I'm trying to get the output name to be the same as the input name while using the pipe command in ffmpeg.

Example:

The file is called 1-Minute Audio Test for Stereo Speakers & Headphones [2ZrWHtvSog4].m4a. I'm trying to get the output filename to be automatically the same as the input file name but with the .mp3 extension.

So the final name should be 1-Minute Audio Test for Stereo Speakers & Headphones [2ZrWHtvSog4].mp3 without having to type it in manually.

Example:

yt-dlp -o - -f 139 --external-downloader aria2c --external-downloader-args '-d ./ -x 10' https://www.youtube.com/watch?v=2ZrWHtvSog4 | ffmpeg -i pipe: -codec:a libmp3lame -b:a 8000 -ac 1 -ar 8000 test_audio.mp3

These commands create a file called test_audio.mp3 I'm trying to get it to be 1-Minute Audio Test for Stereo Speakers & Headphones [2ZrWHtvSog4].mp3 without having to type it in.

I'm not sure how to pipe / get the file name variable from the input file to the output file of ffmpeg.

My thoughts were to:

  1. Get the file name from yt-dlp and place that in a variable.
  2. Use that variable as the output file name with ffmpeg
Destroy666
  • 12,350
Rick T
  • 163

1 Answers1

0

Here's what worked for me.

yt-dlp -o - -f 139 --external-downloader aria2c --external-downloader-args '-d ./ -x 10' https://www.youtube.com/watch?v=2ZrWHtvSog4 | ffmpeg -i pipe: -codec:a libmp3lame -b:a 8000 -ac 1 -ar 8000 -f mp3 "$(basename "$(yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4 | sed 's/[\/:*?"<>|]/_/g')").mp3"

Explanation:

The basename command is used to extract the base name from the URL. It retrieves the video title using yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4 and then replaces any characters that are not allowed in file names with underscores using sed 's/[/:*?"<>|]/_/g'.

The $(...) syntax is used to execute a command and use its output as part of the larger command.

$(basename "$(yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4 | sed 's/[/:*?"<>|]/_/g')").mp3 is the resulting file name with the .mp3 extension added.

Rick T
  • 163