All Projects → sunlubo → Swiftffmpeg

sunlubo / Swiftffmpeg

Licence: apache-2.0
A Swift wrapper for the FFmpeg API

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftffmpeg

Ffmpeg
Mirror of https://git.ffmpeg.org/ffmpeg.git
Stars: ✭ 27,382 (+11168.31%)
Mutual labels:  webm, audio, ffmpeg, mp4, multimedia, hevc
Axiom
An FFmpeg GUI for Windows
Stars: ✭ 560 (+130.45%)
Mutual labels:  webm, audio, ffmpeg, mp4
Trinity
android video record editor muxer sdk
Stars: ✭ 609 (+150.62%)
Mutual labels:  audio, ffmpeg, mp4, h264
Ffmediaelement
FFME: The Advanced WPF MediaElement (based on FFmpeg)
Stars: ✭ 733 (+201.65%)
Mutual labels:  audio, ffmpeg, mp4, h264
Awesome Video
A curated list of awesome streaming video tools, frameworks, libraries, and learning resources.
Stars: ✭ 397 (+63.37%)
Mutual labels:  audio, ffmpeg, mp4, hevc
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.
Stars: ✭ 156 (-35.8%)
Mutual labels:  ffmpeg, mp4, h264
Mpc Hc
MPC-HC's main repository. For support use our Trac: https://trac.mpc-hc.org/
Stars: ✭ 3,567 (+1367.9%)
Mutual labels:  audio, ffmpeg, h264
Ffmpeg Video Player
An FFmpeg and SDL Tutorial.
Stars: ✭ 149 (-38.68%)
Mutual labels:  audio, ffmpeg, multimedia
Node Video Lib
Node.js Video Library / MP4 & FLV parser / MP4 builder / HLS muxer
Stars: ✭ 264 (+8.64%)
Mutual labels:  mp4, h264, hevc
Voukoder
Provides an easy way to include the FFmpeg encoders in other windows applications.
Stars: ✭ 436 (+79.42%)
Mutual labels:  ffmpeg, h264, hevc
Mediatoolkit
A .NET library to convert and process all your video & audio files.
Stars: ✭ 492 (+102.47%)
Mutual labels:  audio, ffmpeg, mp4
Mlt
MLT Multimedia Framework
Stars: ✭ 836 (+244.03%)
Mutual labels:  audio, ffmpeg, multimedia
Fastflix
FastFlix is a free GUI for HEVC and AV1 encoding, GIF/WebP creation, and more!
Stars: ✭ 154 (-36.63%)
Mutual labels:  ffmpeg, mp4, hevc
Androidffmpeg
android 读取摄像头和麦克风,使用rtmp推流
Stars: ✭ 298 (+22.63%)
Mutual labels:  audio, ffmpeg, h264
Mystiq
Qt5/C++ FFmpeg Media Converter
Stars: ✭ 393 (+61.73%)
Mutual labels:  audio, ffmpeg, multimedia
Ffmpeg Build Script
The FFmpeg build script provides an easy way to build a static FFmpeg on OSX and Linux with non-free codecs included.
Stars: ✭ 290 (+19.34%)
Mutual labels:  webm, ffmpeg, h264
smart rtmpd
RTMP server, smart, compact, high performance(c, c++), high concurrency, easy to maintain, easy to deploy, (supports multiple operating systems Windows and Linux, ARM, FreeBSD)
Stars: ✭ 159 (-34.57%)
Mutual labels:  h264, ffmpeg, hevc
camstudio
CamStudio fork
Stars: ✭ 83 (-65.84%)
Mutual labels:  h264, ffmpeg, mp4
Digital video introduction
A hands-on introduction to video technology: image, video, codec (av1, vp9, h265) and more (ffmpeg encoding).
Stars: ✭ 12,184 (+4913.99%)
Mutual labels:  audio, ffmpeg, h264
Testing Video
Generator of test video files for testing your media playback devices and calibrate TV sets
Stars: ✭ 70 (-71.19%)
Mutual labels:  mp4, h264, hevc

SwiftFFmpeg

A Swift wrapper for the FFmpeg API.

Note: SwiftFFmpeg is still in development, and the API is not guaranteed to be stable. It's subject to change without warning.

Installation

You should install FFmpeg (Requires FFmpeg 4.0 or higher) before use this library, on macOS, you can:

brew install ffmpeg

Swift Package Manager

SwiftFFmpeg primarily uses SwiftPM as its build tool, so we recommend using that as well. If you want to depend on SwiftFFmpeg in your own project, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
    .package(url: "https://github.com/sunlubo/SwiftFFmpeg.git", from: "1.0.0")
]

Documentation

Usage

import Foundation
import SwiftFFmpeg

if CommandLine.argc < 2 {
    print("Usage: \(CommandLine.arguments[0]) <input file>")
    exit(1)
}
let input = CommandLine.arguments[1]

let fmtCtx = try AVFormatContext(url: input)
try fmtCtx.findStreamInfo()

fmtCtx.dumpFormat(isOutput: false)

guard let stream = fmtCtx.videoStream else {
    fatalError("No video stream.")
}
guard let codec = AVCodec.findDecoderById(stream.codecParameters.codecId) else {
    fatalError("Codec not found.")
}
let codecCtx = AVCodecContext(codec: codec)
codecCtx.setParameters(stream.codecParameters)
try codecCtx.openCodec()

let pkt = AVPacket()
let frame = AVFrame()

while let _ = try? fmtCtx.readFrame(into: pkt) {
    defer { pkt.unref() }

    if pkt.streamIndex != stream.index {
        continue
    }

    try codecCtx.sendPacket(pkt)

    while true {
        do {
            try codecCtx.receiveFrame(frame)
        } catch let err as AVError where err == .tryAgain || err == .eof {
            break
        }

        let str = String(
            format: "Frame %3d (type=%@, size=%5d bytes) pts %4lld key_frame %d",
            codecCtx.frameNumber,
            frame.pictureType.description,
            frame.pktSize,
            frame.pts,
            frame.isKeyFrame
        )
        print(str)

        frame.unref()
    }
}

print("Done.")
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].