munim-ffmpeg 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +178 -0
  2. package/NitroMunimFfmpeg.podspec +41 -0
  3. package/README.md +95 -0
  4. package/android/CMakeLists.txt +29 -0
  5. package/android/build.gradle +144 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  10. package/android/src/main/java/com/margelo/nitro/munimffmpeg/HybridMunimFfmpeg.kt +141 -0
  11. package/android/src/main/java/com/margelo/nitro/munimffmpeg/NitroMunimFfmpegPackage.kt +18 -0
  12. package/app.plugin.js +5 -0
  13. package/ios/Bridge.h +8 -0
  14. package/ios/HybridMunimFfmpeg.swift +161 -0
  15. package/lib/index.d.ts +10 -0
  16. package/lib/index.js +21 -0
  17. package/lib/specs/MunimFfmpeg.nitro.d.ts +25 -0
  18. package/lib/specs/MunimFfmpeg.nitro.js +1 -0
  19. package/nitro.json +30 -0
  20. package/nitrogen/generated/.gitattributes +1 -0
  21. package/nitrogen/generated/android/NitroMunimFfmpeg+autolinking.cmake +81 -0
  22. package/nitrogen/generated/android/NitroMunimFfmpeg+autolinking.gradle +27 -0
  23. package/nitrogen/generated/android/NitroMunimFfmpegOnLoad.cpp +60 -0
  24. package/nitrogen/generated/android/NitroMunimFfmpegOnLoad.hpp +34 -0
  25. package/nitrogen/generated/android/c++/JFFmpegSessionResult.hpp +86 -0
  26. package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
  27. package/nitrogen/generated/android/c++/JFunc_void_double_double_double_double_double_double_double.hpp +75 -0
  28. package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
  29. package/nitrogen/generated/android/c++/JHybridMunimFfmpegSpec.cpp +138 -0
  30. package/nitrogen/generated/android/c++/JHybridMunimFfmpegSpec.hpp +67 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimffmpeg/FFmpegSessionResult.kt +86 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimffmpeg/Func_void_double.kt +78 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimffmpeg/Func_void_double_double_double_double_double_double_double.kt +78 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimffmpeg/Func_void_std__string.kt +78 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimffmpeg/HybridMunimFfmpegSpec.kt +85 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimffmpeg/NitroMunimFfmpegOnLoad.kt +35 -0
  37. package/nitrogen/generated/ios/NitroMunimFfmpeg+autolinking.rb +62 -0
  38. package/nitrogen/generated/ios/NitroMunimFfmpeg-Swift-Cxx-Bridge.cpp +73 -0
  39. package/nitrogen/generated/ios/NitroMunimFfmpeg-Swift-Cxx-Bridge.hpp +298 -0
  40. package/nitrogen/generated/ios/NitroMunimFfmpeg-Swift-Cxx-Umbrella.hpp +51 -0
  41. package/nitrogen/generated/ios/NitroMunimFfmpegAutolinking.mm +33 -0
  42. package/nitrogen/generated/ios/NitroMunimFfmpegAutolinking.swift +26 -0
  43. package/nitrogen/generated/ios/c++/HybridMunimFfmpegSpecSwift.cpp +11 -0
  44. package/nitrogen/generated/ios/c++/HybridMunimFfmpegSpecSwift.hpp +119 -0
  45. package/nitrogen/generated/ios/swift/FFmpegSessionResult.swift +77 -0
  46. package/nitrogen/generated/ios/swift/Func_void_FFmpegSessionResult.swift +46 -0
  47. package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
  48. package/nitrogen/generated/ios/swift/Func_void_double_double_double_double_double_double_double.swift +46 -0
  49. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  50. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
  51. package/nitrogen/generated/ios/swift/HybridMunimFfmpegSpec.swift +59 -0
  52. package/nitrogen/generated/ios/swift/HybridMunimFfmpegSpec_cxx.swift +277 -0
  53. package/nitrogen/generated/shared/c++/FFmpegSessionResult.hpp +112 -0
  54. package/nitrogen/generated/shared/c++/HybridMunimFfmpegSpec.cpp +26 -0
  55. package/nitrogen/generated/shared/c++/HybridMunimFfmpegSpec.hpp +72 -0
  56. package/package.json +131 -0
  57. package/react-native.config.js +16 -0
  58. package/scripts/patch-ffmpegkit-level.rb +45 -0
  59. package/src/index.ts +56 -0
  60. package/src/specs/MunimFfmpeg.nitro.ts +52 -0
@@ -0,0 +1,72 @@
1
+ ///
2
+ /// HybridMunimFfmpegSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `FFmpegSessionResult` to properly resolve imports.
17
+ namespace margelo::nitro::munimffmpeg { struct FFmpegSessionResult; }
18
+
19
+ #include <string>
20
+ #include "FFmpegSessionResult.hpp"
21
+ #include <NitroModules/Promise.hpp>
22
+ #include <vector>
23
+ #include <functional>
24
+ #include <optional>
25
+
26
+ namespace margelo::nitro::munimffmpeg {
27
+
28
+ using namespace margelo::nitro;
29
+
30
+ /**
31
+ * An abstract base class for `MunimFfmpeg`
32
+ * Inherit this class to create instances of `HybridMunimFfmpegSpec` in C++.
33
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
34
+ * @example
35
+ * ```cpp
36
+ * class HybridMunimFfmpeg: public HybridMunimFfmpegSpec {
37
+ * public:
38
+ * HybridMunimFfmpeg(...): HybridObject(TAG) { ... }
39
+ * // ...
40
+ * };
41
+ * ```
42
+ */
43
+ class HybridMunimFfmpegSpec: public virtual HybridObject {
44
+ public:
45
+ // Constructor
46
+ explicit HybridMunimFfmpegSpec(): HybridObject(TAG) { }
47
+
48
+ // Destructor
49
+ ~HybridMunimFfmpegSpec() override = default;
50
+
51
+ public:
52
+ // Properties
53
+ virtual std::string getFfmpegVersion() = 0;
54
+
55
+ public:
56
+ // Methods
57
+ virtual std::shared_ptr<Promise<FFmpegSessionResult>> execute(const std::vector<std::string>& arguments_, const std::optional<std::function<void(const std::string& /* message */)>>& onLog, const std::optional<std::function<void(double /* timeMs */, double /* sizeBytes */, double /* bitrateKbits */, double /* speed */, double /* videoFrameNumber */, double /* fps */, double /* quality */)>>& onStatistics, const std::optional<std::function<void(double /* sessionId */)>>& onSessionCreated) = 0;
58
+ virtual std::shared_ptr<Promise<FFmpegSessionResult>> probe(const std::vector<std::string>& arguments_, const std::optional<std::function<void(const std::string& /* message */)>>& onLog, const std::optional<std::function<void(double /* sessionId */)>>& onSessionCreated) = 0;
59
+ virtual std::shared_ptr<Promise<std::string>> getMediaInformation(const std::string& path) = 0;
60
+ virtual void cancel(std::optional<double> sessionId) = 0;
61
+ virtual void cancelAll() = 0;
62
+
63
+ protected:
64
+ // Hybrid Setup
65
+ void loadHybridMethods() override;
66
+
67
+ protected:
68
+ // Tag for logging
69
+ static constexpr auto TAG = "MunimFfmpeg";
70
+ };
71
+
72
+ } // namespace margelo::nitro::munimffmpeg
package/package.json ADDED
@@ -0,0 +1,131 @@
1
+ {
2
+ "name": "munim-ffmpeg",
3
+ "version": "0.1.0",
4
+ "description": "Fast FFmpeg and FFprobe for Expo and React Native, powered by Nitro Modules",
5
+ "main": "lib/index",
6
+ "module": "lib/index",
7
+ "types": "lib/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "react-native.config.js",
13
+ "lib",
14
+ "nitrogen",
15
+ "android/build.gradle",
16
+ "android/gradle.properties",
17
+ "android/fix-prefab.gradle",
18
+ "android/CMakeLists.txt",
19
+ "android/src",
20
+ "cpp",
21
+ "ios/**/*.h",
22
+ "ios/**/*.m",
23
+ "ios/**/*.mm",
24
+ "ios/**/*.cpp",
25
+ "ios/**/*.swift",
26
+ "scripts",
27
+ "app.plugin.js",
28
+ "nitro.json",
29
+ "*.podspec",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
33
+ "scripts": {
34
+ "typecheck": "tsc --noEmit",
35
+ "clean": "rm -rf android/build node_modules/**/android/build lib",
36
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
37
+ "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions --max-warnings 0",
38
+ "build": "npm run typecheck && tsc",
39
+ "prepack": "npm run build",
40
+ "typescript": "tsc",
41
+ "codegen": "nitrogen --logLevel=\"debug\"",
42
+ "specs": "npm run codegen"
43
+ },
44
+ "keywords": [
45
+ "react-native",
46
+ "expo",
47
+ "ffmpeg",
48
+ "ffprobe",
49
+ "video",
50
+ "audio",
51
+ "ios",
52
+ "android",
53
+ "typescript",
54
+ "nitro",
55
+ "nitro-modules",
56
+ "munim-technologies"
57
+ ],
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/munimtechnologies/munim-ffmpeg.git"
61
+ },
62
+ "author": "sheehanmunim <support@munimtech.com> (https://github.com/sheehanmunim)",
63
+ "license": "Apache-2.0",
64
+ "bugs": {
65
+ "url": "https://github.com/munimtechnologies/munim-ffmpeg/issues"
66
+ },
67
+ "homepage": "https://github.com/munimtechnologies/munim-ffmpeg#readme",
68
+ "publishConfig": {
69
+ "access": "public",
70
+ "registry": "https://registry.npmjs.org/"
71
+ },
72
+ "expo": {
73
+ "name": "munim-ffmpeg",
74
+ "platforms": [
75
+ "ios",
76
+ "android"
77
+ ]
78
+ },
79
+ "devDependencies": {
80
+ "@react-native/eslint-config": "0.85.3",
81
+ "@types/react": "^19.2.15",
82
+ "eslint": "^9.39.4",
83
+ "eslint-config-prettier": "^10.1.8",
84
+ "eslint-plugin-prettier": "^5.5.5",
85
+ "nitrogen": "0.36.5",
86
+ "prettier": "^3.8.3",
87
+ "react": "19.2.3",
88
+ "react-native": "0.86.2",
89
+ "react-native-nitro-modules": "^0.36.5",
90
+ "typescript": "^6.0.3"
91
+ },
92
+ "peerDependencies": {
93
+ "react": "*",
94
+ "react-native": "*",
95
+ "react-native-nitro-modules": ">=0.36.5 <1"
96
+ },
97
+ "eslintConfig": {
98
+ "root": true,
99
+ "extends": [
100
+ "@react-native",
101
+ "prettier"
102
+ ],
103
+ "plugins": [
104
+ "prettier"
105
+ ],
106
+ "rules": {
107
+ "prettier/prettier": [
108
+ "warn",
109
+ {
110
+ "quoteProps": "consistent",
111
+ "singleQuote": true,
112
+ "tabWidth": 2,
113
+ "trailingComma": "es5",
114
+ "useTabs": false
115
+ }
116
+ ]
117
+ }
118
+ },
119
+ "eslintIgnore": [
120
+ "node_modules/",
121
+ "lib/"
122
+ ],
123
+ "prettier": {
124
+ "quoteProps": "consistent",
125
+ "singleQuote": true,
126
+ "tabWidth": 2,
127
+ "trailingComma": "es5",
128
+ "useTabs": false,
129
+ "semi": false
130
+ }
131
+ }
@@ -0,0 +1,16 @@
1
+ // https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
2
+
3
+ module.exports = {
4
+ dependency: {
5
+ platforms: {
6
+ /**
7
+ * @type {import('@react-native-community/cli-types').IOSDependencyParams}
8
+ */
9
+ ios: {},
10
+ /**
11
+ * @type {import('@react-native-community/cli-types').AndroidDependencyParams}
12
+ */
13
+ android: {},
14
+ },
15
+ },
16
+ }
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+
6
+ pods_root = ENV.fetch('PODS_ROOT')
7
+ build_products = ENV.fetch('PODS_CONFIGURATION_BUILD_DIR')
8
+ source_root = File.join(pods_root, 'ffmpeg-kit-ios-https-alt', 'ffmpegkit.xcframework')
9
+
10
+ # Patch only the two vendored slices and CocoaPods' selected build product. Nitro's
11
+ # Swift/C++ bridge imports the selected header after this before-compile phase.
12
+ headers = [
13
+ File.join(source_root, 'ios-arm64', 'ffmpegkit.framework', 'Headers', 'Level.h'),
14
+ File.join(source_root, 'ios-arm64_x86_64-simulator', 'ffmpegkit.framework', 'Headers', 'Level.h'),
15
+ File.join(
16
+ build_products,
17
+ 'XCFrameworkIntermediates',
18
+ 'ffmpeg-kit-ios-https-alt',
19
+ 'ffmpegkit.framework',
20
+ 'Headers',
21
+ 'Level.h'
22
+ ),
23
+ ].select { |path| File.file?(path) }
24
+
25
+ abort('munim-ffmpeg: could not find the expected FFmpegKit Level.h') if headers.empty?
26
+
27
+ unsigned_declaration = 'NS_ENUM(NSUInteger, Level)'
28
+ signed_declaration = 'NS_ENUM(NSInteger, Level)'
29
+
30
+ headers.each do |header|
31
+ contents = File.binread(header)
32
+ next if contents.include?(signed_declaration) && !contents.include?(unsigned_declaration)
33
+
34
+ occurrences = contents.scan(unsigned_declaration).length
35
+ abort("munim-ffmpeg: unexpected Level enum declaration in #{header}") unless occurrences == 1
36
+
37
+ patched = contents.sub(unsigned_declaration, signed_declaration)
38
+ Tempfile.create(['Level', '.h'], File.dirname(header)) do |temporary|
39
+ temporary.binmode
40
+ temporary.write(patched)
41
+ temporary.flush
42
+ FileUtils.chmod(File.stat(header).mode, temporary.path)
43
+ FileUtils.mv(temporary.path, header)
44
+ end
45
+ end
package/src/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { NitroModules } from 'react-native-nitro-modules'
2
+ import type {
3
+ FFmpegLogCallback,
4
+ FFmpegSessionResult,
5
+ FFmpegSessionCreatedCallback,
6
+ FFmpegStatisticsCallback,
7
+ MunimFfmpeg as MunimFfmpegSpec,
8
+ } from './specs/MunimFfmpeg.nitro'
9
+
10
+ const MunimFfmpeg =
11
+ NitroModules.createHybridObject<MunimFfmpegSpec>('MunimFfmpeg')
12
+
13
+ export type {
14
+ FFmpegLogCallback,
15
+ FFmpegSessionResult,
16
+ FFmpegSessionCreatedCallback,
17
+ FFmpegStatisticsCallback,
18
+ MunimFfmpegSpec,
19
+ }
20
+
21
+ export function execute(
22
+ arguments_: string[],
23
+ onLog?: FFmpegLogCallback,
24
+ onStatistics?: FFmpegStatisticsCallback,
25
+ onSessionCreated?: FFmpegSessionCreatedCallback
26
+ ): Promise<FFmpegSessionResult> {
27
+ return MunimFfmpeg.execute(arguments_, onLog, onStatistics, onSessionCreated)
28
+ }
29
+
30
+ export function probe(
31
+ arguments_: string[],
32
+ onLog?: FFmpegLogCallback,
33
+ onSessionCreated?: FFmpegSessionCreatedCallback
34
+ ): Promise<FFmpegSessionResult> {
35
+ return MunimFfmpeg.probe(arguments_, onLog, onSessionCreated)
36
+ }
37
+
38
+ export function getMediaInformation(path: string): Promise<unknown> {
39
+ return MunimFfmpeg.getMediaInformation(path).then((value) =>
40
+ JSON.parse(value)
41
+ )
42
+ }
43
+
44
+ export function cancel(sessionId?: number): void {
45
+ MunimFfmpeg.cancel(sessionId)
46
+ }
47
+
48
+ export function cancelAll(): void {
49
+ MunimFfmpeg.cancelAll()
50
+ }
51
+
52
+ export function getFFmpegVersion(): string {
53
+ return MunimFfmpeg.ffmpegVersion
54
+ }
55
+
56
+ export default MunimFfmpeg
@@ -0,0 +1,52 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules'
2
+
3
+ export type FFmpegSessionResult = {
4
+ sessionId: number
5
+ returnCode: number
6
+ success: boolean
7
+ cancelled: boolean
8
+ state: string
9
+ durationMs: number
10
+ output: string
11
+ failStackTrace?: string
12
+ }
13
+
14
+ export type FFmpegLogCallback = (message: string) => void
15
+
16
+ export type FFmpegSessionCreatedCallback = (sessionId: number) => void
17
+
18
+ export type FFmpegStatisticsCallback = (
19
+ timeMs: number,
20
+ sizeBytes: number,
21
+ bitrateKbits: number,
22
+ speed: number,
23
+ videoFrameNumber: number,
24
+ fps: number,
25
+ quality: number
26
+ ) => void
27
+
28
+ export interface MunimFfmpeg extends HybridObject<{
29
+ ios: 'swift'
30
+ android: 'kotlin'
31
+ }> {
32
+ readonly ffmpegVersion: string
33
+
34
+ execute(
35
+ arguments_: string[],
36
+ onLog?: FFmpegLogCallback,
37
+ onStatistics?: FFmpegStatisticsCallback,
38
+ onSessionCreated?: FFmpegSessionCreatedCallback
39
+ ): Promise<FFmpegSessionResult>
40
+
41
+ probe(
42
+ arguments_: string[],
43
+ onLog?: FFmpegLogCallback,
44
+ onSessionCreated?: FFmpegSessionCreatedCallback
45
+ ): Promise<FFmpegSessionResult>
46
+
47
+ getMediaInformation(path: string): Promise<string>
48
+
49
+ cancel(sessionId?: number): void
50
+
51
+ cancelAll(): void
52
+ }