dmrschmidt / DSWaveformImage

Generate waveform images from audio files on iOS, macOS & visionOS in Swift. Native SwiftUI & UIKit views.
MIT License
980 stars 109 forks source link

filtering non-audio tracks for AVAssetReaderTrackOutput #15

Closed avyavya closed 4 years ago

avyavya commented 4 years ago

I thought wanna use this framework for mp4 video file.

AVAssetReaderTrackOutput raises NSInvalidArgumentException when analyze non-audio tracks with the outputSettings(). this fix will able to supports for movie files (.mp4 and more)

sorry for no tests...

dmrschmidt commented 4 years ago

Hey avyavya, thanks for the PR! Just took a quick look from my phone and it looks good. I’ll merge and release it today or tomorrow when I’m back at my laptop.

Thanks a lot!

dmrschmidt commented 4 years ago

I'll merge this now since it looks right, works for me and I can't see any potential issues. However, with the videos I just tried it with, I actually never got the crash you mentioned. So either there is still some other issue at play, or it's simply the way the videos are encoded and presumably their tracks arranged or something.

@avyavya, would it be possible to send me the video file that caused the NSInvalidArgumentException to me?

avyavya commented 4 years ago

Hi @dmrschmidt ! thanks for merge :)

I tested with video downloaded from https://mazwai.com/video/excuse-the-roach-iii---miami/454986

NSInvalidArgumentException occures when audioAsset.tracks.first.mediaType is NOT AVMediaType.audio 'the first track' of that video is AVMediaType.video

regards 🙇

dmrschmidt commented 4 years ago

Thanks for the video! I've tested it now and just as I expected, the issue isn't yet fixed completely. It doesn't crash any more and reads the file while producing a waveform image, but that image is still wrong.

This is what it looks like

Screen Shot 2020-01-23 at 09 31 25

and this is what it should look like

Screen Shot 2020-01-23 at 09 32 42

So it's only loading like a quarter or whatever of the actual audio data in this example.

I've isolated the issue to the way audio data is encoded in the tracks of a video. Looks like I'll need to rewrite the whole loading process of the AVAssetReader to get the proper values for the duration.

Working on that now.

dmrschmidt commented 4 years ago

This is now fixed properly and released as 6.0.0.

As the semantic versioning indicates, this is an API breaking change as the workflow is now always asynchronous.

avyavya commented 4 years ago

thx for update! ☺️

btw, tag 6.1.0 does not exists for me 🤔 commit: https://github.com/dmrschmidt/DSWaveformImage/commit/d16f193f0e47ed950c9e1602e55295b73c9969d2 is gone?

dmrschmidt commented 4 years ago

🤔 Guess i forgot something. Will check tomorrow. I tried it on one of my own projects with Carthage and it updated to 6.1.0 but I’ll see what’s missing. Thanks for letting me know!

On Fri 24. Jan 2020 at 18:03, avyavya notifications@github.com wrote:

thx for update! ☺️

btw, tag 6.1.0 does not exists for me 🤔 commit: d16f193 https://github.com/dmrschmidt/DSWaveformImage/commit/d16f193f0e47ed950c9e1602e55295b73c9969d2 is gone?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dmrschmidt/DSWaveformImage/pull/15?email_source=notifications&email_token=AAAQ55M47NVUDROI7ER64G3Q7LDGTA5CNFSM4KJCG43KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ2ODSI#issuecomment-578085321, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAQ55P325IL2U7G2H6SZNDQ7LDGTANCNFSM4KJCG43A .

dmrschmidt commented 4 years ago

thx for update! ☺️

btw, tag 6.1.0 does not exists for me 🤔 commit: d16f193 is gone?

I had indeed forgotten to push the actual commit and not just the tag 🤦‍♂️ all there now