问题
I referred FFMPEG not "cutting" as expected to split video in chunks in below format:
00:00:00 - 00:00:01
00:00:01 - 00:00:02
00:00:02 - 00:00:03
00:00:03 - 00:00:04
00:00:04 - 00:00:05
Here is the command i used:
String[] cmd1 = new String []{"-ss", "00:00:00.000", "-i", inputVideoUrl, "-t", "00:00:01.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd2 = new String []{"-ss", "00:00:01.000", "-i", inputVideoUrl, "-t", "00:00:02.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd3 = new String []{"-ss", "00:00:02.000", "-i", inputVideoUrl, "-t", "00:00:03.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd4 = new String []{"-ss", "00:00:03.000", "-i", inputVideoUrl, "-t", "00:00:04.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd5 = new String []{"-ss", "00:00:04.000", "-i", inputVideoUrl, "-t", "00:00:05.000", "-c:v", "libx264", "-strict", "-2", outputPath};
And i use this library: https://github.com/teanersener/mobile-ffmpeg
implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.2.2.LTS'
When i execute i get the duration starting from beginning of the video all the time. Please suggest what am i doing wrong, i searched and tried changing commands but nothing works.
00:00:00 - 00:00:01
00:00:00 - 00:00:02
00:00:00 - 00:00:03
00:00:00 - 00:00:04
00:00:00 - 00:00:05
Let me share another example to explain my requirement: inputVideoUrl contains a video of any length(ex: 5min) I want to cut a user selected portion of it(ex first one minute) in the form of 5 split videos.
split 1: 00 sec - 12.0sec
split 2: 12.1 sec - 24.0sec
split 3: 24.1 sec - 36.0sec
split 4: 36.1 sec - 48.0sec
split 5: 48.1 sec - 60.0sec
And later i will provide these split videos to a player playlist.
回答1:
Use the segment muxer
You can do everything with one command with the segment muxer:
ffmpeg -i input -c:v libx264 -c:a aac -f segment -segment_time 1 -force_key_frames "expr:gte(t,n_forced*1)" -reset_timestamps 1 output_%03d.mp4
The numerical value in expr:gte(t,n_forced*1)
should equal the -segment_time
value (which is 1
in this example).
来源:https://stackoverflow.com/questions/65403348/ffmpeg-not-cutting-as-expected-in-android