Skip to content

Instantly share code, notes, and snippets.

@priintpar
Last active February 5, 2025 01:51
Show Gist options
  • Save priintpar/f7a56af8977206e9f45b486f767b02ac to your computer and use it in GitHub Desktop.
Save priintpar/f7a56af8977206e9f45b486f767b02ac to your computer and use it in GitHub Desktop.
Convert many .media files created by security cameras and babyphones to a single .mkv file using ffmpeg on Macos or Linux. Even skips defective files.
find . -type f -name '*media' >> unsortedlist.txt
sort unsortedlist.txt >> sortedlist.txt
while read line; do ffprobe $line; if [ $? = "1" ]; then echo $line; fi; done < sortedlist.txt >> corruptfiles.txt
awk 'NR==FNR{a[$0];next} !($0 in a)' corruptfiles.txt sortedlist.txt > temp; mv temp sortedlist.txt
while read line; do echo "file '$line'"; done < sortedlist.txt >> sortedlistwithoutcorruptfiles.txt
ffmpeg -f concat -safe 0 -i sortedlistwithoutcorruptfiles.txt -c copy outputvideo.mkv
rm unsortedlist.txt sortedlist.txt sortedlistwithoutcorruptfiles.txt corruptfiles.txt
@Gast114
Copy link

Gast114 commented Nov 19, 2023

I'm curious if you were actually able to convert the .media file while retaining the audio, and if you could send it back to me. If this works, I would consider borrowing a Mac to perform the conversions instead of purchasing one.

@Darex1991
Copy link

Video link is not working for me. There is player but without video

@sambul13
Copy link

sambul13 commented Feb 5, 2025

The convertion code doesn't work when embedded audio is encoded in NHNT format typical for cloud cameras, but not usually recognised by default config ffprobe.

You need to buy mac

Irrelevant for this error. Further, the code purges present in the media folder structure "non-media" files with audio codec info, and fails to identify in the targeted day folder structure correct start & sequence & stop fragments belonging to the same motion event video. Too simplistic to be universally useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment