change time unit from int to float

dev
xufuji456 4 years ago
parent 7f031c8dcf
commit 979b25dbbf
  1. 2
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt
  2. 6
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt
  3. 16
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -174,7 +174,7 @@ class AudioHandleActivity : BaseActivity() {
return
}
val cutFile = PATH + File.separator + "cutAudio" + suffix
commandLine = FFmpegUtil.cutAudio(srcFile, 10, 15, cutFile)
commandLine = FFmpegUtil.cutAudio(srcFile, 10.5f, 15.0f, cutFile)
}
R.id.btn_concat//concat audio
-> {

@ -165,8 +165,8 @@ class VideoHandleActivity : BaseActivity() {
R.id.btn_video_cut//cut video
-> {
val cutVideo = PATH + File.separator + "cutVideo" + suffix
val startTime = 0
val duration = 20
val startTime = 5.5f
val duration = 20.0f
commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, cutVideo)
}
R.id.btn_video_concat//concat video together
@ -174,7 +174,7 @@ class VideoHandleActivity : BaseActivity() {
R.id.btn_screen_shot//video snapshot
-> {
val screenShot = PATH + File.separator + "screenShot.jpg"
val time = 18
val time = 10.5f
commandLine = FFmpegUtil.screenShot(srcFile, time, screenShot)
}
R.id.btn_water_mark//add watermark to video

@ -41,8 +41,8 @@ public class FFmpegUtil {
* @param outputPath output file
* @return cut success or not
*/
public static String[] cutAudio(String inputPath, int startTime, int duration, String outputPath) {
String cutAudioCmd = "ffmpeg -ss %d -accurate_seek -t %d -i %s -acodec copy -vn %s";
public static String[] cutAudio(String inputPath, float startTime, float duration, String outputPath) {
String cutAudioCmd = "ffmpeg -ss %f -accurate_seek -t %f -i %s -acodec copy -vn %s";
cutAudioCmd = String.format(Locale.getDefault(), cutAudioCmd, startTime, duration, inputPath, outputPath);
return cutAudioCmd.split(" ");
}
@ -333,12 +333,12 @@ public class FFmpegUtil {
* @param outputPath output file
* @return cut video success or not
*/
public static String[] cutVideo(String inputPath, int startTime, int duration, String outputPath) {
public static String[] cutVideo(String inputPath, float startTime, float duration, String outputPath) {
// -map 0 -codec copy (copy all tracks)
// -map 0:v -vcodec copy (copy track of video)
// -map 0:a -acodec copy (copy all tracks of audio)
// -map 0:s -scodec copy (copy all tracks of subtitle)
String cutVideoCmd = "ffmpeg -ss %d -accurate_seek -t %d -i %s -map 0 -codec copy -avoid_negative_ts 1 %s";
String cutVideoCmd = "ffmpeg -ss %f -accurate_seek -t %f -i %s -map 0 -codec copy -avoid_negative_ts 1 %s";
cutVideoCmd = String.format(Locale.getDefault(), cutVideoCmd, startTime, duration, inputPath, outputPath);
return cutVideoCmd.split(" ");
}
@ -347,13 +347,13 @@ public class FFmpegUtil {
* screenshot from video, you could assign the specific time
*
* @param inputPath input file
* @param time which time you want to shot
* @param offset which time you want to shot
* @param outputPath output file
* @return screenshot success or not
*/
public static String[] screenShot(String inputPath, int time, String outputPath) {
String screenShotCmd = "ffmpeg -ss %d -i %s -f image2 -vframes 1 -an %s";
screenShotCmd = String.format(Locale.getDefault(), screenShotCmd, time, inputPath, outputPath);
public static String[] screenShot(String inputPath, float offset, String outputPath) {
String screenShotCmd = "ffmpeg -ss %f -i %s -f image2 -vframes 1 -an %s";
screenShotCmd = String.format(Locale.getDefault(), screenShotCmd, offset, inputPath, outputPath);
return screenShotCmd.split(" ");
}

Loading…
Cancel
Save