question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError: No ffmpeg exe could be found.

See original GitHub issue

When using imageio to read youtube videos in python as shown below:

import cv2
import imageio
from pytube import YouTube
import numpy as np


def car_detection(url, frame_gap, initial_path, name):
    cars_classifier = cv2.CascadeClassifier(
        'cars.xml')
    yt = YouTube(url)
    stream = yt.streams.filter(file_extension='mp4').first()
    stream.download(output_path=initial_path, filename=name)
    path = initial_path
    path += '/'
    path += name
    path += '.mp4'

    reader = imageio.get_reader(path)
    frame_number_counter = 0
    traffic_density_values = []
    for frame in reader:
        frame_number_counter = frame_number_counter + 1
        if frame is not None:
            if frame_number_counter == 1 or frame_number_counter % frame_gap == 0:
                blur = cv2.blur(np.float32(frame), (3, 3))
                gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
                gray = np.array(gray, dtype='uint8')
                cars = cars_classifier.detectMultiScale(gray)
                count = 0
                for (x, y, w, h) in cars:
                    count = count + 1
                traffic_density_values.append(count)
                key = cv2.waitKey(1)
                if key == 27:
                    break
        else:
            break
    print(traffic_density_values)
    return traffic_density_values

I receive the following error in my android studio logcat:

2021-01-23 01:13:34.022 22417-22570/Brian.Okoth.trafficapp E/AndroidRuntime: FATAL EXCEPTION: Thread-2
    Process: Brian.Okoth.trafficapp, PID: 22417
    com.chaquo.python.PyException: RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
        at <python>.imageio_ffmpeg._utils.get_ffmpeg_exe(_utils.py:49)
        at <python>.imageio_ffmpeg._io._get_exe(_io.py:19)
        at <python>.imageio_ffmpeg._io.read_frames(_io.py:140)
        at <python>.imageio.plugins.ffmpeg._initialize(ffmpeg.py:468)
        at <python>.imageio.plugins.ffmpeg._open(ffmpeg.py:323)
        at <python>.imageio.core.format.__init__(format.py:221)
        at <python>.imageio.core.format.get_reader(format.py:170)
        at <python>.imageio.core.functions.get_reader(functions.py:186)
        at <python>.car_detection_and_counter_python_script.car_detection(car_detection_and_counter_python_script.py:18)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:380)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:352)
        at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)
        at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:221)
        at com.example.trafficapp.car_detection_thread.run(car_detection_thread.java:46)

However, the python code works just fine on my pc. The error only occurs when i try to run the script with chaquopy. How can i install ffmpeg on my system, or set the IMAGEIO_FFMPEG_EXE environment variable? Below are the installed packages in build.gradle:

pip {
                install "sklearn"
                install "pandas"
                install "opencv-python"
                install "pytube==10.4.1"
                install "imageio"
                install "imageio-ffmpeg"
                install "numpy"
                install "ffmpeg"
                install "ffmpeg-python"

            }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Brokothcommented, Aug 5, 2021

@ashnaeldho Using chaquopy, send the path of the video on your phone to the python code.

 if (!Python.isStarted())
     Python.start(new AndroidPlatform(c));
 Python python = Python.getInstance();
 PyObject pyObj = python.getModule("python_script");
 PyObject returnedData = pyObj.callAttr(path);

You can use this method to get the root path:

String path = YourActivity.this.getFilesDir().toString()

Concatenate the remainder of the video’s path at the end of the path variable. Then you can refer to the python code above to see how you would handle the parameters you passed.

0reactions
ashnaeldhocommented, Aug 5, 2021

Hi,

I’m new to android studio. I want to develop an android app which can do motion detection. The motion detection algorithm is in python. So, my question is, if I want to use mobile-ffmpeg to convert video to frames and then do motion detection (planning to use some of the python codes above for getting frames), how can i pass the video to this python code? The video loading portion is done on Java.

I know chaquopy can be used for the communication between java and python, but I don’t know how to pass video to the python code above.

If someone knows the answer, can you please help me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: No ffmpeg exe could be found. Install ... - GitHub
RuntimeError : No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable. #1158.
Read more >
No ffmpeg exe could be found - FFMpeg error in Windows 10
RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
Read more >
FFMpeg installation (Newbie question) : r/moviepy - Reddit
RuntimeError : No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable. Thanks!
Read more >
Linux/MacOS 报错No ffmpeg exe could be found. Install ...
ERROR: Cannot uninstall 'imageio'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which ...
Read more >
macos - Install FFmpeg on OS X - Super User
I have Xcode installed as well as the CLI for Xcode ( gcc etc). I have a version of FFmpeg currently installed, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found