Apply multiple text filters at once and burn into video for captioning without re-encoding, and fix error [ffmpeg-python wrapper]
18:39 12 May 2025

Is there any way to burn text into a video without re-encoding? I ask this because the re-encoding process goes at around 0.1x speed on my device when writing to WEBM. Alternatively, if there is a faster way to render high quality video quickly while still re-encoding that would be great. I vaguely remember someone writing to a temporary file to solve this problem.

Also small error in program, code attatched

def processVideo(self):
    print("creating video")

    # File location management
    font_path = self.input_path / "CalSans-Regular.ttf"
    background_path = self.input_path / "new_video_background.webm"
    audio_path = self.sound_output_path
    video_ouput_path = self.parent_path / "new_result.webm"
    sound_input = ffmpeg.input(str(audio_path))
    video_input = ffmpeg.input(str(background_path))

    # Adding captions
    print(self.text_caption)
    previous_timepoint = 0
    for caption, timepoint in zip(self.text_caption, self.timepoints, strict=False): 
        # Text caption and timepooints are lists where the end of the words in text_caption correspond
        # to the timepoint with the same index in timepoint
        video_input = video_input.drawtext(
                                            text=caption, 
                                            fontfile = font_path, 
                                            x='w-text_w/2', 
                                            y='h-text_h/2', 
                                            escape_text=True, 
                                            fontsize= 32,
                                            bordercolor = "black",
                                            borderw = 4,
                                            enable=f'between(t,{previous_timepoint},{timepoint["timeSeconds"]})'
                                            )
        previous_timepoint = timepoint["timeSeconds"]
        
    # Combining sound and video and writing output
    command = ffmpeg.output(sound_input, video_input, str(video_ouput_path), codec='copy').overwrite_output().global_args('-shortest')
    print("args =", command)
    print(command.get_args())
    command.run()
    print("done!")
  File "c:\Desktop\Projects\video_project\main.py", line 239, in 
    post_list[0].processVideo()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "c:\Desktop\Projects\video_project\main.py", line 223, in processVideo
    command.run()
    ~~~~~~~~~~~^^
  File "C:\Desktop\Projects\video_project\.venv\Lib\site-packages\ffmpeg\_run.py", line 313, in run
    process = run_async(
        stream_spec,
    ...<5 lines>...
        overwrite_output=overwrite_output,
    )
  File "C:\Desktop\Projects\video_project\.venv\Lib\site-packages\ffmpeg\_run.py", line 284, in run_async
    return subprocess.Popen(
           ~~~~~~~~~~~~~~~~^
        args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 1038, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        pass_fds, cwd, env,
                        ^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
                        gid, gids, uid, umask,
                        ^^^^^^^^^^^^^^^^^^^^^^
                        start_new_session, process_group)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 1550, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
                             # no special security
                             ^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
                             cwd,
                             ^^^^
                             startupinfo)
                             ^^^^^^^^^^^^
FileNotFoundError: [WinError 206] The filename or extension is too long
python ffmpeg