xiph / flac

Free Lossless Audio Codec
https://xiph.org/flac/
GNU Free Documentation License v1.3
1.57k stars 276 forks source link

Feature request: Process only last part of file #716

Open vlakoff opened 6 days ago

vlakoff commented 6 days ago

I have an use case where I need to decode only about the last 10 ms of the files.

Here are the currently available options in the flac tool:

--skip={#|mm:ss.ss} Skip over the first number of samples of the input. This works for both encoding and decoding, but not testing. The alternative form mm:ss.ss can be used to specify minutes, seconds, and fractions of a second.

--until={#|[+|-]mm:ss.ss} Stop at the given sample number for each input file. This works for both encoding and decoding, but not testing. The given sample number is not included in the decoded output. The alternative form mm:ss.ss can be used to specify minutes, seconds, and fractions of a second. If a `+’ (plus) sign is at the beginning, the --until point is relative to the --skip point. If a `-‘ (minus) sign is at the beginning, the --until point is relative to end of the audio.

These options don't directly suit my case. Currently, I have to use ffprobe to get the duration of the file, then substract from this duration and use --skip with that result.

I could suggest two solutions:

vlakoff commented 6 days ago

On second thought, I think the first solution (allow to use --skip with a negative value) would be the best.

Consider it this way: --skip and --until are used to define a slice. In most cases, only one option is used, so the slice just goes until the start or the end of the file. But the two options can perfectly be used simultaneously. --skip specifies the start point, and --until the end point (absolute from the file start, from the file end, or relative from --skip). Therefore, being able to specify the start point counting from the file end would nicely complement the existing possibilities.

ktmf01 commented 6 days ago

FLAC is a lossless audio compressor, not audio editing software. To be honest, I'd rather be rid of --skip and --until altogether, because it makes the code quite complex in certain places.