I bought a Xiaomi camera, with 32GB microSD, it can record about 10 days, but it saves data to many folders, per folder has many files, the length of file less than 60 seconds. When I backup data from microSD to hard disk, it is difficult to watch because I must open file many many time.
So, I want to merge all file in the folder to one file and upload to youtube to easy to access. I have to code something.
The first, I install FFmpeg to my Mac, it is not easy as installing FFmpeg on Ubuntu, but I did. That’s ok, FFmpeg saves my life :p. This is my code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|list = os.listdir(path)|
|base_path = "/Users/phihongthai/Documents/Yicam/"|
|def create_file(list, path):|
|file_path = path + "ffmpeg-sound.txt"|
|with open(file_path, "w") as f:|
|for file in list:|
|f.write("file " + file + "\n")|
|list_dir = list_file(base_path)|
|for dir in list_dir:|
|if not str(dir).startswith("."):|
|path = base_path + dir + "/"|
|#get list file mp4 in folder|
|list = list_file(path)|
|#write list file mp4 to a txt file|
|out_name = dir + ".mp4"|
|cmd = "/usr/local/bin/ffmpeg -f concat -i ffmpeg-sound.txt -c copy " + out_name|
|cmd1 = "cd " + path + " && " + cmd + " && mv " + out_name + " ../"|
|#run command to merge files to a file|
|#call API to upload to youtube|