Using your photos to create cool videos.(高仿抖音照片电影功能)
PhotoMovie can easily achieve the function of PhotoMovie like TikTok. The functions are shown below.
add Maven
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}add implementation
dependencies {
implementation 'com.github.yellowcath:PhotoMovie:1.6.4'
}Recording PhotoMovie with Music
Before:------------Record Video------------>------Mix Music------>End
Now: --------Record Video And Music------>End
GLMovieRenderer.setWaterMark(bitmap,dstRect,alpha);
GLMovieRenderer.setWaterMark(text,textSize,textColor,x,y);For reference DemoPresenter
…PhotoMovie uses a modular design, and each part can be customized and replaced.
Class Diagram
ScaleSegment will do scale animation. EndGaussianBlurSegment will do a gaussian blur animation from clear to blurry
PhotoMovie:PhotoMovie stands for the Movie itself,A complete PhotoMovie consists of a PhotoSource and a series of MovieSegment,images are allocated to MovieSegment through PhotoAllocator.
MovieLayer:MovieLayer provides the ability to render multilayer effects for MovieSegment , such as SubtitleLayer with subtitle demonstrations
IMovieFilter:MovieFilter provides filters for the entire PhotoMovie.
MovieRenderer:The MovieRenderer's function is to render the photo movie to the specified output interface, such as TextureView (GLTextureMovieRender), GLSurfaceView(GLSurfaceMovieRenderer)
PhotoMoviePlayer:PhotoMoviePlayer provides a MediaPlayer-like interface to play PhotoMovie,its progress is controlled by IMovieTimer.
Six types are currently built in
public enum PhotoMovieType {
THAW,
SCALE,
SCALE_TRANS,
WINDOW,
HORIZONTAL_TRANS,
VERTICAL_TRANS
}Here is an example of how to extend the gradient effect of 微视
According to the analysis, the picture was placed in the center first, and then a weak zoom in animation was made throughout, and the change of transparency disappeared in the second half ,A more intuitive flow chart is shown below
So two different MovieSegment is required.
FitCenterScaleSegment for zooming in images
…And then create the GradientTransferSegment,it's superclass contains both the prior and the next MovieSegment for implementing any transition animation.
…Generate PhotoMovie Object
private static PhotoMovie initGradientPhotoMovie(PhotoSource photoSource) {
List segmentList = new ArrayList<>(photoSource.size());
for (int i = 0; i Lut means [Lookup Table](https://en.wikipedia.org/wiki/Lookup_table)
For example
lut | filter
---|---
|
|
``` java
public class LutMovieFilter extends TwoTextureMovieFilter {
public LutMovieFilter(Bitmap lutBitmap){
super(loadShaderFromAssets("shader/two_vertex.glsl"),loadShaderFromAssets("shader/lut.glsl"));
setBitmap(lutBitmap);
}
}GLMovieRecorder provides the ability to record photo movies as mp4
See DemoPresenter saveVideo()
GLMovieRecorder recorder = new GLMovieRecorder();
recorder.configOutput(width, height(), bitrate,frameRate,iFrameInterval, outputPath);
recorder.setDataSource(movieRenderer);
recorder.startRecord(new GLMovieRecorder.OnRecordListener() {
@Override
public void onRecordFinish(boolean success) {
......
}
@Override
public void onRecordProgress(int recordedDuration, int totalDuration) {
......
}
}); mPhotoMoviePlayer.setMusic(context, mMusicUri); glMovieRecorder.setMusic(audioPath);No open issues yet, or sync has not completed.