FFMpegAttachedPicCollection.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using Bmp.Core.FFMpeg.CsCorePorts.FFMpegWrap.Interops;
  3. namespace Bmp.Core.FFMpeg.CsCoreExt
  4. {
  5. public unsafe class FFMpegAttachedPicCollection : IReadOnlyList<FFMpegAttachedPic>
  6. {
  7. private readonly FFMpegAttachedPic[] _items;
  8. internal FFMpegAttachedPicCollection(AVFormatContext formatContext)
  9. {
  10. var pics = new List<FFMpegAttachedPic>((int)(formatContext.nb_streams - 1));
  11. for (var i = 0; i < formatContext.nb_streams; i++)
  12. {
  13. var stream = formatContext.streams[i];
  14. if ((stream->disposition & 0x0400) != 0x0400) continue; // AV_DISPOSITION_ATTACHED_PIC
  15. var item = new FFMpegAttachedPic(stream);
  16. pics.Add(item);
  17. }
  18. _items = pics.ToArray();
  19. }
  20. public IEnumerator<FFMpegAttachedPic> GetEnumerator()
  21. {
  22. var x = _items.Where(p => true);
  23. return x.GetEnumerator();
  24. }
  25. IEnumerator IEnumerable.GetEnumerator()
  26. {
  27. return GetEnumerator();
  28. }
  29. public int Count => _items.Length;
  30. public FFMpegAttachedPic this[int index] => _items[index];
  31. }
  32. }