change the speed of video

change the speed of video
pull/166/head
xufulong 5 years ago
parent 835f092ab4
commit 8e64125f0b
  1. 7
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 29
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 7
      app/src/main/res/layout/activity_video_handle.xml
  4. 1
      app/src/main/res/values-en/strings.xml
  5. 1
      app/src/main/res/values/strings.xml

@ -99,7 +99,8 @@ public class VideoHandleActivity extends BaseActivity {
R.id.btn_denoise_video,
R.id.btn_to_image,
R.id.btn_pip,
R.id.btn_moov
R.id.btn_moov,
R.id.btn_speed
);
}
@ -271,6 +272,10 @@ public class VideoHandleActivity extends BaseActivity {
Log.e(TAG, "move moov use time=" + (System.currentTimeMillis() - start));
}
break;
case R.id.btn_speed://playing speed of video
String speed = PATH + File.separator + "speed.mp4";
commandLine = FFmpegUtil.changeSpeed(srcFile, speed, 2f, false);
break;
default:
break;
}

@ -478,11 +478,36 @@ public class FFmpegUtil {
return ffprobeCmd.split(" ");
}
public static String[] changeSpeed(String inputFile, String outputFile, float speed) {
/**
* Changing the speed of playing, speed range at 0.5-2 in audio-video mode.
* However, in pure video mode, the speed range at 0.25-4
* @param inputFile the inputFile of normal speed
* @param outputFile the outputFile which you want to change speed
* @param speed speed of playing
* @param pureVideo whether pure video or not, default false
* @return change speed success or not
*/
public static String[] changeSpeed(String inputFile, String outputFile, float speed, boolean pureVideo) {
//audio atempo: 0.5--2
//video pts:0.25--4
if (pureVideo) {
if (speed > 4 || speed < 0.25) {
throw new IllegalArgumentException("speed range is 0.25--4");
}
} else {
if (speed > 2 || speed < 0.5) {
throw new IllegalArgumentException("speed range is 0.5--2");
}
}
float ptsFactor = 1/speed;
String speedCmd = "ffmpeg -i %s -filter_complex [0:v]setpts=%.2f*PTS[v];[0:a]atempo=%.2f[a] -map [v] -map [a] %s";
String speedCmd;
if (pureVideo) {
speedCmd = "ffmpeg -i %s -filter_complex [0:v]setpts=%.2f*PTS[v] -map [v] %s";
speedCmd = String.format(Locale.getDefault(), speedCmd, inputFile, ptsFactor, outputFile);
} else {
speedCmd = "ffmpeg -i %s -filter_complex [0:v]setpts=%.2f*PTS[v];[0:a]atempo=%.2f[a] -map [v] -map [a] %s";
speedCmd = String.format(Locale.getDefault(), speedCmd, inputFile, ptsFactor, speed, outputFile);
}
return speedCmd.split(" ");
}

@ -122,6 +122,13 @@
android:layout_marginTop="4dp"
android:text="@string/video_moov"/>
<Button
android:id="@+id/btn_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/video_speed"/>
</LinearLayout>
</ScrollView>

@ -42,6 +42,7 @@
<string name="video_pip">Video Pip</string>
<string name="video_preview">Video preview</string>
<string name="video_moov">MOOV move ahead</string>
<string name="video_speed">Playing speed</string>
<string name="swap">Swap</string>
<string name="start">Start</string>

@ -42,6 +42,7 @@
<string name="video_pip">视频画中画</string>
<string name="video_preview">播放预览</string>
<string name="video_moov">MOOV前移</string>
<string name="video_speed">播放倍率</string>
<string name="swap">切换</string>
<string name="start">开始</string>

Loading…
Cancel
Save