flac icon indicating copy to clipboard operation
flac copied to clipboard

Feature request: Process only last part of file

Open vlakoff opened this issue 1 year ago • 2 comments

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:

  • Let use --skip with a negative value, which would determinate the "break point" counting from the end. But maybe people would argue that it is confusing.
  • Implement a --keep option. With a positive value, keep the N samples from the beginning, and with a negative value, keep the N samples from the end. Sounds simple and straightforward, and would nicely complement the existing options.
    • About the name of this option: maybe --keep would be ambiguous (as there as other things such as "keep metadata" for instance). I could also suggest --only (I don't like this one much… it's even more ambiguous), or --slice (I like this one! unambiguous, and descriptive).

vlakoff avatar Jul 01 '24 00:07 vlakoff

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.

vlakoff avatar Jul 01 '24 00:07 vlakoff

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.

ktmf01 avatar Jul 01 '24 07:07 ktmf01

I understand your points, in particular that you don't want to complexify the code further if it's already too complex.

Nevertheless, I am able to figure out my way using the already available options. I'm closing the ticket.

vlakoff avatar Jul 10 '24 03:07 vlakoff