Answers.Body: <pre><code>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 &quot;$(basename &quot;$(yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4 | sed 's/[\/:*?&quot;&lt;&gt;|]/_/g')&quot;).mp3&quot;
  </code></pre>
  <p>To use the same output file name from the pipe as the input name with <code>ffmpeg</code>, you can modify the command as follows:</p>
  <pre class="lang-bash prettyprint-override"><code>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 &quot;$(basename &quot;$(yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4 | sed 's/[\/:*?&quot;&lt;&gt;|]/_/g')&quot;).mp3&quot;
  </code></pre>
  <p>Explanation:</p>
  <ol>
  <li>The <code>basename</code> command is used to extract the base name from the URL. It retrieves the video title using <code>yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4</code> and then replaces any characters that are not allowed in file names with underscores using <code>sed 's/[\/:*?&quot;&lt;&gt;|]/_/g'</code>.</li>
  <li>The <code>$(...)</code> syntax is used to execute a command and use its output as part of the larger command.</li>
  <li><code>$(basename &quot;$(yt-dlp -e https://www.youtube.com/watch?v=2ZrWHtvSog4 | sed 's/[\/:*?&quot;&lt;&gt;|]/_/g')&quot;).mp3</code> is the resulting file name with the <code>.mp3</code> extension added.</li>
  </ol>
  <p>Replace <code>test_audio.mp3</code> 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-24T16:18:34.120Z
Answers.LastActivityDate: 2023-05-24T16:18:34.120Z
Answers.UserDisplayName: Rick T
Body: <p>I'm trying to get the output name to be the same as the input name while using the pipe command in ffmpeg.</p>
  <p>The file is called <strong>1-Minute Audio Test for Stereo Speakers &amp; Headphones [2ZrWHtvSog4].m4a</strong>
  I'm trying to get the <strong>output filename</strong> to be <strong>automatically</strong> the same as the <strong>input file name</strong> but with the <strong>mp3</strong> extension.</p>
  <p>So the final name should be <strong>1-Minute Audio Test for Stereo Speakers &amp; Headphones [2ZrWHtvSog4].mp3</strong> without having to type it in manually.</p>
  <p><strong>Example:</strong></p>
  <pre><code>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
  </code></pre>
  <p>These commands create a file called <strong>test_audio.mp3</strong> it should be <strong>1-Minute Audio Test for Stereo Speakers &amp; Headphones [2ZrWHtvSog4].mp3</strong></p>
  <p><strong>I'm not sure how to pipe the name variable from the input file to the output file of ffmpeg.</strong></p>
  
Tags: <ffmpeg><bash>
Title: Use same output file name from pipe as input name with ffmpeg
UserDisplayName: Rick T
ThreadText: # Use same output file name from pipe as input name with ffmpeg
  
  (Asked by: username_0 on 2023-02-03)
  
  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.**
  
  **Tags:** ffmpeg, bash
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-05-24. Score: 0 | Accepted answer
  
  ```
  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:
  
  ```bash
  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.
  
  
  ---
  
  