Skip to content

Instantly share code, notes, and snippets.

@jhodges10
Last active January 21, 2020 01:28
Show Gist options
  • Save jhodges10/1c271b25a6888c1fa242c1265b700f9e to your computer and use it in GitHub Desktop.
Save jhodges10/1c271b25a6888c1fa242c1265b700f9e to your computer and use it in GitHub Desktop.
def merge_slate_with_video(slate_path, video_path):
# Process w/ FFMPEG
with open("output.log", "a") as output:
# Generate intermediate transport streams to prevent re-encoding of h.264
print("Generating intermediate1.ts")
subprocess.call(
"""docker run -v $(pwd):$(pwd) -w $(pwd) jrottenberg/ffmpeg:3.2-scratch -y -i '{}' -c copy -bsf:v h264_mp4toannexb -f mpegts ./temp/intermediate1.ts""".format(slate_path),
shell=True, stdout=output, stderr=output
)
print("Done Generating intermediate1.ts")
print("Creating intermediate2.ts")
subprocess.call(
"""docker run -v $(pwd):$(pwd) -w $(pwd) jrottenberg/ffmpeg:3.2-scratch -y -i ./temp/temp_black.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts ./temp/intermediate2.ts""",
shell=True, stdout=output, stderr=output
)
print("Done Generating intermediate2.ts")
print("Creating intermediate3.ts")
subprocess.call(
"""docker run -v $(pwd):$(pwd) -w $(pwd) jrottenberg/ffmpeg:3.2-scratch -y -i '{}' -c copy -bsf:v h264_mp4toannexb -f mpegts ./temp/intermediate3.ts""".format(video_path),
shell=True, stdout=output, stderr=output
)
print("Done Generating intermediate3.ts")
print("Beginning merge...")
# Merge together transport streams
subprocess.call(
"""docker run -v $(pwd):$(pwd) -w $(pwd) jrottenberg/ffmpeg:3.2-scratch -y -i 'concat:./temp/intermediate1.ts|./temp/intermediate2.ts|./temp/intermediate3.ts' -c copy -bsf:a aac_adtstoasc ./temp/slated_output.mp4""",
shell=True, stdout=output, stderr=output
)
print("Merge completed... Ready to upload!")
return "temp/slated_output.mp4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment