我有几个以横向和纵向模式制作的视频。我想将它们连接成一部电影。
为此,我旋转了肖像视频:
ffmpeg -i in.mp4 -vf transpose=1 out.mp4
构建要连接的文件列表并将所有文件连接起来:
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
结果是无法播放。所有玩家在第一次从横向切换到旋转纵向片段时都会挂起/崩溃。
回复LordNeckbeard的请求:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2017-07-20T12:50:32.000000Z
Duration: 00:00:30.36, start: 0.000000, bitrate: 20202 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 20005 kb/s, SAR 1:1 DAR 16:9, 29.45 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2017-07-20T12:50:32.000000Z
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 156 kb/s (default)
Metadata:
creation_time : 2017-07-20T12:50:32.000000Z
handler_name : SoundHandle
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2017-07-24T13:57:42.000000Z
Duration: 00:00:31.94, start: 0.000000, bitrate: 20171 kb/s
Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 19997 kb/s, SAR 1:1 DAR 16:9, 29.43 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 90
creation_time : 2017-07-24T13:57:42.000000Z
handler_name : VideoHandle
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 156 kb/s (default)
Metadata:
creation_time : 2017-07-24T13:57:42.000000Z
handler_name : SoundHandle
At least one output file must be specified```
给我文件
$f
结果的最终算法是:
删除元数据旋转字段:
ffmpeg -i $f -c copy -metadata:s:v:0 rotate=0 md_$f
旋转视频:
ffmpeg -i md_$f -vf transpose=1 rt_$f.mp4
转换为TS:
ffmpeg -i rt_$f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
连接所有 ts 文件:
ffmpeg -i "concat:f1.ts|f2.ts|f3.ts" -c copy -bsf:a aac_adtstoasc output.mp4