1

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

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 it should be 1-Minute Audio Test for Stereo Speakers & Headphones [2ZrWHtvSog4].mp3

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

1 Answer 1

0
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"

To use the same output file name from the pipe as the input name with ffmpeg, you can modify the command as follows:

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:

  1. 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'.
  2. The $(...) syntax is used to execute a command and use its output as part of the larger command.
  3. $(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.

Replace test_audio.mp3 in your original command with the modified file name expression. This will create an output file with the same name as the video title retrieved from the URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.