{"id":31923507,"url":"https://github.com/sctg-development/libwebm-swift","last_synced_at":"2025-10-13T23:54:22.910Z","repository":{"id":313493158,"uuid":"1051613671","full_name":"sctg-development/libwebm-swift","owner":"sctg-development","description":"A Swift package providing bindings for libwebm, enabling WebM file parsing and creation on iOS and macOS platforms.","archived":false,"fork":false,"pushed_at":"2025-09-06T13:12:39.000Z","size":22891,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-06T13:14:19.754Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sctg-development.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-06T11:14:06.000Z","updated_at":"2025-09-06T13:12:42.000Z","dependencies_parsed_at":"2025-09-06T13:28:24.922Z","dependency_job_id":null,"html_url":"https://github.com/sctg-development/libwebm-swift","commit_stats":null,"previous_names":["sctg-development/libwebm-swift"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/sctg-development/libwebm-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctg-development%2Flibwebm-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctg-development%2Flibwebm-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctg-development%2Flibwebm-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctg-development%2Flibwebm-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sctg-development","download_url":"https://codeload.github.com/sctg-development/libwebm-swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctg-development%2Flibwebm-swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017190,"owners_count":26086017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-13T23:54:21.346Z","updated_at":"2025-10-13T23:54:22.904Z","avatar_url":"https://github.com/sctg-development.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibWebMSwift\n\nA Swift package providing bindings for libwebm, enabling WebM file parsing and creation on iOS and macOS platforms.\n\n## Features\n\n- **WebM Parsing**: Parse WebM files and extract metadata, track information, and media properties\n- **WebM Muxing**: Create new WebM files with video and audio tracks\n- **Swift Idiomatic API**: Clean, safe Swift interfaces with proper error handling\n- **Memory Safe**: Automatic memory management with ARC\n- **Cross-Platform**: Supports both iOS and macOS\n\n## Installation\n\nAdd this package to your Swift project using Swift Package Manager:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/sctg-development/libwebm-swift.git\", from: \"1.0.0\")\n]\n```\n\n## Usage\n\n### Parsing WebM Files\n\n```swift\nimport LibWebMSwift\n\ndo {\n    let parser = try WebMParser(filePath: \"/path/to/file.webm\")\n\n    // Parse headers\n    try parser.parseHeaders()\n\n    // Get basic information\n    let duration = try parser.getDuration()\n    let trackCount = try parser.getTrackCount()\n\n    // Get track information\n    for i in 0..\u003ctrackCount {\n        let trackInfo = try parser.getTrackInfo(trackIndex: i)\n        print(\"Track: \\(trackInfo.name) (\\(trackInfo.codecId))\")\n\n        switch trackInfo.trackType {\n        case .video:\n            let videoInfo = try parser.getVideoInfo(trackNumber: trackInfo.trackNumber)\n            print(\"Video: \\(videoInfo.width)x\\(videoInfo.height) @ \\(videoInfo.frameRate)fps\")\n        case .audio:\n            let audioInfo = try parser.getAudioInfo(trackNumber: trackInfo.trackNumber)\n            print(\"Audio: \\(audioInfo.channels) channels @ \\(audioInfo.samplingFrequency)Hz\")\n        default:\n            break\n        }\n    }\n\n    // Extract frames (example with first video track)\n    if let videoTrack = try parser.getTrackInfo(trackIndex: 0) as? VideoTrackInfo {\n        var frameCount = 0\n        while frameCount \u003c 5 {  // Extract first 5 frames\n            if let frameData = try parser.readNextVideoFrame(trackId: videoTrack.trackNumber) {\n                print(\"Frame \\(frameCount): \\(frameData.data.count) bytes, timestamp: \\(frameData.timestampNs)ns, keyframe: \\(frameData.isKeyframe)\")\n                frameCount += 1\n            } else {\n                break  // No more frames\n            }\n        }\n    }\n} catch let error as WebMError {\n    print(\"WebM Error: \\(error)\")\n}\n```\n\n### Creating WebM Files\n\n```swift\nimport LibWebMSwift\n\ndo {\n    let muxer = try WebMMuxer(filePath: \"/path/to/output.webm\")\n\n    // Add video track\n    let videoTrackId = try muxer.addVideoTrack(width: 1920, height: 1080, codecId: \"V_VP9\")\n\n    // Add audio track\n    let audioTrackId = try muxer.addAudioTrack(samplingFrequency: 48000, channels: 2, codecId: \"A_OPUS\")\n\n    // Write frames with proper timestamps (30fps video, 48kHz audio)\n    let frameDurationNs: UInt64 = 33_333_333  // ~30fps\n    let audioFrameDurationNs: UInt64 = 20_833_333  // ~48 frames per second for 1ms audio chunks\n\n    for frameIndex in 0..\u003c10 {\n        let timestamp = UInt64(frameIndex) * frameDurationNs\n\n        // Write video frame\n        try muxer.writeVideoFrame(\n            trackId: videoTrackId,\n            frameData: videoFrameData[frameIndex],\n            timestampNs: timestamp,\n            isKeyframe: frameIndex % 3 == 0  // Keyframe every 3 frames\n        )\n\n        // Write audio frame (multiple audio frames per video frame)\n        for audioFrame in 0..\u003c2 {\n            let audioTimestamp = timestamp + UInt64(audioFrame) * audioFrameDurationNs\n            try muxer.writeAudioFrame(\n                trackId: audioTrackId,\n                frameData: audioFrameData[frameIndex * 2 + audioFrame],\n                timestampNs: audioTimestamp\n            )\n        }\n    }\n\n    // Finalize the file\n    try muxer.finalize()\n} catch let error as WebMError {\n    print(\"WebM Error: \\(error)\")\n}\n```\n\n### Advanced Usage: Multiple Tracks and Frame Extraction\n\n```swift\nimport LibWebMSwift\n\n// Example: Parse existing file and create new one with multiple tracks\ndo {\n    // Parse source file\n    let sourceParser = try WebMParser(filePath: \"/path/to/source.webm\")\n    try sourceParser.parseHeaders()\n\n    let sourceDuration = try sourceParser.getDuration()\n    let sourceTrackCount = try sourceParser.getTrackCount()\n\n    // Create new muxer\n    let muxer = try WebMMuxer(filePath: \"/path/to/output.webm\")\n\n    // Add tracks based on source file\n    var videoTrackId: UInt32?\n    var audioTrackId: UInt32?\n\n    for i in 0..\u003csourceTrackCount {\n        let trackInfo = try sourceParser.getTrackInfo(trackIndex: i)\n\n        switch trackInfo.trackType {\n        case .video:\n            let videoInfo = try sourceParser.getVideoInfo(trackNumber: trackInfo.trackNumber)\n            videoTrackId = try muxer.addVideoTrack(\n                width: videoInfo.width,\n                height: videoInfo.height,\n                codecId: trackInfo.codecId\n            )\n        case .audio:\n            let audioInfo = try sourceParser.getAudioInfo(trackNumber: trackInfo.trackNumber)\n            audioTrackId = try muxer.addAudioTrack(\n                samplingFrequency: audioInfo.samplingFrequency,\n                channels: audioInfo.channels,\n                codecId: trackInfo.codecId\n            )\n        default:\n            break\n        }\n    }\n\n    // Extract and remux frames\n    if let videoId = videoTrackId {\n        var frameCount = 0\n        while let frameData = try sourceParser.readNextVideoFrame(trackId: videoId) {\n            try muxer.writeVideoFrame(\n                trackId: videoId,\n                frameData: frameData.data,\n                timestampNs: frameData.timestampNs,\n                isKeyframe: frameData.isKeyframe\n            )\n            frameCount += 1\n            if frameCount \u003e= 100 { break }  // Limit for example\n        }\n    }\n\n    if let audioId = audioTrackId {\n        var frameCount = 0\n        while let frameData = try sourceParser.readNextAudioFrame(trackId: audioId) {\n            try muxer.writeAudioFrame(\n                trackId: audioId,\n                frameData: frameData.data,\n                timestampNs: frameData.timestampNs\n            )\n            frameCount += 1\n            if frameCount \u003e= 200 { break }  // Limit for example\n        }\n    }\n\n    try muxer.finalize()\n    print(\"Successfully created WebM file with \\(sourceTrackCount) tracks\")\n\n} catch let error as WebMError {\n    print(\"WebM Error: \\(error)\")\n}\n```\n\n### Video Codecs\n- VP8 (`V_VP8`)\n- VP9 (`V_VP9`)\n- AV1 (`V_AV1`)\n\n### Audio Codecs\n- Opus (`A_OPUS`)\n- Vorbis (`A_VORBIS`)\n\n## Error Handling\n\nThe package uses Swift's error handling system with the `WebMError` enum:\n\n```swift\nenum WebMError: Error {\n    case invalidFile          // File doesn't exist or is not a valid WebM file\n    case corruptedData        // File data is corrupted\n    case unsupportedFormat    // Codec or format not supported\n    case ioError             // File I/O error\n    case outOfMemory         // Memory allocation failed\n    case invalidArgument     // Invalid parameter passed to function\n}\n```\n\n### Error Handling Best Practices\n\n```swift\ndo {\n    let parser = try WebMParser(filePath: filePath)\n    try parser.parseHeaders()\n\n    // Handle specific errors\n    let trackCount = try parser.getTrackCount()\n    guard trackCount \u003e 0 else {\n        throw WebMError.invalidFile\n    }\n\n} catch WebMError.invalidFile {\n    print(\"Invalid WebM file\")\n} catch WebMError.corruptedData {\n    print(\"File appears to be corrupted\")\n} catch WebMError.unsupportedFormat {\n    print(\"Unsupported codec or format\")\n} catch {\n    print(\"Unexpected error: \\(error)\")\n}\n```\n\n## Advanced Features\n\n### Video-Only Files\n\n```swift\nlet muxer = try WebMMuxer(filePath: \"/path/to/video-only.webm\")\nlet videoTrackId = try muxer.addVideoTrack(width: 1920, height: 1080, codecId: \"V_VP9\")\n\n// Write video frames only\nfor i in 0..\u003cframes.count {\n    try muxer.writeVideoFrame(\n        trackId: videoTrackId,\n        frameData: frames[i],\n        timestampNs: UInt64(i) * 33_333_333,  // 30fps\n        isKeyframe: i % 30 == 0  // Keyframe every second\n    )\n}\n\ntry muxer.finalize()\n```\n\n### Audio-Only Files\n\n```swift\nlet muxer = try WebMMuxer(filePath: \"/path/to/audio-only.webm\")\nlet audioTrackId = try muxer.addAudioTrack(samplingFrequency: 48000, channels: 2, codecId: \"A_OPUS\")\n\n// Write audio frames only\nfor i in 0..\u003caudioFrames.count {\n    try muxer.writeAudioFrame(\n        trackId: audioTrackId,\n        frameData: audioFrames[i],\n        timestampNs: UInt64(i) * 20_833_333  // ~48 frames per second\n    )\n}\n\ntry muxer.finalize()\n```\n\n- iOS 13.0+ or macOS 10.15+\n- Swift 5.9+\n- Xcode 15.0+\n\n## Architecture\n\nThis package consists of:\n\n1. **CLibWebM**: C++ wrapper around libwebm providing a C API\n2. **LibWebMSwift**: Swift classes providing idiomatic Swift interfaces\n3. **libwebm**: Google libwebm library (included as git submodule)\n\n## Building\n\n```bash\n# Clone with submodules\ngit clone --recursive https://github.com/sctg-development/libwebm-swift.git LibWebMSwift\ncd LibWebMSwift\n\n# Build\nswift build\n\n# Run tests\nswift test\n```\n\n## License\n\nThis project is licensed under the same terms as libwebm. See LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please ensure that:\n\n1. All tests pass\n2. Code follows Swift style guidelines\n3. New features include appropriate tests\n4. Documentation is updated for API changes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsctg-development%2Flibwebm-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsctg-development%2Flibwebm-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsctg-development%2Flibwebm-swift/lists"}