Including ffmpeg in Django project - python

I am making a very simple Django app (it's a test for non-Django course) and I need to analyse a mp3 file in there, so I try to turn it into wav with this:
sound = AudioSegment.from_mp3('upload/' + filename)
sound.export('upload/wavfile', format="wav")
rate, data = wav.read('upload/wavfile')
I have installed ffmpeg by pip install ffmpeg in venv terminal, since I want to my code to run not only on my machine. The ffmpeg and ffprobe folders have appeared in /venv/lib/python3.7/site-packages/ however when I run my server I get the warning:
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg,
but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
and when I load file in web page it throws
[Errno 2] No such file or directory: 'ffprobe': 'ffprobe'
at the first line of the code above.
I would really appreciate any help with how I can use ffmpeg in my app or other ways to handle my mp3 file.

You have to add path for ffmpeg executable
import sys
sys.path.append('/path/to/ffmpeg')
or
import ffmpy
ff = ffmpy.FFmpeg(executable='C:\\ffmpeg\\bin\\ffmpeg.exe', inputs={path+'/Stage1Rap.wav': None}, outputs={path+'/FinalRap.mp3': ["-filter:a", "atempo=0.5"]})
ff.run()

Related

subprocess.call can't find file/shutil.which failed in pycharm

I am trying to transform a mp3 to a wav file in pycharm using subprocess
import subprocess
subprocess.call(['ffmpeg', '-i','test.mp3','test.wav'])
It returns error of not finding file, so I change the 'ffmpeg' to its path on my pc and it work.
The problem is that I am making an app and others might install ffpmeg on other's location (since it is download with zip and can be unzip at any place), but I don't know how to get its full path.
I tried using os module
import os
print(os.path('ffmpeg.exe'))
but it seems like it is not able to get the path of exe
Traceback (most recent call last):
File "C:\Users\Percy\PycharmProjects\APP\test3.py", line 8, in <module>
print(os.path('ffmpeg.exe'))
TypeError: 'module' object is not callable
I also tried shutil module
import shutil
print(shutil.which('ffmpeg'))
print(shutil.which('ffmpeg.exe'))
but it returns 2 None (prob wrong cause I am 100% sure I have installed ffmpeg)
None
None
I want to ask if there is any way to get the full path of ffmpeg in pycharm or any method that I can make ffmpeg install in designated path with the app when it is downloaded by users
If you can make "everyone" to install using my ffmpeg-downloader then all of you can install FFmpeg by:
pip install ffmpeg-downloader
ffdl install
Then in Python your package could use
import ffmpeg_downloader as ffdl
sp.run([ffdl.ffmpeg_path, '-i', 'input.mp4', 'output.mkv'])
Alternately, you can use static-ffmpeg to (dynamically) install FFmpeg to Lib/site-package. (See the linked GitHub page for howto.)

/usr/local/bin/conver cannot find error on imagemagic for movie.py

I want use moviepy so, I checking example snippets from official moviepy web site.
I installed all requirements and When I try to run moviepy on jupyter notebook, I get this error:
Code :
txt_clip = TextClip("My Holidays 2013",fontsize=70,color='white')
Error :
OSError: MoviePy Error: creation of None failed because of the following error:
[Errno 2] No such file or directory: '/usr/local/bin/convert'.
This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
My os : M1 BigSur 11.2.3 - MacOS
Also I checked
ls /opt/homebrew/opt
ls /usr/local/Cellar
ls -l /usr/local/opt/
But I cannot find anything about "convert"
Btw I can user imagemagic convert from terminal like that:
magick convert
output is like that:
Version: ImageMagick 7.0.11-7 Q16 arm 2021-04-12 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(4.5)
Delegates (built-in): bzlib freetype gslib heic jng jp2 jpeg lcms lqr ltdl lzma openexr png ps tiff webp xml zlib
Usage: convert [options ...] file [ [options ...] file ...] [options ...] file
Image Settings:
-adjoin join images into a single multi-image file
-affine matrix affine transform matrix
-alpha option activate, deactivate, reset, or set the alpha channel
-antialias remove pixel-aliasing
How can solve this? Any tip or solution?
I solved this error.
I checked my PATH
echo $PATH
After that, I checked path folders and I find 'convert' from /opt/homebrew/bin/convert
After that I copied this file to /usr/local/bin/
So,
sudo cp /opt/homebrew/bin/convert /usr/local/bin/
solved my issue.

pyshark.tshark.tshark.TSharkNotFoundException: TShark not found

I am trying to run below code using pyshark on MACOX Catlina , when I run it I get the below exception (Also I ran below program using sudo ,incase if it was issue due to permission,but gives me same error)
"Searched these paths: {}".format(possible_paths)
pyshark.tshark.tshark.TSharkNotFoundException: TShark not found. Try adding its location to the configuration file. Searched these paths: ['C:\\Program Files\\Wireshark\\dumpcap.exe', '/usr/local/bin/dumpcap', '/usr/bin/dumpcap', '/bin/dumpcap', '/usr/sbin/dumpcap', '/sbin/dumpcap', '/opt/X11/bin/dumpcap']
import pyshark
class SniffPacket(object):
def __init__(self):
self.sniff()
def sniff(self):
capture = pyshark.LiveCapture(interface='en0')
capture.sniff(timeout=10)
if __name__ == '__main__':
s = SniffPacket()
I already have wireshark installed . Any help is appreciated . Is it because pyshark doesn't work on Mac ?
Open config.ini file and change the tshark path to the path where your tshark.exe is located. (Worked for Windows)
If this doesn't work try changing the dumpcap path also to the location where dumpcap.exe is stored.
I had the same issue [Windows 11]. For me it was Wireshark not being installed along with the associated Tshark requirements/files. After doing the wireshark install with the associate thsark files [it was an option in the installed exe) everything snapped into place.
Get the latest Wirehsark install =
https://www.wireshark.org/download.html
Help with TShark =
https://tshark.dev/setup/install/

python error lib dont execute the library

Before enter data, I import a lib, but this lib give an error like this /
Warning (from warnings module): File
"C:\Users\Samuel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py",
line 165
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning) RuntimeWarning: Couldn't find ffmpeg or
avconv - defaulting to ffmpeg, but may not work
Warning (from warnings module): File
"C:\Users\Samuel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py",
line 179
warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning) RuntimeWarning: Couldn't find ffplay or
avplay - defaulting to ffplay, but may not work
TL;DR: As the source code indicates, you should install ffmpeg add it to your %PATH%. Since ffplay comes with ffmpeg, this should solve your problem.
You can install ffmpeg here: http://ffmpeg.org/
After installation, you can open your control panel, and then search environment. There you can adjust your %PATH% variable. Add the ffmpeg installation's binary path to the %PATH%.
And here's why from source code:
def get_encoder_name():
"""
Return enconder default application for system, either avconv or ffmpeg
"""
if which("avconv"):
return "avconv"
elif which("ffmpeg"):
return "ffmpeg"
else:
# should raise exception
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
return "ffmpeg"
def get_player_name():
"""
Return enconder default application for system, either avconv or ffmpeg
"""
if which("avplay"):
return "avplay"
elif which("ffplay"):
return "ffplay"
else:
# should raise exception
warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning)
return "ffplay"
def which(program):
"""
Mimics behavior of UNIX which command.
"""
# Add .exe program extension for windows support
if os.name == "nt" and not program.endswith(".exe"):
program += ".exe"
envdir_list = [os.curdir] + os.environ["PATH"].split(os.pathsep)
for envdir in envdir_list:
program_path = os.path.join(envdir, program)
if os.path.isfile(program_path) and os.access(program_path, os.X_OK):
return program_path
From this we can know that it looks up those programs from your environment variable %PATH%. And that's why installing those softwares and adding them to your %PATH% should solve the problem.

pip fails to install PIL or Pillow with mt.exe error

On one of my Windows 7 development machines, I am attempting to install the Python Image Library.
My machines are similar. Both run Windows 7 Professional, x64. Both use Python 2.7.3 (32bit). On one of the machine pip install PIL works fine. On the other it fails with the trace ending with this:
build\temp.win-amd64-2.7\Release\_imaging.pyd.manifest : general error c1010070:
Failed to load and parse the manifest. The system cannot find the file specified.
error: command 'mt.exe' failed with exit status 31
How can I resolve this error?
Thanks to http://bugs.python.org/issue4431, this error was fixed by modifying:
C:\<Python dir>\Lib\distutils\msvc9compiler.py
and adding:
ld_args.append('/MANIFEST')
after the MANIFESTFILE line so it looks like:
# Embedded manifests are recommended - see MSDN article titled
# "How to: Embed a Manifest Inside a C/C++ Application"
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
# Ask the linker to generate the manifest in the temp dir, so
# we can embed it later.
temp_manifest = os.path.join(
build_temp,
os.path.basename(output_filename) + ".manifest")
ld_args.append('/MANIFESTFILE:' + temp_manifest)
ld_args.append('/MANIFEST')
If you still get the error, then change the if arg.startswith("/MANIFESTFILE:") to if arg.startswith("/MANIFEST:") in the manifest_get_embed_info(self, target_desc, ld_args) method.
Download the compressed package from pypi, and try building and installing in your machine. This link could give you some hints. That exactly deals with your problem only but the installation varies.
If you've reached here looking for
general error c1010070:
Failed to load and parse the manifest. The system cannot find the file specified.
error: command 'mt.exe' failed with exit status 31
Here's a workaround that worked in Windows 8/x64/Python 3.3/VS 11:
# py 3.3 seems to be compiled against VS 2010 compiler, force using VS11 cl.exe for us
$env:VS100COMNTOOLS=$env:VS110COMNTOOLS
# Modify C:\Python33\lib\distutils\msvc9compiler.py
# Comment line 670: ld_args.append('/MANIFESTFILE:' + temp_manifest)
# Basically it will instruct build to not look for manifest file

Categories