3

I am relatively new to python, I am working on extracting some metadata from a video and I am trying to use ffmpeg.probe (or ffprobe) because it provides all the data I need.

After many errors I went to the basic and tried:

import ffmpeg
import json

movie_path="E:\Archive\Peliculas\Clasicos\Casablanca.avi"
probe = ffmpeg.probe(movie_path)

The error that I get is:

Traceback (most recent call last):
  File "C:\Users\xxx\Desktop\test.py", line 5, in <module>
    probe = ffmpeg.probe(movie_path)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python310\lib\site-packages\ffmpeg\_probe.py", line 20, in probe
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

I have been searching around and tried installing and uninstalling ffmpeg, ffmpeg-python, installing it directly on windows (adding the files to the path so that I can run it in the console). Then tried to do it on my own using the _probe.py as example:

p = subprocess.Popen(['ffprobe', '-show_format', '-show_streams', '-of', 'json', 'E:\Archive\Peliculas\Clasicos\Casablanca.avi'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) #shell=True is not present in _probe.py  but it wont run otherwise
out, err = p.communicate()

The error returned is: b'"ffprobe" is not recognized as an internal or external command, \r\n program, or executable batch file.\r\n' but runs, it is not the "FileNotFoundError"

When I run it in cmd there is no issue, ffprobe -show_format -show_streams -of json E:\Archive\Peliculas\Clasicos\Casablanca.avi provides the information (with a couple of lines before the JSON but works).

I don't know if it is a windows thing (I have tried both \ and \\ already with no apparent difference) or I am doing wrong.

martineau
  • 119,623
  • 25
  • 170
  • 301
Skurian25
  • 31
  • 1
  • 3

4 Answers4

2

try to use r mark, like this:

movie_path=r"E:\Archive\Peliculas\Clasicos\Casablanca.avi"

This marker is a 'raw string literal', which are exactly the string literals marked by an 'r', before the opening quote and resolves this issues with \ backslash.

Jolitos
  • 41
  • 6
  • 1
    The **r** is called a "string prefix" — see the [documention](https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals). – martineau Dec 10 '21 at 20:59
  • Thanks for the tip, I tried and it works, I will note the **r** for issues with strings. But I just tried out of curiosity without the r again and it worked. It might be that the install of ffmpeg was just missing a reboot of mi PC. Thanks for the support! – Skurian25 Dec 11 '21 at 16:52
0

Turns out that when I came in the next day it worked fine. I think I was just missing to reboot after installing ffmpeg (hadn't have that happen with any of the other packages installed with pip before).

Skurian25
  • 31
  • 1
  • 3
0

You should have "ffprobe.exe" in the directory (just "ffmpeg.exe" isn't enough). It solved the issue for me.

Harel Brodai
  • 71
  • 1
  • 7
0

For this to work, you need an FFmpeg version installed on your system and added to your PATH environment variable.

This is a short description of how I did it on windows and got it to work:

  1. Download the ffmpeg-release-full.7z binary from here

  2. Unpack the archive and move it to your desired install location. Personally, I moved the unpacked folder to C:\ffmpeg\

  3. Add the bin subfolder of your new directory to your PATH environment variable. In my case, I had to add C:\ffmpeg\ffmpeg-5.1.2-full_build\bin

  4. The shell environment your python distribution is using now has to be restarted, for the environment variable change to come into effect. If you are not sure how to do this, just restart your pc.

GWD
  • 3,081
  • 14
  • 30