我有这样的mp4文件(格式相同但更长):
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'N1.2.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2018-10-31T13:44:21.000000Z
Duration: 00:28:54.21, start: 0.000000, bitrate: 10295 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 9972 kb/s, 50 fps, 50 tbr, 50k tbn, 100 tbc (default)
Metadata:
creation_time : 2018-10-31T13:44:21.000000Z
handler_name : ?Mainconcept Video Media Handler
encoder : AVC Coding
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
Metadata:
creation_time : 2018-10-31T13:44:21.000000Z
handler_name : #Mainconcept MP4 Sound Media Handler
我还有另一个3分钟的视频文件。并且没有音频。对其他视频进行编码的最快方法是将其编码为主视频,然后用原始视频的视频轨道的最后三分钟替换它?
换一种说法。我有1小时的视频A.使用上面显示的编码。
我的视频B长3分钟,没有音频。随机编码。
我希望视频C具有与A相同的编码和相同的音频。但它的视频轨道将是A + B的前57分钟(即3分钟)。
我想尽快做到这一点,所以我不想重新编码A.
我知道如何连接两个视频,我使用这个命令:
ffmpeg -f concat -i files.txt -c copy res.mp4
ffmpeg -i videob.mp4 -f lavfi -i anullsrc=sample_rate=48000:channel_layout=stereo -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,format=yuv420p,fps=50[v]" -map "[v]" -map 1:a -c:v libx264 -profile:v main -c:a aac -video_track_timescale 50000 -shortest videob2.mp4
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 main.mp4
files.txt
:
file 'main.mp4'
outpoint 3420
file 'videob2.mp4'
在此示例中,outpoint
是主视频持续时间减去结束视频持续时间。ffmpeg -f concat -i files.txt -i main.mp4 -map 0:v -map 1:a -c copy -shortest output.mp4