[英]How to reverse a video using ffmpeg in android?
我想反向播放從圖庫和相機加載的視頻。 視頻使用ffmpeg命令轉換為圖像幀,並且幀轉換為反向視頻。
從https://stackoverflow.com/a/8137637/2930834
后者如下:
轉儲所有視頻幀
$ ffmpeg -i input.mkv -an -qscale 1 %06d.jpg
轉儲音頻
$ ffmpeg -i input.mkv -vn -ac 2 audio.wav
反向音頻
$ sox -V audio.wav backwards.wav reverse
Cat視頻幀以與FFmpeg相反的順序輸入
$ cat $(ls -t *jpg) | ffmpeg -f image2pipe -vcodec mjpeg -r 25 -i - -i backwards.wav -vcodec libx264 -vpre slow -crf 20 -threads 0 -acodec flac output.mkv
使用Mencoder對PAL dv進行去隔行,並將幀頻從25倍增至50,然后通過管道傳輸到FFmpeg。
$ mencoder input.dv -of rawvideo -ofps 50 -ovc raw -vf yadif=3,format=i420 -nosound -really-quiet -o - | ffmpeg -vsync 0 -f rawvideo -s 720x576 -r 50 -pix_fmt yuv420p -i - -vcodec libx264 -vpre slow -crf 20 -threads 0 video.mkv
還值得檢查,
我還沒試過 希望這可以幫助
1.將視頻分為時長為10秒或更短的段(以下命令為6秒)
String[] complexCommand = {"-i", inputFileAbsolutePath, "-c:v", "libx264", "-crf", "22", "-map", "0", "-segment_time", "6", "-g", "9", "-sc_threshold", "0", "-force_key_frames", "expr:gte(t,n_forced*6)", "-f", "segment", outputFileAbsolutePath};
2. 反轉分段視頻
有聲
String command[] = {"-i", inputFileAbsolutePath, "-vf", "reverse", "-af", "areverse", outputFileAbsolutePath};
沒有音頻
String command[] = {"-i",inputFileAbsolutePath, "-vf", "reverse", outputFileAbsolutePath};
3. 以反向順序串聯反向分割的視頻
有聲
String command[] = {"-i",inputFile1AbsolutePath,"-i",inputFile2AbsolutePath .....,"-i",inputFileNAbsolutePath,"-filter_complex","[0:v0] [0:a0] [1:v1] [1:a1]...[N:vN] concat=n=N:v=1:a=1 [v] [a],"-map","[v]","-map","[a]", outputFileAbsolutePath};
沒有音頻
String command[] = {"-i",inputFile1AbsolutePath,"-i",inputFile2AbsolutePath .....,"-i",inputFileNAbsolutePath,"-filter_complex","[0:0] [1:0] [2:0]...[N:0] concat=n=N:v=1:a=0",outputFileAbsolutePath};
此示例代碼僅是反向視頻,不包括音頻。
build.gradle
compile 'com.writingminds:FFmpegAndroid:0.3.2'
在執行命令之前,您需要先加載二進制文件
FFmpeg ffmpeg = FFmpeg.getInstance(this);
try {
ffmpeg.loadBinary(new FFmpegLoadBinaryResponseHandler() {
@Override
public void onFailure() {
}
@Override
public void onSuccess() {
}
@Override
public void onStart() {
}
@Override
public void onFinish() {
}
});
} catch (FFmpegNotSupportedException e) {
e.printStackTrace();
}
加載二進制文件后,您可以執行命令。
String strInputVideoPath = dir.getAbsolutePath() + "/" + "1543999518815.mp4";
String strRevOutputVideoPath = dir.getAbsolutePath() + "/" + "reverse.mp4";
String[] cmdRevVid = {"-i", strInputVideoPath,"-vf","reverse", strRevOutputVideoPath};
try {
ffmpeg.execute(cmdRevVid, new ExecuteBinaryResponseHandler(){
@Override
public void onStart() {
}
@Override
public void onProgress(String message) {
}
@Override
public void onFailure(String message) {
}
@Override
public void onSuccess(String message) {
try{
}catch (Exception ex){
}
}
@Override
public void onFinish() {
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is not supported by device
}
就我而言,我必須做反向視頻和連續視頻本身。 參考文章
String[] cmdFinal = {"-i", dir.getAbsolutePath() + "/" + "inputVideo.mp4",
"-filter_complex", "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]",
"-map", "[v]",
dir.getAbsolutePath() + "/" + "final.mp4"};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.