2

In a command line, if I run:

ffmpeg -i inputVideo.mp4 -vn -f mp4 -acodec copy outputAudio.aac

everything works perfectly fine. However if I do the same thing, except standard out instead of the output file ("pipe:1" instead of "outputAudio.aac") then I get this error: "Could not write header for output file #0 (incorrect codec parameters ?)"

Help from anyone with ffmpeg experience is greatly appreciated

Thanks

fefwfefefwfwe
  • 1,505
  • 2
  • 11
  • 19

1 Answers1

1

Well the trouble is you are asking for a mp4 file with a filename of outputAudio.aac. So if you check outputAudio.aac it is actually a mp4 file. To write mp4 files ffmpeg will need a seekable file descriptor which stdout is not. [this is because mp4 moov atom is written at the end in the beginning of the file.
If you want aac to be dumped to stdout you should ask for a adts file

ffmpeg -i input.mp4 -acodec copy -vn -f adts -strict -2 -

If you need it in a mp4.. mux it after that into a file

mp4 is not a streaming format: see here Fix 3GP file after streaming from Android Media Recorder for my answer to a different question which explains this.

Community
  • 1
  • 1
av501
  • 6,645
  • 2
  • 23
  • 34
  • amazingly, this did work. thank you. it raises a new issue though. the end goal is having this audio stream in a browser (html5 audio), and at the least, chrome does not like what this is outputting. chrome will play aac, so that means what this is outputting isn't really aac... – fefwfefefwfwe Aug 29 '12 at 07:25
  • @mhuusko5, It is aac. It is aac with adts headers. Find out whether chrome needs raw aac or adts. If it needs raw aac you need to have your own program in the middle to strip off adts headers from ffmpeg output because ffmpeg won't output raw aac to stdout. – av501 Aug 29 '12 at 09:07
  • Yeah I do need raw AAC. ffmpeg will output this to a file, but no standard out... Why? And could I trick it to somehow? Do you know if mplayer/mencoder could do this job better, and just strip the aac to standard out? – fefwfefefwfwe Aug 29 '12 at 16:48
  • You may have to change some of its source code. The thing is aac is unplayable unless it has the adts headers or is part of a container which has the right header to make it play. Other time when it goes out raw is rtp stream in mpeg4-latm form – av501 Aug 29 '12 at 19:01
  • Safari officially supports AAC. Chrome also officially supports AAC. However the output from the above command only plays in Safari... do you have any idea why this would be? I really appreciate the insight. – fefwfefefwfwe Aug 29 '12 at 22:53
  • Actually, I did some deeper reading, and found out that Safari will play ADTS because safari falls back on installed quicktime components. Chrome/Firefox/IE support AAC, but it needs to be AAC in M4A format. Isn't M4A the audio component of MP4? Shouldn't I be able to get M4A in standard out? – fefwfefefwfwe Aug 29 '12 at 23:03
  • M4a is the same as mp4. Just a different name to indicate that it has only audio. You will not be able to pipe out mp4 though. See this thread to understand why http://stackoverflow.com/questions/11994470/fix-3gp-file-after-streaming-from-android-media-recorder/12167100#12167100 I have explained here why mp4 is not streamable because of which you will not get output on stdout. – av501 Aug 30 '12 at 06:42