ffxsam
ffxsam

Reputation: 27763

How to get ffmpeg to encode once and mux twice, plus options?

I've read up on -f tee, but I can't wrap my head around how to do what I want.

I'd like to read in an audio file, encode once, and dump out a single mp3 file as well as mp3 HLS segments. In other words, the separate commands would be:

$ cat file.wav | ffmpeg -y -i pipe:0 -c:a libmp3lame -q:a 0 -map 0:0 -f segment -segment_time 10 -segment_list /tmp/segments.m3u8 -segment_format mpegts -vn /tmp/segment_%03d.ts

and

$ cat file.wav | ffmpeg -y -i pipe:0 -c:a libmp3lame -q:a 1 /tmp/working.mp3

(note the different qscale value in the 2nd command)

I can't quite figure out how to apply different command line options to each output.

EDIT: I'm a bit closer to a solution, I think:

$ ffmpeg -y -i pipe:0 -c:a libmp3lame -map 0:0 -f tee -vn '[q\:a=1]/tmp/working.mp3|[q\:a=0:f=segment:segment_time=10:segment_list=/tmp/segments.m3u8:segment_format=mpegts]/tmp/segment_%03d.ts'

But escaping via q\:a isn't working:

[tee @ 0x7fe897815600] No option found near "q:a=1]/tmp/working.mp3"
[tee @ 0x7fe897815600] Slave muxer #0 failed: Invalid argument, continuing with 1/2 slaves.
[tee @ 0x7fe897815600] No option found near "q:a=0:f=segment:segment_time=10:segment_list=/tmp/segments.m3u8:segment_format=mpegts]/tmp/segment_%03d.ts"
[tee @ 0x7fe897815600] All tee outputs failed.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Conversion failed!

Upvotes: 0

Views: 453

Answers (1)

Gyan
Gyan

Reputation: 93221

If you're encoding once, you can't have two q:a values - there's only one encoding instance. You can simply encode twice and mux both outputs in one command.

$ cat file.wav | ffmpeg -y -i pipe:0 -c:a libmp3lame -q:a 0 -map 0:0 -f segment -segment_time 10 -segment_list /tmp/segments.m3u8 -segment_format mpegts -vn /tmp/segment_%03d.ts -c:a libmp3lame -q:a 1 /tmp/working.mp3

Upvotes: 1

Related Questions