我在连接视频时遇到了问题。
首先使用以下命令修剪不同视频中的块
val cmd = arrayOf("-ss", start, "-i", inputFile.ts,"-c:v" ,"libx264","-preset" ,"ultrafast","-crf" ,"32", "-tune","fastdecode","-t",
duration, "-avoid_negative_ts", "make_zero","-fflags","+genpts",
outPutPath.mp4
)
使用以下命令进行第二次合并
val cmd = arrayOf("-f", "concat", "-safe", "0", "-i", data.ts, "-c", "copy", outP.mp4)
仅当视频尺寸不同时才会发生这种情况。 请指导我这里做错了什么或如何解决这个问题。
更新 我知道您必须将视频缩放到相同的大小才能实现上述效果。我已执行以下命令:** 过滤器 setsar 具有未连接的输出转换失败!**
var cmd = arrayOf( "-i", listofFiles[0],"-i",listofFiles[1], "-filter_complex",
"[0]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[0v];[1]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[1v];[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1:unsafe=1[v][a]", "-map", "[v]","-map" ,"[a]" ,outP)"
出错:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Flory/temp/Trimmed1599124061259.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.35.101
Duration: 00:00:05.02, start: 0.000000, bitrate: 1537 kb/s
Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 1080x1920 [SAR 1:1 DAR 9:16], 1465 kb/s, 24.97 fps, 24.87 tbr, 90k tbn, 49.74 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 70 kb/s (default)
Metadata:
handler_name : SoundHandle
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Flory/temp/Trimmed1599124064134.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.35.101
Duration: 00:00:03.02, start: 0.000000, bitrate: 16173 kb/s
Stream #1:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 16279 kb/s, 29.79 fps, 29.58 tbr, 11360 tbn, 59.17 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #1:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s (default)
Metadata:
handler_name : SoundHandle
Filter setsar has an unconnected output
Conversion failed!
请帮助我,我已经被困了一个星期了。
答案1
使用[0v]
和[1v]
作为 concat 过滤器的输入,而不是[0:v]
和[1:v]
。
ffmpeg -i input0.mp4 -i input1.mp4 -filter_complex "[0]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[0v];[1]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[1v];[0v][0:a][1v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
答案2
解决了
通过运行以下命令:
var cmd = arrayOf( "-i", listofFiles[0],"-i",listofFiles[1],"-max_muxing_queue_size", "9999","-vsync" ,"2" , "-filter_complex",
"[0]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[0v];[1]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[1v];[0v][0:a][1v][1:a]concat=n=2:v=1:a=1:unsafe=1[outv][outa]", "-map", "[outv]","-map" ,"[outa]","-c:a", "aac","-strict", "-2","-c:v","libx264","-crf" ,"32",outP)
这会使音频流保留在最终输出中,同时将两个输入缩放为相等的最小尺寸以避免拉伸。
不确定这是否是最好的解决方案,但至少它是一个可行的解决方案。