How to Run FFmpeg in a Python Step Without Local Installation and No Access to Apt-Get or Pip?

This topic was automatically generated from Slack. You can find the original thread here.

I’ve been banging my head on this for hours and searching the slack isn’t helpful at all…

I’m trying to run ffmpeg inside a python step and I dont have it install locally…many suggestions have suggested to apt-get install it or pip install but the process cannot find neither pip nor apt-get…anyone have any ideas?

My suggestion is you can try to download the ffmpeg executable for amd64 platform in your python code, then try to use it in the same python code.

there’s no way to just install a package?

tried it and it can’t seem to download and unzip the tarball locally

Ffmpeg is a command line tool, so you need to install it as commandline tool. One way to do that is just download the executable.

About the unzip issue, I think this is not a Pipedream issue and you can search through the internet or ask LLM tools for debuging.

I afraid I can not help further without much information on the error you’re facing.

One day Pipedream will support BYOC (custom container images).

Then we’ll be able to do whatever we want.

In case it helps, ffmpeg seems to work in Node.js code steps. For example:

import fs from "fs";
import stream from "stream";
import { promisify } from "util";
import { exec as childProcessExec } from "child_process";
import { path } from "@ffmpeg-installer/ffmpeg";

export default {
  props: {
    videoUrl: {
      type: "string"
    },
    filename: {
      type: "string"
    },
    subtitlesFileUrl: {
      type: "string"
    }
  },
  async run({ steps, $ }) {
    const { default: got } = await import("got");

    // This code downloads the video file to the /tmp directory
    const f = `/tmp/${this.filename}`
    const pipeline = promisify(stream.pipeline);
    await pipeline(
      got.stream(this.videoUrl),
      fs.createWriteStream(f)
    );

    // This code downloads the subtitles file to the /tmp directory
    const subFile = `/tmp/subtitles-en.vtt`
    await pipeline(
      got.stream(this.subtitlesFileUrl),
      fs.createWriteStream(subFile)
    );

    // Get file info
    const ffmpegPath = path;
    const exec = promisify(childProcessExec);
    return await exec(`${ffmpegPath} -i ${f} -i ${subFile} -codec:v "copy" -codec:a "copy" -codec:s "mov_text" -metadata:s:s:0 'language=eng' -f "mp4" -movflags "+faststart" /tmp/video.avi`);
  }
};

You could potentially use a Node.js step to run ffmpeg and use Python for the rest of the workflow. Or Pi might be able to convert your Python step to Node.js.

hey guys, so I figured out how to get ffmpeg to work in python…

Want to get this on the record as I’m sure that people will be looking for it at some point. maybe worth tagging here as well.

At the top of my script I added these comments:

# pipedream add-package imageio-ffmpeg
# pipedream add-package imageio

Turns out you can add external Pypi libs but it must be done in this notation. It was buried in the docs but I managed to get it to work.

This will work for any external library.

To get ffmpeg working in Python on Pipedream, you can use the imageio-ffmpeg and imageio packages. Here’s how you can do it: At the top of your Python script, add the following magic comments to ensure the necessary packages are installed: ```

pipedream add-package imageio-ffmpeg # pipedream add-package imageio

``` These comments will instruct Pipedream to install the imageio-ffmpeg and imageio packages, which are necessary for working with ffmpeg in Python. This approach is useful for anyone looking to use ffmpeg in their Pipedream workflows. If you have any further questions or need additional support, feel free to visit Pipedream Support.