4

Somewhat related to this question: Convert audio files to mp3 using ffmpeg

I want to execute a command in one line using piping in BASH.

What I am trying to do is this:

echo "Hello" | somecommand | ffmpeg -i _____ -f mp2 output.mp3 

Where the _____ is the output of somecommand. Is there any way to achieve this?

1
  • ffmpeg supports libflite which can make audio from text files.
    – llogan
    Sep 11, 2015 at 14:35

2 Answers 2

9

Try using xargs

echo "Hello" | somecommand | xargs ffmpeg -f mp2 output.mp3 -i

or

echo "Hello" | somecommand | xargs -i ffmpeg -i {} -f mp2 output.mp3
2
  • 1
    xargs -i is my new best friend!
    – mhand
    Feb 6, 2020 at 4:27
  • xargs -i is deprecated, use xargs -I{}
    – SteeveDroz
    Feb 10, 2023 at 16:20
4

You can use command substitution here in the middle argument:

ffmpeg -i "$(echo 'Hello' | somecommand)" -f mp2 output.mp3 
8
  • somecommand actually represents the text2wave function, so how would I get the output .wav file from that and pass it into ffmpeg?
    – bawse
    Sep 11, 2015 at 7:03
  • Yes same line syntax is what I've shown. It will be: ffmpeg -i "$(echo 'Hello' | text2wave)" -f mp2 output.mp3
    – anubhava
    Sep 11, 2015 at 7:06
  • I get an error saying "file name too long" When I run that in terminal. In order to actually save to a .wav file, it has to be done like this: text2wave -o file.wav
    – bawse
    Sep 11, 2015 at 7:08
  • Does text2wave writes output on terminal that you want to use in ffmpeg command?
    – anubhava
    Sep 11, 2015 at 7:10
  • no, text2wave creates an output wav file that I want to use in ffmpeg
    – bawse
    Sep 11, 2015 at 7:11

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.