ryanheise / just_audio

Audio Player
1.06k stars 681 forks source link

Export Clipped Audio File #829

Open caseycrogers opened 2 years ago

caseycrogers commented 2 years ago

Is your feature request related to a problem? Please describe. I have an app where users can record, edit, upload audio files. Users can listen to each-other's edited audio files. I'm using just_audio for the basic editing and want to upload the post-editing version of the audio to my database.

Describe the solution you'd like I have a series of clipped audio sources loaded as a concatonating audio source into just audio. I'd like to save the full source to a single file with all trimming and concatenation.

Describe alternatives you've considered I can do this with an external library, but I'd prefer to do so in just_audio to ensure that what the user edited is exactly what gets uploaded. I could upload the start/stop info along with my file, but I'd rather not do that as the user could have a significant trim, resulting in much more data being written and read than necessary.

Additional context Add any other context or screenshots about the feature request here.

caseycrogers commented 2 years ago

FWIW I'm doing the following right now and it seems to work fairly well, but I haven't scrutinized the output too closely to ensure it perfectly matches AudioPlayer's clip behavior:

FFmpegKit.execute('-i "${file.path}" -ss ${startMs}ms -to ${toMs}ms ${out.path}');
ryanheise commented 2 years ago

My original intention was for just_audio to "just" play audio, and that is because plugins that attempt too many responsibilities will prevent other audio plugins in the Flutter ecosystem from working nicely together.

However, i would not object to such a feature if there is a reason for why it must be done in the same plugin, and if it could be done in a way that would not negatively impact the Flutter ecosystem.

I think one model of how such an API could be designed is AudioKit which has nodes for both input and for offline rendering. As for avoiding conflicts with other audio plugins, the main issues are solved by having separate plugins to manage things like the audio session, permissions and background audio, and we now have those.

So I think this idea could work. But it's another thing altogether to get it done. I don't personally need this feature, but if enough contributors were to get together who do need this feature, then it could get implemented.

hioshih commented 1 year ago

That would be very helpful.

I can totally see it working with the ecosystem if it just exports in a simple format, while leaving the job of specific format conversion to other plugins.

This way just_audio is focused on editing and composing while leaving recording and conversion for others.