radek-k / FFMediaToolkit

FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
MIT License
352 stars 56 forks source link

StreamsToLoad AudioVideo has no effect #110

Closed hey-red closed 2 years ago

hey-red commented 2 years ago

Maybe it's ffmpeg behavior, but when we set MediaMode.AudioVideo(which is default), in streams list we can see only primary stream.

Only way to get information about both video and audio streams is separate opening same file.

MediaFile.Open(input, new MediaOptions { StreamsToLoad = MediaMode.Audio });

hey-red commented 2 years ago

I forget about important detail - it's problem with mp3 with cover images. Sample: https://files.catbox.moe/7cz4o9.mp3

IsaMorphic commented 2 years ago

Hello @hey-red. I don't remember encountering an issue like this when I originally wrote the code for handling this. If you are interested in potentially fixing this yourself, examine this method. Hope this helps :D

hey-red commented 2 years ago

@yodadude2003 I have found that method throws EndOfStreamException while trying to get packet from video stream(mjpeg). That's strange, because with MediaMode.Video it sucessfully read packet from stream. Maybe for mp3 decoder/demuxer needs additional handling.

IsaMorphic commented 2 years ago

Huh, that is quite strange indeed. I have an idea, however. I believe the code in that method is erroneously retrieving a packet from a non-existent stream number. If you replace the line in that method: GetPacketFromStream(i) with GetPacketFromStream(stream->index), does it work? If so, I can write up a proper fix to address this issue.

hey-red commented 2 years ago

@yodadude2003 Method should works correctly, but I guess order is important in this case. If I try to decode video first it's correctly take first packet with image cover, and both streams is presents in container.

IsaMorphic commented 2 years ago

Ah I see @hey-red, good to know! The issue is probably due to this reason: if you read the audio stream first, the file seeks past the first video packet. So when you try to read the video stream afterwards, there are no more packets to read and so it returns empty data. I don't think that's neccisarilly an issue with the library.

hey-red commented 2 years ago

@yodadude2003 Yes. It's a just unexpected behavior(for me). I think in future will be good to have an option to ordering streams, that should be loaded, but today I'm just can load file twice.

IsaMorphic commented 2 years ago

Sounds good @hey-red. Thanks!