如何合并具有不同编解码器的多个视频文件?MP4/H.265

如何合并具有不同编解码器的多个视频文件?MP4/H.265

我有一个非常非常非常丑陋的脚本合并我的足球比赛的多个文件(每场比赛我有 10 个摄像机),现在我开始制作每场比赛的精彩片段。但有些摄像机的帧速率不同,使用不同的编解码器。所以现在我完全不知道如何在 Linux 中让它们工作。如果需要的话,我可以使用 GUI 或其他视频编辑软件。

丑陋的脚本(用于上下文)

#!/bin/bash

#filesList=""
#for file in $(ls -1v *.MP4);do #lists even numbered file
#    filesList="${filesList}${file}|"
#done
#filesList=${filesList%?} # removes trailing pipe
#ffmpeg -i "concat:$filesList" -c copy ../$(date +%Y%m%d_%H%M%S)_merged.mp4
# customize with your own.


simpleCopy(){    
    printf "Would you like to have a thumbnail:\n"
    select answer in Yes No Mkv
    do
        break;
    done
}

checkFolders(){ 
    d=$(zenity  --file-selection --title="Choose a directory and merge all .MP4s inside folder" --directory)
}

simpleCopy
checkFolders

cd "$d"
echo $(pwd)
howManyFolders=$(ls -l -tr "$(pwd)" | grep -c ^d)

if [ $howManyFolders -gt 1 ] 
then
    checkFolders
fi

currentDate=$(date +'%m.%d.%Y_%H.%M')
safeVideoName="${d/ /_}"
safeVideoName="${safeVideoName////}"
echo "safeVideoName: ${safeVideoName}"
videoName="../${safeVideoName}_${currentDate}_merged"


if [ "$answer" = "Yes" ] 
    then
        numberOfVideos=0
        videoFilter=""
        filesList=""
        for file in $(ls -1v | grep -i mp4);do 
            filesList="${filesList} -i ${file}"
            videoFilter="${videoFilter}[${numberOfVideos}:v][${numberOfVideos}:a]"
            
            let "numberOfVideos=numberOfVideos+1"
        done
        echo "videoFilter: ${videoFilter}"
        ffmpeg $filesList -vf "transpose=2,transpose=2,transpose=2" -filter_complex "${videoFilter}concat=n=${numberOfVideos}:v=1:a=1[vv][a];[vv]overlay=main_w-overlay_w-5:main_h-overlay_h-5[v]:" -map "[v]" -map "[a]" ${videoName%/}.mp4
    elif [ "$answer" = "Mkv" ]
    then
        ffmpeg -safe 0 -f concat -i <(find . -type f -name '*.MP4' -printf "file '$PWD/%p'\n" | sort) -c copy ${videoName%/}.mkv
    else
        ls -1v -tr | grep -i mp4 | perl -ne '$_ =~ s/\n$//; print "file '"'"'$_'"'"'\n"' | ffmpeg -safe 0 -protocol_whitelist file,tcp,http,pipe -f concat -i - -c copy "${videoName%/}.mp4"
fi

当我合并文件时,H.265 文件播放正常,但当转换为 MP4 时,它只包含 H.265 文件的最后一帧和 MP4 中的音频。

合并时出现错误

// cmd -         echo ls -1v -tr | grep -i mp4 | perl -ne '$_ =~ s/\n$//; print "file '"'"'$_'"'"'\n"' | ffmpeg -safe 0 -protocol_whitelist file,tcp,http,pipe -f concat -i - -c copy "${videoName%/}.mp4"

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55f528e4d3c0] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x55f528e4fb40] Non-monotonous DTS in output stream 0:1; previous: 655360, current: 626560; changing to 655361. This may result in incorrect timestamps in the output file.
[concat @ 0x55f528e436c0] DTS 1116270 < 1167534 out of order
[mp4 @ 0x55f528e4fb40] Non-monotonous DTS in output stream 0:0; previous: 1226574, current: 1175310; changing to 1226575. This may result in incorrect timestamps in the output file.
[mp4 @ 0x55f528e4fb40] Non-monotonous DTS in output stream 0:1; previous: 655361, current: 627584; changing to 655362. This may result in incorrect timestamps in the output file.
[mp4 @ 0x55f528e4fb40] Non-monotonous DTS in output stream 0:0; previous: 1226575, current: 1178313; changing to 1226576. This may result in incorrect timestamps in the output file.
[mp4 @ 0x55f528e4fb40] Non-monotonous DTS in output stream 0:1; previous: 655362, current: 628608; changing to 655363. This may result in incorrect timestamps in the output file.

在此处输入图片描述

如果需要,我可以提供示例剪辑:)

相关内容