/
VideoLibrary.java
163 lines (150 loc) · 7.05 KB
/
VideoLibrary.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* This file is a part of VideoLibrary Interface
* Copyright © Vyacheslav Krylov (slavone@protonmail.ch) 2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.vkryl.videolib;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
/**
* VideoLibrary Interface
*
* All methods must be thread-safe.
*
* Most of the methods return data asynchronously.
* Library implementation is free to invoke {@link Callback}'s methods on any thread.
*/
public interface VideoLibrary {
/**
* @return Library name
*/
String getName ();
/**
* @return Library version
*/
String getVersion ();
/**
* Provides information about supported formats asynchronously.
*
* @param context Context
* @param callback callback to invoke
*/
void getSupportedFormats (Context context, Callback<AvailableFormats, VideoLibraryError> callback);
/**
* Provides an information about the input video, and supported features.
*
* @param context Context
* @param uri Input video path, file:// or content://
* @param prepareTrimmingCache True, if library should generate {@link InputVideoInformation#trimCache} that will be passed by the client to {@link #correctTrimSegment(Context, Uri, TimeSegmentsCache, TimeSegment, boolean, Callback)} once it's no longer needed.
* False, if library should not generate such cache.
* @param callback Callback to invoke
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long getVideoInformation (Context context, Uri uri, boolean prepareTrimmingCache, Callback<InputVideoInformation, VideoLibraryError> callback);
/**
* Corrects trim start/end timestamp to the actual one that will be used in the output video.
*
* This might be useful if only keyframe-accurate video trimming is supported,
* or could be slightly changed for optimization purposes.
*
* This provides user an ability to ensure that no extra frames will be included in the final video,
* and no essential frames will be dropped.
*
* @param context Context
* @param uri Input video path, file:// or content://.
* @param timeSegmentsCache Library cache relevant to this video generated in {@link #getVideoInformation(Context, Uri, boolean, Callback)}
* @param segment Trim values generated by the user interface
* @param correctEnd True, if user has changed the {@link TimeSegment#endTimeUs}, which should be corrected.
* False, if user has changed the {@link TimeSegment#startTimeUs}, which should be corrected.
* When one value is changed, the other one should be kept as-is.
* @param callback Callback to invoke once frame-accurate timestamps will
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long correctTrimSegment (Context context, Uri uri, TimeSegmentsCache timeSegmentsCache, TimeSegment segment, boolean correctEnd, Callback<TimeSegment, VideoLibraryError> callback);
/**
* Creates a static image with output video preview without a need in waiting the video to be generated.
*
* This method shouldn't rely on the precise match of the output video quality, but
* shouldn't miss any essential parameters that affect the content.
*
* @param context Context
* @param uri Input video path, file:// or content://.
* @param maxSize Maximum size of the biggest side of the output image
* @param configuration Conversion configuration
* @param callback Callback to invoke
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long generateThumbnail (Context context, Uri uri, int maxSize, OutputVideoConfiguration configuration, OverlayProvider overlayProvider, Callback<Bitmap, VideoLibraryError> callback);
/**
* Provides an estimated video output size for the given configuration.
*
* @param context Context
* @param uri Input video path, file:// or content://.
* @param configuration Conversion configuration
* @param callback Callback to invoke
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long estimateOutputVideoSize (Context context, Uri uri, OutputVideoConfiguration configuration, Callback<EstimatedOutputSize, VideoLibraryError> callback);
/**
* Converts the input video or .GIF image based on the provided configuration.
*
* @param context Context
* @param inputVideoPath Path to the input video or .GIF image. file:// or content://
* @param configuration Conversion configuration
* @param overlayProvider Overlay provider
* @param destinationPath Destination video path.
* @param callback Callback to invoke during the conversion process.
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long convertVideo (Context context, Uri inputVideoPath, OutputVideoConfiguration configuration, OverlayProvider overlayProvider, String destinationPath, ConversionCallback callback);
/**
* Generates the video from the still image.
*
* @param context Context
* @param inputImagePath Path to the image on which the video should be based. file:// or content://
* @param durationUs Output duration in microseconds
* @param configuration Output video configuration.
* @param overlayProvider Overlay provider
* @param destinationPath Destination video path
* @param callback Callback to invoke during the generation process.
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long generateVideoFromImage (Context context, Uri inputImagePath, double durationUs, OutputVideoConfiguration configuration, OverlayProvider overlayProvider, String destinationPath, ConversionCallback callback);
/**
* Generates the video file from animated .GIF image
*
* @param context Context
* @param inputGifPath Path to the image on which the video should be based. file:// or content://
* @param configuration Output video configuration.
* @param overlayProvider Overlay provider
* @param destinationPath Destination video path
* @param callback Callback to invoke during the generation process.
*
* @return Task identifier that could be cancelled via {@link #cancel(long)}
*/
long generateVideoFromGif (Context context, Uri inputGifPath, OutputVideoConfiguration configuration, OverlayProvider overlayProvider, String destinationPath, ConversionCallback callback);
/**
* Cancels the task by its identifier.
*
* @param taskId task identifier obtained through other methods.
*/
void cancel (long taskId);
}