macostwitterffmpegflac

Segmenting .flac files with ffmpeg truncates audio but not file length


I am trying to get Twitter spaces audio (.ts) files into a format I can easily edit, on OSX.

So far I was able to convert the files in bulk to .flac with this:

for i in *.ts;
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
ffmpeg -i "$i" -sample_fmt s16 -ar 41000 "${name}.flac"
done

That worked, and reduced the file sizes somewhat, but.. Because most of the files are around 7 hours long, my editor of choice cannot process that much audio in one file.

So I looked around and was able to find this command to segment the files into 3hr long sections.

ffmpeg -i space-1OdKrBealBqKX_0.flac -map 0 -f segment -segment_time 10800 -c copy space-1OdKrBealBqKX_0__%03d.flac

This works, but each file contains as much empty / silent space at the end as the orginal file. That's going to be a problem for sharing with a team that will help edit these files, as each file has the original file's length and file size. There are a lot of files. The audio segments and naming did work though.

How to truncate the actual length of the file to the audio segment?

Caveat: I am no expert on any of these matters, I just managed to google and get this far, so if someone knows and wants to provide working code that would be very much appreciated!


Solution

  • FLAC files contain metadata of stream duration. When streamcopying, ffmpeg cannot overwrite that metadata, so it is retained.

    Your workaround is to segment in the original step.

    ffmpeg -i "$i" -sample_fmt s16 -ar 44100 -f segment -segment_time 10800 "${name}__%03d.flac"