Passing an uploaded video file into an FFmpeg function


I have a working function that embeds a subtitle file into a video file using Python and FFmpeg. I would like to use that function within a streamlit app with files uploaded via st.file_uploader. When I try to run the process via an st.button, I get an error. I am new to streamlit. I was expecting to just pass the uploaded files from a variable to my function, but I must be missing a step in between.

Code snippet:

import ffmpeg
import streamlit as st

st.title("Caption Embedder")

video_filename = st.sidebar.file_uploader("Choose a video file", type=["mov", "mp4"])
if video_filename is not None:
sub_filename = st.sidebar.file_uploader("Choose a caption file", type=["srt", "txt"])
if sub_filename is not None:
start_button = st.sidebar.button("Start")

def embed_srt(video_filename, sub_filename):
    video = ffmpeg.input(video_filename)
    audio =
    ffmpeg.concat(video.filter("subtitles", sub_filename), audio, v=1, a=1).output(video_filename + "output.mp4").run()

if start_button:
    embed_srt(video_filename, sub_filename)

Expected behavior:
A new video file is output that has the subtitles embedded in the the original file.

Actual behavior:
TypeError: unsupported operand type(s) for +: ‘UploadedFile’ and ‘str’

Debug info

  • Streamlit version: 1.17.0
  • Python version: 3.11.1
  • OS version: macOS 11.7
  • Browser version: Safari