I have a very very very ugly script to merge multiple files of my football games (I have 10 cameras a game) and now I am starting to make highlights of each game. But some of the cameras have different frame rates and use different codecs. So now I am completely at a loss on how to get these working in linux. I would be ok with a GUI or some other video editing software if that is what it would take.
Ugly script (for context)
#!/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
When I do merge the files, the H.265 files play fine, but when it gets to the MP4's it just has the last frame from the H.265 files and audio from the MP4.
error seen when merging
// 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.
I can provide example clips if required :)
0 Answers