Feature: convert video into stereo3d mode(VR video)

pull/221/head
xufuji456 2 years ago
parent 643d4c8081
commit 92da88c480
  1. 62
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt
  2. 20
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 1
      app/src/main/res/values-en/strings.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -115,7 +115,7 @@ class VideoHandleActivity : BaseActivity() {
getString(R.string.video_screen_shot), getString(R.string.video_screen_shot),
getString(R.string.video_water_mark), getString(R.string.video_water_mark),
getString(R.string.video_remove_logo), getString(R.string.video_remove_logo),
getString(R.string.video_from_photo), getString(R.string.video_stereo3d),
getString(R.string.video_to_gif), getString(R.string.video_to_gif),
getString(R.string.video_multi), getString(R.string.video_multi),
getString(R.string.video_reverse), getString(R.string.video_reverse),
@ -175,28 +175,25 @@ class VideoHandleActivity : BaseActivity() {
return return
} }
when (currentPosition) { when (currentPosition) {
0 //transform format 0 -> { //transform format
-> {
outputPath = PATH + File.separator + "transformVideo.mp4" outputPath = PATH + File.separator + "transformVideo.mp4"
commandLine = FFmpegUtil.transformVideo(srcFile, outputPath) commandLine = FFmpegUtil.transformVideo(srcFile, outputPath)
} }
1 //cut video 1 -> { //cut video
-> {
outputPath = PATH + File.separator + "cutVideo" + suffix outputPath = PATH + File.separator + "cutVideo" + suffix
val startTime = 5.5f val startTime = 5.5f
val duration = 20.0f val duration = 20.0f
commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, outputPath) commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, outputPath)
} }
2 //concat video together 2 -> { //concat video together
-> concatVideo(srcFile) concatVideo(srcFile)
3 //video snapshot }
-> { 3 -> { //video snapshot
outputPath = PATH + File.separator + "screenShot.jpg" outputPath = PATH + File.separator + "screenShot.jpg"
val time = 10.5f val time = 10.5f
commandLine = FFmpegUtil.screenShot(srcFile, time, outputPath) commandLine = FFmpegUtil.screenShot(srcFile, time, outputPath)
} }
4 //add watermark to video 4 -> { //add watermark to video
-> {
// the unit of bitRate is kb // the unit of bitRate is kb
var bitRate = 500 var bitRate = 500
val retriever = MediaMetadataRetriever() val retriever = MediaMetadataRetriever()
@ -234,15 +231,17 @@ class VideoHandleActivity : BaseActivity() {
} }
} }
} }
5 //Remove logo from video, or use to mosaic video 5 -> { //Remove logo from video, or use to mosaic video
-> {
outputPath = PATH + File.separator + "removeLogo" + suffix outputPath = PATH + File.separator + "removeLogo" + suffix
val widthL = 64 val widthL = 64
val heightL = 40 val heightL = 40
commandLine = FFmpegUtil.removeLogo(srcFile, 10, 10, widthL, heightL, outputPath) commandLine = FFmpegUtil.removeLogo(srcFile, 10, 10, widthL, heightL, outputPath)
} }
7 //convert video into gif 6 -> { // VR video: convert to stereo3d video
-> { outputPath = PATH + File.separator + "stereo3d" + suffix
commandLine = FFmpegUtil.videoStereo3D(srcFile, outputPath)
}
7 -> { //convert video into gif
outputPath = PATH + File.separator + "video2Gif.gif" outputPath = PATH + File.separator + "video2Gif.gif"
val gifStart = 10 val gifStart = 10
val gifDuration = 3 val gifDuration = 3
@ -264,8 +263,7 @@ class VideoHandleActivity : BaseActivity() {
convertGifInHighQuality(outputPath!!, srcFile, gifStart, gifDuration, frameRate) convertGifInHighQuality(outputPath!!, srcFile, gifStart, gifDuration, frameRate)
} }
} }
8 //combine video which layout could be horizontal of vertical 8 -> { //combine video which layout could be horizontal of vertical
-> {
val input1 = PATH + File.separator + "input1.mp4" val input1 = PATH + File.separator + "input1.mp4"
val input2 = PATH + File.separator + "input2.mp4" val input2 = PATH + File.separator + "input2.mp4"
outputPath = PATH + File.separator + "multi.mp4" outputPath = PATH + File.separator + "multi.mp4"
@ -274,18 +272,15 @@ class VideoHandleActivity : BaseActivity() {
} }
commandLine = FFmpegUtil.multiVideo(input1, input2, outputPath, VideoLayout.LAYOUT_HORIZONTAL) commandLine = FFmpegUtil.multiVideo(input1, input2, outputPath, VideoLayout.LAYOUT_HORIZONTAL)
} }
9 //video reverse 9 -> { //video reverse
-> {
outputPath = PATH + File.separator + "reverse.mp4" outputPath = PATH + File.separator + "reverse.mp4"
commandLine = FFmpegUtil.reverseVideo(srcFile, outputPath) commandLine = FFmpegUtil.reverseVideo(srcFile, outputPath)
} }
10 //noise reduction of video 10 -> { //noise reduction of video
-> {
outputPath = PATH + File.separator + "denoise.mp4" outputPath = PATH + File.separator + "denoise.mp4"
commandLine = FFmpegUtil.denoiseVideo(srcFile, outputPath) commandLine = FFmpegUtil.denoiseVideo(srcFile, outputPath)
} }
11 //convert video to picture 11 -> { //convert video to picture
-> {
outputPath = PATH + File.separator + "Video2Image/" outputPath = PATH + File.separator + "Video2Image/"
val imageFile = File(outputPath) val imageFile = File(outputPath)
if (!imageFile.exists()) { if (!imageFile.exists()) {
@ -298,8 +293,7 @@ class VideoHandleActivity : BaseActivity() {
val mFrameRate = 10//frameRate val mFrameRate = 10//frameRate
commandLine = FFmpegUtil.videoToImage(srcFile, mStartTime, mDuration, mFrameRate, outputPath) commandLine = FFmpegUtil.videoToImage(srcFile, mStartTime, mDuration, mFrameRate, outputPath)
} }
12 //combine into picture-in-picture video 12 -> { //combine into picture-in-picture video
-> {
val inputFile1 = PATH + File.separator + "beyond.mp4" val inputFile1 = PATH + File.separator + "beyond.mp4"
val inputFile2 = PATH + File.separator + "small_girl.mp4" val inputFile2 = PATH + File.separator + "small_girl.mp4"
if (!FileUtil.checkFileExist(inputFile1) && !FileUtil.checkFileExist(inputFile2)) { if (!FileUtil.checkFileExist(inputFile1) && !FileUtil.checkFileExist(inputFile2)) {
@ -312,36 +306,30 @@ class VideoHandleActivity : BaseActivity() {
outputPath = PATH + File.separator + "PicInPic.mp4" outputPath = PATH + File.separator + "PicInPic.mp4"
commandLine = FFmpegUtil.picInPicVideo(inputFile1, inputFile2, x, y, outputPath) commandLine = FFmpegUtil.picInPicVideo(inputFile1, inputFile2, x, y, outputPath)
} }
13 //playing speed of video 13 -> { //playing speed of video
-> {
outputPath = PATH + File.separator + "speed.mp4" outputPath = PATH + File.separator + "speed.mp4"
commandLine = FFmpegUtil.changeSpeed(srcFile, outputPath, 2f, false) commandLine = FFmpegUtil.changeSpeed(srcFile, outputPath, 2f, false)
} }
14 // insert thumbnail into video 14 -> { // insert thumbnail into video
-> {
val thumbnailPath = PATH + File.separator + "thumb.jpg" val thumbnailPath = PATH + File.separator + "thumb.jpg"
outputPath = PATH + File.separator + "thumbnailVideo" + suffix outputPath = PATH + File.separator + "thumbnailVideo" + suffix
commandLine = FFmpegUtil.insertPicIntoVideo(srcFile, thumbnailPath, outputPath) commandLine = FFmpegUtil.insertPicIntoVideo(srcFile, thumbnailPath, outputPath)
} }
15 //add subtitle into video 15 -> { //add subtitle into video
-> {
val subtitlePath = PATH + File.separator + "test.ass" val subtitlePath = PATH + File.separator + "test.ass"
outputPath = PATH + File.separator + "subtitle.mkv" outputPath = PATH + File.separator + "subtitle.mkv"
commandLine = FFmpegUtil.addSubtitleIntoVideo(srcFile, subtitlePath, outputPath) commandLine = FFmpegUtil.addSubtitleIntoVideo(srcFile, subtitlePath, outputPath)
} }
16 // set the rotate degree of video 16 -> { // set the rotate degree of video
-> {
val rotateDegree = 90 val rotateDegree = 90
outputPath = PATH + File.separator + "rotate" + rotateDegree + suffix outputPath = PATH + File.separator + "rotate" + rotateDegree + suffix
commandLine = FFmpegUtil.rotateVideo(srcFile, rotateDegree, outputPath) commandLine = FFmpegUtil.rotateVideo(srcFile, rotateDegree, outputPath)
} }
17 // change video from RGB to gray 17 -> { // change video from RGB to gray
-> {
outputPath = PATH + File.separator + "gray" + suffix outputPath = PATH + File.separator + "gray" + suffix
commandLine = FFmpegUtil.toGrayVideo(srcFile, outputPath) commandLine = FFmpegUtil.toGrayVideo(srcFile, outputPath)
} }
18 // zoom photo to video 18 -> { // zoom photo to video
-> {
outputPath = PATH + File.separator + "zoom.mp4" outputPath = PATH + File.separator + "zoom.mp4"
commandLine = FFmpegUtil.photoZoomToVideo(srcFile, outputPath) commandLine = FFmpegUtil.photoZoomToVideo(srcFile, outputPath)
} }

@ -826,5 +826,23 @@ public class FFmpegUtil {
return insert(waveformCmd.split(" "), 2, inputPath, outputPath); return insert(waveformCmd.split(" "), 2, inputPath, outputPath);
} }
// ffmpeg -i beyond.mp4 -vf stereo3d=sbsl:arbg -y left3d.mp4 /**
* Convert video into stereo3d mode(VR video)
* @param inputPath inputPath
* @param outputPath outputPath
* @return the command of stereo3d
*/
public static String[] videoStereo3D(String inputPath, String outputPath) {
/* *
* sbsl: side by side parallel (left eye left, right eye right)
* sbsr: side by side crosseye (right eye left, left eye right)
* abl : above-below (left eye above, right eye below)
* al : alternating frames (left eye first, right eye second)
* irl : interleaved rows (left eye has top row, right eye next)
* icl : interleaved columns, left eye first
*/
String stereo3dCmd = "ffmpeg -i -filter_complex stereo3d=sbsl:arbg";
return insert(stereo3dCmd.split(" "), 2, inputPath, outputPath);
}
} }

@ -68,6 +68,7 @@
<string name="video_subtitle">add subtitle</string> <string name="video_subtitle">add subtitle</string>
<string name="video_zoom">Zoom video</string> <string name="video_zoom">Zoom video</string>
<string name="video_gray">Gray video</string> <string name="video_gray">Gray video</string>
<string name="video_stereo3d">stereo 3d</string>
<string name="swap">Swap</string> <string name="swap">Swap</string>
<string name="start">Start</string> <string name="start">Start</string>

@ -68,6 +68,7 @@
<string name="video_subtitle">添加字幕</string> <string name="video_subtitle">添加字幕</string>
<string name="video_zoom">图片缩放</string> <string name="video_zoom">图片缩放</string>
<string name="video_gray">黑白视频</string> <string name="video_gray">黑白视频</string>
<string name="video_stereo3d">3D视频</string>
<string name="swap">切换</string> <string name="swap">切换</string>
<string name="start">开始</string> <string name="start">开始</string>

Loading…
Cancel
Save