Giter VIP home page Giter VIP logo

ffmpegmediaextension's Introduction

FFMPEGMediaExtension

This is an attempt to build a macOS 15.0 MediaExtension for libAV* which in theory would allow for native AVFoundation container parsing and decode.

Since MediaExtensions are shipped in a host app, this has also provides a Host app.

We have basic frame decoding working! image

But there is a ton left to do!

  • Asset / Track Metadata
  • GOP Support
  • Additional Codecs

Goal

Provide additional media format playback support for any macOS app which leverages AVFoundation / Core Media as its underlying playback / decode engine

  • Finder
  • Quicklook
  • Quicktime Player
  • Any other app which opts in by calling:
    • MTRegisterProfessionalVideoWorkflowFormatReaders() for format parsing support
    • VTRegisterProfessionalVideoWorkflowVideoDecoders() for additional decoder support

Requirements:

  • MacOS 15 Beta 4 +
  • XCode 16 Beta 4 +

Building:

If you want to build FFMPEG libAVFormat and libAVCodec:

brew install automake nasm pkg-config

FFMPEG is installed as a submodule - so ensure you git checkout the submodule and init

cd ffmpeg

./configure --prefix=/usr/local --enable-static --disable-shared --disable-programs --disable-doc --disable-avdevice --disable-avfilter --disable-postproc --disable-swscale --disable-swresample --arch=arm64 --disable-avfoundation

make -j$(sysctl -n hw.ncpu)

This will build you the statically linked libAVFormat.a and libAVCodec.a libries

Design

MEFormatReader (LibAVFOrmatReader)

  • Plugin instantiation via LibAVFormatReaderFactory
  • Register a limited number of supported container formats via plist / exported content types
    • MKV
    • Adding new Containers requires editing multiple annoying Plist entries
  • Basic Container parsing via libavformat (LibAVFormatReader)
  • Container metadata to AVMetadataItems
  • Track Parsing (Audio and Video only right now) (LibAVTrackReader)
  • Track specific metadata to AVMEtadataItems
  • CMFormatDescriptions for our Tracks
  • Seek / Stepping via LibAVSampleCursor
  • Provide additional sample metadata that some formats require
    • Sample Sync info
    • Sample Dependency info
    • Post Decode Processing Data

MEVideoDecoder

  • Not yet started
  • This means today we only add container support, not yet additional codecs
  • Stay tuned

Todo:

  • libavformat / libavcodec, libavutil compiled as a .a
  • ffmpeg headers inlcuded
  • Swift Modulemap + Obj-C libav*
  • Implement necessary Media Extension protocols
    • MEFormatReaderExtension
    • MEFormatReader (partial)
    • METrackReader
    • METrackInfo
    • MESampleCursor (partial)
    • MEVideoDecoderExtension
    • MEVideoDecoder
    • MEVideoDecoderPixelBufferManager
  • impelment Extension requirements (plists, entitlements, etc)
  • Memory Management pass in ObjC / C

Strategy

We Eventually require 2 Bundle targets that are Media Extensions.

  • A Media Extention that implements MEFormatReader, which will allow container parsing via libavformat and provide container metadata, track metadata, and compressed sample metadata.

  • A Media Extension that impelments MEVideoDecoder - a Video Decompressor which will allow for codec decompression via libavcodec and provide pixel buffers from appropriate samples.

FFMPEGs library more or less follows similar design patterns to AVFoundation. The following isnt totally accurate, but more or less gets the point across:

  • CMTime <~> AVRational

  • CMMediaType <~> AVMediaType

  • CMFormatDescription <~> AVCodecParameters

  • CMSampleBuffer <~> AVPacket

  • CMBlockBuffer <~> AVBuffer

  • CVPixelBuffer <-> AVFrame (decoded video)

  • AVAsset <~> AVFormatContext

  • AVAssetTrack <~> AVStream

  • AVSampleCursor <~> AVIOContext

Leverage AVIOContext to allow a MEByteSource to driven by a AVFormatContext to get us container parsing and metadata

Running Notes:

  • Weirdly MediaExtension headers imply macOS 14 supported?
  • entitlements for Media Extensions

ffmpegmediaextension's People

Contributors

vade avatar

Stargazers

 avatar Kartik Venugopal avatar Joshua Minor avatar Tim Lehr avatar Hongyu Shi avatar Emilio Loi avatar Gaston Morixe avatar An Tran avatar Alexander Eichhorn avatar Doug avatar  avatar Kunwar Sahni avatar Mel Massadian avatar Sandalots avatar Aman Gupta Karmani avatar  avatar Jordi Bruin avatar Douglas Heriot avatar  avatar Ryder Mackay avatar Damiano Galassi avatar  avatar  avatar Sean Stevens avatar Danja Vasiliev avatar Tamas Nagy avatar Gllmar avatar liquid avatar Chris Hocking avatar

Watchers

 avatar Chris Hocking avatar

ffmpegmediaextension's Issues

Determine Sync metadata for samples from libavformat / libavcodec without decoding

It seems like our Media Format Extension is super close, but we need to understand how to provide the MESampleCursor implementation with some metadata about key frame, sync and dependencies

  • AVSampleCursorSyncInfo
  • AVSampleCursorDependencyInfo
  • MEHEVCDependencyInfo
  • decodeTimeOfLastSampleReachableByForwardSteppingThatIsAlreadyLoadedByByteSource
  • samplesWithEarlierDTSsMayHaveLaterPTSsThanCursor
  • samplesWithLaterDTSsMayHaveEarlierPTSsThanCursor

Support GOP Codecs

So while we have our first frame, this only works right now for I frame codecs - ie we aren't properly supporting other frame types just yet.

Playback appears to be requiring some additional metadata we aren't supplying (see #6 )

But we also will need to update the function

- (void)loadSampleBufferContainingSamplesToEndCursor:(nullable id<MESampleCursor>)endSampleCursor completionHandler:(void (^)(CMSampleBufferRef _Nullable newSampleBuffer, NSError * _Nullable error))completionHandler

To support the end sample cursor and 'accrue' samples in the CMBlockBuffer and populate the sample timing info.

The header docs for CMSampleBufferCreateReady has some good insight there.

Determine if Dispatch Queue is in fact necessary

While having a sexy multi threaded thingy-majigy sounds cool, because we have multiple objects handling the same underlying 'asset' and sharing pointers for format contexts, streams, codec parsers managing that seems stupid and error prone.

Lets see if we can KISS.

Next Steps - Populate Metadata

From what I can tell, we also need to actually implement some metadata reporting

<<<< MEFormatReaderWrapper >>>> objcWrapperPluginFormatReader_CopyProperty signalled err=-12784 (kCMBaseObjectError_PropertyNotFound) (can not find metatdata info) at ExtensionFormatReaderWrapper.m:535


<<<< AVAssetInspectorLoader >>>> -[AVFigAssetInspectorLoader loadValuesAsynchronouslyForKeys:keysForCollectionKeys:completionHandler:]: called (self: 0x600001dac310, keys: (
    commonMetadata,
    hasProtectedContent,
    composable,
    streaming,
    availableMetadataFormats,
    metadata,
    compatibleWithAirPlayVideo,
    availableMediaCharacteristicsWithMediaSelectionOptions,
    availableChapterLocales,
    maximumVideoResolution,
    availableVideoDynamicRanges,
    tracks,
    assetCache
), keysForCollectionKeys: (null), handler: non-nil)

<<<< AVAssetInspectorLoader >>>> -[AVFigAssetInspectorLoader loadValuesAsynchronouslyForKeys:keysForCollectionKeys:completionHandler:]: Calling FigAssetLoadValuesAsyncForProperties for properties (
    availableMediaCharacteristicsWithMediaSelectionOptions,
    "assetProperty_QuickTimeUserData",
    "assetProperty_HLSMetadata",
    "assetProperty_ID3Metadata",
    "assetProperty_CommonMetadata",
    "assetProperty_ISOUserData",
    Chapters,
    "assetProperty_AVCHDMetadata",
    "assetProperty_FormatSpecificMetadata",
    "assetProperty_QuickTimeMetadata",
    "assetProperty_Tracks",
    "assetProperty_AvailableVideoDynamicRanges",
    "assetProperty_AssetType",
    "assetProperty_MaximumVideoResolution",
    "assetProperty_CompatibleWithAirPlayVideo",
    "assetProperty_iTunesMetadata",
    "assetProperty_AvailableMetadataFormats",
    "assetProperty_ChapterGroupInfo",
    "assetProperty_ProtectedStatus"
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.