[FFmpeg-user] Use concat demuxer with input format

Hans Carlson forbyta at gmx.com
Mon Jul 17 00:19:44 EEST 2017


On Sun, 16 Jul 2017, Nicolas George wrote:

> Le septidi 27 messidor, an CCXXV, Hans Carlson a écrit :
>>   $ ffmpeg -f s16le -ac 2 -f concat -i concat-raw.txt ...
>> or
>>   $ ffmpeg -f concat -f s16le -ac 2 -i concat-raw.txt ...
>>
>> I've tried both and it doesn't work, so I assume it's either not supported
>> or I'm doing something wrong.
>
> That cannot work, the second -f option is just overriding the first one.

I kind of figured that's what was happening.

> You would need to specify the format and options in the concat script 
> itself, as they could be different for each file. But it is not 
> implemented yet.

"... not implemented yet"?  Does that mean it's currently in the works? 
Or just something that has been considered, but no work has been done?

> Since PCM is just a sequence of uncompressed samples, you can use the 
> concat PROTOCOL to join them, and the subfile protocol to extract part 
> of them. You just need a little arithmetic to convert from timestamp to 
> octet offset.

I had tried to use subfile, but at the time, was still using it with the 
concat DEMUXER.  I quickly realized that has the same problem... still 
need to specify the -f option twice and only the 2nd one is used.  But I 
hadn't considered using subfile and the concat PROTOCOL.  That does seem 
to work... at least with my test case:

   $ ffmpeg -f s16le -ac 2 -i 'concat:subfile,,start,5292000,end,47628000,,:file1.raw|subfile,,start,1764000,end,28224000,,:file2.raw' -codec mp3 test.mp3

To calculate the subfile offset sizes, I multiplied the start/end times by 
176400 (which is the filesize=[52920320] / duration=[300.001814]).  So, 
for file1.raw, inpoint=30 = (176400 * 30 = 5292000) and outpoint=270 = 
(176400 * 270 = 47628000).

I checked 200+ PCM (s16le) files and the multiplier was virtually the same 
for all of them 176400 (+/- ~0.0005). So is 176400 the "standard" 
bytes/sec for PCM (s16le)?  In other words, can I just use 176400 as a 
fixed number for calculating the subfile offset size, or should I be doing 
some other calculation to determine this multiplier?

> Since PCM is lossless, you can use the concat FILTER to join them, and 
> the trim filter (possibly implicitly with -ss and -t) to extract a part.

I previously looked into the concat FILTER, but wasn't sure how to extract 
a section from each file.  I assume you mean "atrim" in my case and not 
"trim".

Combining the concat FILTER and atrim I came up with the following and it 
works as well:

   ffmpeg -f s16le -ar 44100 -ac 2 -i file1.raw -f s16le -ar 44100 -ac 2 -i file2.raw -filter_complex '[0:0]atrim=30:270[a1]; [1:0]atrim=10:160[a2]; [a1][a2]concat=n=2:v=0:a=1[a]' -map '[a]' -codec:a mp3 test.mp3

I also tried using -ss/-t as input options for each file instead of 
"atrim" and that also works:

   ffmpeg -accurate_seek -f s16le -ar 44100 -ac 2 -ss 30 -t 240 -i file1.raw -f s16le -ar 44100 -ac 2 -ss 10 -t 150 -i file2.raw -filter_complex '[0:0][1:0]concat=n=2:v=0:a=1[a]' -map '[a]' -codec:a mp3 test.mp3

Thanks for the various options.


More information about the ffmpeg-user mailing list