1

I'm having an issue using the FFmpeg package.

Here's my code :

import ffmpeg_streaming

from ffmpeg_streaming import Formats, Bitrate, Representation, Size

_360p  = Representation(Size(640, 360), Bitrate(276 * 1024, 128 * 1024))
_480p  = Representation(Size(854, 480), Bitrate(750 * 1024, 192 * 1024))
_720p  = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024))

hls = video.hls(Formats.h264())
hls.representations(_360p, _480p, _720p)
hls.output('C:/Users/juled/Videos/testStreaming')

Quite simple as you can see, found it on the web.

And here's the error message I have:

Traceback (most recent call last):
  File "C:\Users\juled\OneDrive\Bureau\PACT\streamingMultimedia\streaming.py", line 50, in <module>
    hls.output('C:/Users/juled/Videos/testStreaming')
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 93, in output
    self.run(ffmpeg_bin, monitor, **options)
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 121, in run
    asyncio.run(self.async_run(ffmpeg_bin, monitor, **options))
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\asyncio\base_events.py", line 583, in run_until_complete
    return future.result()
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 112, in async_run
    self._run(ffmpeg_bin, monitor, **options)
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 105, in _run
    with Process(self, command_builder(ffmpeg_bin, self), monitor, **options) as process:
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_process.py", line 58, in __init__
    self.process = _p_open(commands, **options)
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_process.py", line 29, in _p_open
    return subprocess.Popen(shlex.split(commands), **options)
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

I've been checking every file quoted in the error message, but only one of them is "my" code, the others are FFmpeg and Python libraries codes.

I'm using IDLEX for Python 3.7.6 on Windows by the way.

I've tried to change some of the FFmpeg library code, especially where subprocess.Popen appears, by putting a shell=True in the parameters. New Error Message, different this time.

I've added FFmpeg to the PATH, no change.

I've reinstalled FFmpeg to be sure, but no change. I'm using this version: python-ffmpeg-video-streaming-0.1.14.

Do any of you have a solution I could try ?

Oh and a friend has the same issue on MAC.

Jules Dany
  • 11
  • 1
  • 2
  • Can you do `ffmpeg -version` in your command line, just to be sure it's correctly added to PATH? (based on https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming/issues/30) If not, how about copying ffmpeg to the folder you're running your code in? – K.Cl Apr 07 '21 at 09:00
  • It's weird because it seems it is not correctly installed. C:\>ffmpeg -version 'ffmpeg' is not recognized as an internal or external command, operable program or batch file. – Jules Dany Apr 07 '21 at 09:23
  • Also, I've taken a look at your link and already used the wikihow to install FFmpeg. – Jules Dany Apr 07 '21 at 09:45
  • I've also already tried to add the FFmpeg folder to the working directory, but the same error still appeared. Can try it again though – Jules Dany Apr 07 '21 at 09:45
  • 1
    I mean copy the `ffmpeg.exe` file directly, not its folder. What is your full PATH variable, if you can share it? Did you reset your current terminal session so it updated its environment variables? – K.Cl Apr 07 '21 at 10:13
  • Here's my full PATH variable `C:\ffmpeg\bin\;C:\ffmpeg\bin\;C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\Lib\site-packages\ffmpeg_streaming;` or at least every path that concerns ffmpeg, and it shows C:\ffmpeg\bin\ twice when I do `echo %PATH%` – Jules Dany Apr 07 '21 at 11:17
  • Also, could you tell me where I should copy the .exe ? Is the C:\ folder good ? – Jules Dany Apr 07 '21 at 11:18
  • I now get that `ffmpeg -version ffmpeg version 2021-04-04-git-b1b7cc698b-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.2.0 (Rev6, Built by MSYS2 project)` – Jules Dany Apr 07 '21 at 12:49
  • When I said to copy the ffmpeg.exe, I was thinking of copying to the same directory as the script you're trying to run, but now that you have your console recognizing ffmpeg, does your script run? – K.Cl Apr 07 '21 at 12:56
  • The script still doesn't run and shows the exact same error message – Jules Dany Apr 07 '21 at 13:16
  • Ok I've just did what you said and copied the ffmpeg.exe in the working directory, and now my code runs without any error and does create a .m3u8 file that is readable. – Jules Dany Apr 07 '21 at 13:27
  • No problem. I'll convert this to an answer to close this off – K.Cl Apr 07 '21 at 13:36

1 Answers1

1

This is a PATH environment variable issue. Based on this link, you could try:

import os
path = 'the path you want'
os.environ['PATH'] += ';'+path

to add the path to ffmpeg.exe to your system path (and also to check if your python instance is really looking at the correct path), and you can also change pythonpath,

import sys
sys.path.insert(0,'path/to/ffmpeg')

Note how these two are totally different. However, I find that the easiest way with programs like ffmpeg, which are self-contained executables, that you can just copy them to the working directory of your script and then run it, which is what solved your problem.

K.Cl
  • 1,615
  • 2
  • 9
  • 18