Created
June 12, 2019 18:55
-
-
Save NazmusShakib/276642449d04f0da43ad419c7aa07c25 to your computer and use it in GitHub Desktop.
ffmpeg: merge multiple MP4 files, it's necessary to pass by .ts files
This file contains hidden or 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
import os | |
import subprocess | |
import glob | |
def main(): | |
tsFileList = [] | |
# consider only .mp4 files | |
files = glob.glob('*.mp4') | |
for file in files: | |
# file transcode to MPEG-2 TS | |
subprocess.call(['ffmpeg', '-i', file, '-c', 'copy', '-bsf:v', 'h264_mp4toannexb', '-f', 'mpegts', file+'.ts']) | |
tsFileList.append(file+'.ts') | |
process(tsFileList) | |
def process(tsFileList): | |
input = '' | |
for eachfile in tsFileList: | |
input += eachfile + '|' | |
# concatenation | |
subprocess.call(['ffmpeg', '-i', 'concat:' + input, '-c', 'copy', '-bsf:a', 'aac_adtstoasc', 'output.mp4']) | |
# remove all .ts files | |
for eachfile in tsFileList: | |
os.remove(eachfile) | |
print("done!") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment