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?

Community
  • 1
  • 1
bawse
  • 130
  • 4
  • 21
  • `ffmpeg` supports [libflite](https://ffmpeg.org/ffmpeg-filters.html#flite) which can make audio from text files. – llogan Sep 11 '15 at 14:35

2 Answers2

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
Manuel Barbe
  • 2,104
  • 16
  • 21
4

You can use command substitution here in the middle argument:

ffmpeg -i "$(echo 'Hello' | somecommand)" -f mp2 output.mp3 
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • `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 '15 at 07: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 '15 at 07: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 '15 at 07:08
  • Does `text2wave` writes output on terminal that you want to use in `ffmpeg` command? – anubhava Sep 11 '15 at 07:10
  • no, text2wave creates an output wav file that I want to use in ffmpeg – bawse Sep 11 '15 at 07:11
  • In that case your question was little misleading since pipes are used to pass output of previous command to next command. You can try this command: `ffmpeg -i "$(text2wave -o -)" -f mp2 output.mp3` where `text2wave -o -` will write output on stdout. – anubhava Sep 11 '15 at 07:13
  • That doesn't work, it just writes all of the wav encoding on to the screen and attempts to use that as a filename..I need the filename of the output file from text2wave – bawse Sep 11 '15 at 07:18
  • in that case use it separately but on same line: `text2wave -o file.wav && ffmpeg -i "file.wav" -f mp2 output.mp3` – anubhava Sep 11 '15 at 07:21