zoom photo to video

pull/209/head
xufulong 3 years ago
parent 63edbdacd3
commit 3d0950e02f
  1. 71
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt
  2. 12
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 2
      app/src/main/res/values-en/strings.xml
  4. 2
      app/src/main/res/values/strings.xml

@ -121,13 +121,12 @@ class VideoHandleActivity : BaseActivity() {
getString(R.string.video_denoise),
getString(R.string.video_image),
getString(R.string.video_pip),
getString(R.string.video_moov),
getString(R.string.video_speed),
getString(R.string.video_thumbnail),
getString(R.string.video_subtitle),
getString(R.string.video_rotate),
getString(R.string.video_gop),
getString(R.string.video_gray))
getString(R.string.video_gray),
getString(R.string.video_zoom))
layoutVideoHandle = findViewById(R.id.list_video_item)
val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
@ -165,10 +164,10 @@ class VideoHandleActivity : BaseActivity() {
if (!FileUtil.checkFileExist(srcFile)) {
return
}
if (!FileUtil.isVideo(srcFile)) {
showToast(getString(R.string.wrong_video_format))
return
}
// if (!FileUtil.isVideo(srcFile)) {
// showToast(getString(R.string.wrong_video_format))
// return
// }
val suffix = FileUtil.getFileSuffix(srcFile)
if (suffix == null || suffix.isEmpty()) {
return
@ -311,58 +310,39 @@ class VideoHandleActivity : BaseActivity() {
outputPath = PATH + File.separator + "PicInPic.mp4"
commandLine = FFmpegUtil.picInPicVideo(inputFile1, inputFile2, x, y, outputPath)
}
13 //moov box moves ahead, which is behind mdat box of mp4 video
-> {
if (!srcFile.endsWith(FileUtil.TYPE_MP4)) {
showToast(getString(R.string.tip_not_mp4_video))
return
}
val filePath = FileUtil.getFilePath(srcFile)
var fileName = FileUtil.getFileName(srcFile)
fileName = "moov_" + fileName!!
outputPath = filePath + File.separator + fileName
if (useFFmpegCmd) {
commandLine = FFmpegUtil.moveMoovAhead(srcFile, outputPath)
} else {
val ffmpegCmd = FFmpegCmd()
val result = ffmpegCmd.moveMoovAhead(srcFile, outputPath)
Log.e(TAG, "result=" + (result == 0))
}
}
14 //playing speed of video
13 //playing speed of video
-> {
outputPath = PATH + File.separator + "speed.mp4"
commandLine = FFmpegUtil.changeSpeed(srcFile, outputPath, 2f, false)
}
15 // insert thumbnail into video
14 // insert thumbnail into video
-> {
val thumbnailPath = PATH + File.separator + "thumb.jpg"
outputPath = PATH + File.separator + "thumbnailVideo" + suffix
commandLine = FFmpegUtil.insertPicIntoVideo(srcFile, thumbnailPath, outputPath)
}
16 //add subtitle into video
15 //add subtitle into video
-> {
val subtitlePath = PATH + File.separator + "test.ass"
outputPath = PATH + File.separator + "subtitle.mkv"
commandLine = FFmpegUtil.addSubtitleIntoVideo(srcFile, subtitlePath, outputPath)
}
17 // set the rotate degree of video
16 // set the rotate degree of video
-> {
val rotateDegree = 90
outputPath = PATH + File.separator + "rotate" + rotateDegree + suffix
commandLine = FFmpegUtil.rotateVideo(srcFile, rotateDegree, outputPath)
}
18 // change the gop(key frame interval) of video
-> {
val gop = 30
outputPath = PATH + File.separator + "gop" + gop + suffix
commandLine = FFmpegUtil.changeGOP(srcFile, gop, outputPath)
}
19 // change video from RGB to gray
17 // change video from RGB to gray
-> {
outputPath = PATH + File.separator + "gray" + suffix
commandLine = FFmpegUtil.toGrayVideo(srcFile, outputPath)
}
18 // zoom photo to video
-> {
outputPath = PATH + File.separator + "zoom.mp4"
commandLine = FFmpegUtil.photoZoomToVideo(srcFile, outputPath)
}
else -> {
}
}
@ -406,6 +386,25 @@ class VideoHandleActivity : BaseActivity() {
ffmpegHandler!!.executeFFmpegCmds(commandList)
}
private fun moov(srcFile: String) {
if (!srcFile.endsWith(FileUtil.TYPE_MP4)) {
showToast(getString(R.string.tip_not_mp4_video))
return
}
val filePath = FileUtil.getFilePath(srcFile)
var fileName = FileUtil.getFileName(srcFile)
fileName = "moov_" + fileName!!
outputPath = filePath + File.separator + fileName
if (useFFmpegCmd) {
val commandLine = FFmpegUtil.moveMoovAhead(srcFile, outputPath)
ffmpegHandler!!.executeFFmpegCmd(commandLine)
} else {
val ffmpegCmd = FFmpegCmd()
val result = ffmpegCmd.moveMoovAhead(srcFile, outputPath)
Log.e(TAG, "result=" + (result == 0))
}
}
/**
* Combine pictures into video
*/

@ -624,6 +624,18 @@ public class FFmpegUtil {
return grayCmd.split(" ");
}
/**
* Photo zoom to video
* @param inputPath inputPath
* @param outputPath outputPath
* @return zoomCmd
*/
public static String[] photoZoomToVideo(String inputPath, String outputPath) {
String grayCmd = "ffmpeg -loop 1 -i %s -vf zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125 -t 8 %s";
grayCmd = String.format(Locale.getDefault(), grayCmd, inputPath, outputPath);
return grayCmd.split(" ");
}
/**
* using FFprobe to parse the media format
*

@ -65,7 +65,7 @@
<string name="video_speed">Playing speed</string>
<string name="video_thumbnail">Insert thumbnail</string>
<string name="video_subtitle">add subtitle</string>
<string name="video_gop">KeyFrame interval</string>
<string name="video_zoom">Zoom video</string>
<string name="video_gray">Gray video</string>
<string name="swap">Swap</string>

@ -65,7 +65,7 @@
<string name="video_speed">播放倍率</string>
<string name="video_thumbnail">插入封面</string>
<string name="video_subtitle">添加字幕</string>
<string name="video_gop">关键帧间隔</string>
<string name="video_zoom">图片缩放</string>
<string name="video_gray">黑白视频</string>
<string name="swap">切换</string>

Loading…
Cancel
Save