这与视频中的问题是相同的ffmpeg 裁剪:‘宽度无效,过大或非正值’
尝试将视频裁剪为 9:16 的宽高比,检索到的视频大小为宽度 3840 高度 2160,但宽度“3836”或高度“2160”的尺寸无效,太大或为非正值
命令:
I/System.out: "-y" "-ss" "0" "-t" "31" "-i" "/storage/emulated/0/Download/20210227_175547.mp4" "-strict" "experimental" "-vf" "crop=w=3837:h=2160:x=1:y=-2070" "-r" "15" "-ab" "128k" "-vcodec" "mpeg4" "-acodec" "copy" "-b:v" "2500k" "-sample_fmt" "s16" "-ss" "0" "-t" "31" "/storage/emulated/0/VEditor/VideoCroper/20210227_175547-0-13.mp4"
Java代码:
StringBuilder sb = new StringBuilder();
sb.append("crop=w=");
sb.append(this.final_width);
sb.append(":h=");
sb.append(this.final_height);
sb.append(":x=");
sb.append(this.horizontal);
sb.append(":y=");
sb.append(this.vertical);
a(new String[]{"-y", "-ss", Start, "-t", Duration, "-i",file_name, "-strict", "experimental", "-vf",sb.toString(), "-r", "15", "-ab", "128k", "-vcodec", "mpeg4", "-acodec", "copy", "-b:v", "2500k", "-sample_fmt", "s16", "-ss", "0", "-t", this.Duration, Output}, Output);
答案1
由于旋转侧数据,ffmpeg 会自动旋转视频,因此在裁剪之前视频会变成 2160x3840,从而导致错误。您可以使用-noautorotate
输入选项告诉它不要自动旋转。
I/System.out: "-y" "-noautorotate" "-ss" "0" "-t" "31" "-i" "/storage/emulated/0/Download/20210227_175547.mp4" "-vf" "crop=w=3837:h=2160:x=1:y=-2070" "-r" "15" "-vcodec" "mpeg4" "-acodec" "copy" "-b:v" "2500k" "/storage/emulated/0/VEditor/VideoCroper/20210227_175547-0-13.mp4"
我删除了没有任何作用的选项。