增加视频画面拼接、锐化滤镜特效

增加视频画面拼接、锐化滤镜特效
pull/107/head
frank 7 years ago
parent a736ca2683
commit 6850b56fdf
  1. 17
      README.md
  2. 5
      app/src/main/java/com/frank/ffmpeg/activity/FilterActivity.java
  3. 13
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  4. 15
      app/src/main/java/com/frank/ffmpeg/format/VideoLayout.java
  5. 22
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  6. 9
      app/src/main/res/layout/activity_video_handle.xml
  7. 2
      app/src/main/res/values/strings.xml
  8. BIN
      mp4/multi.mp4
  9. BIN
      mp4/multi_vertical.mp4

@ -17,6 +17,7 @@ android端基于FFmpeg库的使用。<br>
- #### 视频截图 - #### 视频截图
- #### 视频转GIF动图 - #### 视频转GIF动图
- #### 视频添加水印 - #### 视频添加水印
- #### 视频画面拼接
- #### 图片合成视频 - #### 图片合成视频
- #### 视频解码播放 - #### 视频解码播放
- #### 本地直播推流 - #### 本地直播推流
@ -38,17 +39,21 @@ android端基于FFmpeg库的使用。<br>
![动态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/gif/VideoToGif.gif) ![动态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/gif/VideoToGif.gif)
滤镜效果: 滤镜效果:
![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_balance.png) ![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_balance.png)
![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_sketch.png) ![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_sketch.png)
![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_bright.png) ![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_bright.png)
![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_edge.png) ![态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_edge.png)
![动态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_blue.png) ![静态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_blue.png)
![静态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_grid.png)
视频画面拼接:
![视频](https://github.com/xufuji456/FFmpegAndroid/blob/master/mp4/multi.mp4)
![动态图片](https://github.com/xufuji456/FFmpegAndroid/blob/master/picture/filter_grid.png)
*** ***
后续会完善音视频播放、推流直播。 后续会完善音视频播放、推流直播。

@ -41,7 +41,7 @@ public class FilterActivity extends AppCompatActivity implements SurfaceHolder.C
"drawbox=x=100:y=100:w=100:h=100:color=red@0.5'", "drawbox=x=100:y=100:w=100:h=100:color=red@0.5'",
"vignette='PI/4+random(1)*PI/50':eval=frame", "vignette='PI/4+random(1)*PI/50':eval=frame",
"vflip", "vflip",
"noise=alls=20:allf=t+u", "unsharp"
}; };
private String[] txtArray = new String[]{ private String[] txtArray = new String[]{
"素描", "素描",
@ -53,7 +53,8 @@ public class FilterActivity extends AppCompatActivity implements SurfaceHolder.C
"均衡", "均衡",
"矩形", "矩形",
"闪烁",//左上角闪烁 "闪烁",//左上角闪烁
"翻转"//vflip上下翻转,hflip是左右翻转 "翻转",//vflip上下翻转,hflip是左右翻转
"锐化"
}; };
private HorizontalAdapter horizontalAdapter; private HorizontalAdapter horizontalAdapter;

@ -13,6 +13,7 @@ import android.widget.ProgressBar;
import com.frank.ffmpeg.FFmpegCmd; import com.frank.ffmpeg.FFmpegCmd;
import com.frank.ffmpeg.R; import com.frank.ffmpeg.R;
import com.frank.ffmpeg.format.VideoLayout;
import com.frank.ffmpeg.util.FFmpegUtil; import com.frank.ffmpeg.util.FFmpegUtil;
import java.io.File; import java.io.File;
@ -67,6 +68,7 @@ public class VideoHandleActivity extends AppCompatActivity implements View.OnCli
findViewById(R.id.btn_screen_record).setOnClickListener(this); findViewById(R.id.btn_screen_record).setOnClickListener(this);
findViewById(R.id.btn_combine_video).setOnClickListener(this); findViewById(R.id.btn_combine_video).setOnClickListener(this);
findViewById(R.id.btn_play_video).setOnClickListener(this); findViewById(R.id.btn_play_video).setOnClickListener(this);
findViewById(R.id.btn_multi_video).setOnClickListener(this);
} }
private void setVisible() { private void setVisible() {
@ -79,6 +81,7 @@ public class VideoHandleActivity extends AppCompatActivity implements View.OnCli
findViewById(R.id.btn_screen_record).setVisibility(View.GONE); findViewById(R.id.btn_screen_record).setVisibility(View.GONE);
findViewById(R.id.btn_combine_video).setVisibility(View.VISIBLE); findViewById(R.id.btn_combine_video).setVisibility(View.VISIBLE);
findViewById(R.id.btn_play_video).setVisibility(View.VISIBLE); findViewById(R.id.btn_play_video).setVisibility(View.VISIBLE);
findViewById(R.id.btn_multi_video).setVisibility(View.VISIBLE);
} }
private void setGone() { private void setGone() {
@ -91,6 +94,7 @@ public class VideoHandleActivity extends AppCompatActivity implements View.OnCli
findViewById(R.id.btn_screen_record).setVisibility(View.GONE); findViewById(R.id.btn_screen_record).setVisibility(View.GONE);
findViewById(R.id.btn_combine_video).setVisibility(View.GONE); findViewById(R.id.btn_combine_video).setVisibility(View.GONE);
findViewById(R.id.btn_play_video).setVisibility(View.GONE); findViewById(R.id.btn_play_video).setVisibility(View.GONE);
findViewById(R.id.btn_multi_video).setVisibility(View.GONE);
} }
@Override @Override
@ -124,6 +128,9 @@ public class VideoHandleActivity extends AppCompatActivity implements View.OnCli
case R.id.btn_play_video: case R.id.btn_play_video:
handleType = 8; handleType = 8;
break; break;
case R.id.btn_multi_video:
handleType = 9;
break;
default: default:
handleType = 0; handleType = 0;
break; break;
@ -206,6 +213,12 @@ public class VideoHandleActivity extends AppCompatActivity implements View.OnCli
case 8://视频解码播放 case 8://视频解码播放
startActivity(new Intent(VideoHandleActivity.this, VideoPlayerActivity.class)); startActivity(new Intent(VideoHandleActivity.this, VideoPlayerActivity.class));
return; return;
case 9://视频画面拼接:分辨率、时长、封装格式不一致时,先把视频源转为一致
String input1 = PATH + File.separator + "input1.mp4";
String input2 = PATH + File.separator + "input2.mp4";
String outputFile = PATH + File.separator + "multi.mp4";
commandLine = FFmpegUtil.multiVideo(input1, input2, outputFile, VideoLayout.LAYOUT_HORIZONTAL);
break;
default: default:
break; break;
} }

@ -0,0 +1,15 @@
package com.frank.ffmpeg.format;
/**
* 视频布局
* Created by frank on 2018/6/18.
*/
public class VideoLayout {
//水平拼接
public final static int LAYOUT_HORIZONTAL = 1;
//垂直拼接
public final static int LAYOUT_VERTICAL = 2;
}

@ -3,6 +3,8 @@ package com.frank.ffmpeg.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log; import android.util.Log;
import com.frank.ffmpeg.format.VideoLayout;
/** /**
* ffmpeg工具拼接命令行处理音视频 * ffmpeg工具拼接命令行处理音视频
* Created by frank on 2018/1/23. * Created by frank on 2018/1/23.
@ -220,10 +222,30 @@ public class FFmpegUtil {
* @param channel 声道:单声道为1/立体声道为2 * @param channel 声道:单声道为1/立体声道为2
* @return 音频编码的命令行 * @return 音频编码的命令行
*/ */
@SuppressLint("DefaultLocale")
public static String[] encodeAudio(String srcFile, String targetFile, int sampleRate, int channel){ public static String[] encodeAudio(String srcFile, String targetFile, int sampleRate, int channel){
String combineVideo = "ffmpeg -f s16le -ar %d -ac %d -i %s %s"; String combineVideo = "ffmpeg -f s16le -ar %d -ac %d -i %s %s";
combineVideo = String.format(combineVideo, sampleRate, channel, srcFile, targetFile); combineVideo = String.format(combineVideo, sampleRate, channel, srcFile, targetFile);
return combineVideo.split(" "); return combineVideo.split(" ");
} }
/**
* 多画面拼接视频
* @param input1 输入文件1
* @param input2 输入文件2
* @param targetFile 画面拼接文件
*
* @return 画面拼接的命令行
*/
public static String[] multiVideo(String input1, String input2, String targetFile, int videoLayout){
// String multiVideo = "ffmpeg -i %s -i %s -i %s -i %s -filter_complex " +
// "\"[0:v]pad=iw*2:ih*2[a];[a][1:v]overlay=w[b];[b][2:v]overlay=0:h[c];[c][3:v]overlay=w:h\" %s";
String multiVideo = "ffmpeg -i %s -i %s -filter_complex hstack %s";//hstack:水平拼接,默认
if(videoLayout == VideoLayout.LAYOUT_VERTICAL){//vstack:垂直拼接
multiVideo = multiVideo.replace("hstack", "vstack");
}
multiVideo = String.format(multiVideo, input1, input2, targetFile);
return multiVideo.split(" ");
}
} }

@ -94,4 +94,13 @@
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:text="@string/video_play"/> android:text="@string/video_play"/>
<Button
android:id="@+id/btn_multi_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/btn_play_video"
android:layout_marginTop="10dp"
android:text="@string/video_multi"/>
</RelativeLayout> </RelativeLayout>

@ -34,6 +34,7 @@
<string name="video_filter">滤镜特效</string> <string name="video_filter">滤镜特效</string>
<string name="video_slow">慢放</string> <string name="video_slow">慢放</string>
<string name="video_fast">快进</string> <string name="video_fast">快进</string>
<string name="video_multi">画面拼接</string>
<string name="swap">切换</string> <string name="swap">切换</string>
<string name="start">开始</string> <string name="start">开始</string>
@ -52,5 +53,6 @@
<string name="video_box">矩形</string> <string name="video_box">矩形</string>
<string name="video_flash">闪烁</string> <string name="video_flash">闪烁</string>
<string name="video_balance">色彩平衡</string> <string name="video_balance">色彩平衡</string>
<string name="video_sharp">锐化</string>
</resources> </resources>

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save