I am attempting to call ffmpeg to create an image from a frame in a video, I am using python to do this with subprocess.Popen on a mac, eventually this will move to a unix server.
I can successfully create a video from the command line with this line
ffmpeg -i /Users/bimemployee/Movies/ski\ commute.m4v -r .5 -vframes 1 -ss 00:01:14 /Users/bimemployee/Movies/untitled\ folder/image-%d.jpeg
I then turn this into a python iterable and passed it Popen
s=["ffmpeg","-i","Users/bimemployee/Movies/ski\ commute.m4v","-r","1","-vframes","1","-ss","00:01:14","/Users/bimemployee/Movies/untitled\ folder/image-%d.jpeg"]
subprocess.Popen(s)
When I do so I get the standard info screen from ffmpeg and an error that says Users/bimemployee/Movies/ski\ commute.m4v: No such file or directory
Why would this path work ok from the command line but not from python?
Secondly is their a better library for handling this, the ones I could find don't seem to be active projects or don't work with straight python but require things like cython.
Thanks,
CG
You're missing the opening forward slash:
/Users/bimemployee/Movies/ski_commute.m4v
is not the same as
Users/bimemployee/Movies/ski_commute.m4v
Related
I am trying to use python to convert files from mp4 to mp3. After some research most places recommend moviepy. I used the command pip install moviepy and it seemed to go off without a hitch. I go to VS Code and enter what a youtube video told me to enter (I know its not recommended to do that, I just wanted to see if it would work). This is what I have
`
#This code should convert a .mp4 file into a .mp3 file
#This imports the moviepy package
from moviepy.editor import *
#here are the names of my files (I have subbed out actual files names)
mp4_file = "file_name.mp4"
mp3_file = "file_name.mp3
#Here is the the audio being stripped from the .mp4 file
video_clip = VideoFileClip(mp4_file)
audio_clip = video_clip.audio
#this is writing the audio to a .mp3 file at the path that is specified.
audio_clip.write_audiofile(mp3_file)
#this closes the conversion code
audio_clip.close()
VideoClip.close()
`
After running the code I get this error:
RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
There is a bunch of gibberish above it but that is the final line that gets spit out.
After looking up what the issue is I tried to input:
`
from moviepy.config import change_settings
change_settings({"FFMPEG_BINARY": "/usr/bin/ffmpeg"})
`
And it also did not work. I have tried searching for where ffmpeg is and it is not in /usr/bin/ffmepg or /usr/local/bin/ffmpeg like most sources I have looked at tell me it should be.
I have tried installing ffmpeg on its own by doing pip install ffmpeg and 'brew install ffmpeg'. Both of those go off without a hitch as well but the error still pops.
I am using a macbook air m1 and I have I think everything I need installed already so I am so lost on what is causing this error to pop.
Can someone please help?
I have tried installing ffmpeg on its own as well as searching for the file directly.
I should expect to get the .py file to run fine.
I instead get the error seen above:
RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
try to use this code which is i got
import moviepy.editor
import os
os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg"
mp4_file = "file_name.mp4"
mp3_file = "file_name.mp3"
# Replace the parameter with the location of the video
video = moviepy.editor.VideoFileClip("mp4_file")
audio = video.audio
# Replace the parameter with the location along with filename
audio.write_audiofile("mp3_file")
if it is still not find the ffmpeg then find its actual path and note that
I'm trying to convert a video between two file types, when run, nothing happens and no file is made. I've tried doing it with subprocess and os - both have the same result - nothing.
I can do the command fine through shell. I really want to be able to use this through python.
import subprocess
command = "ffmpeg -i X:/Desktop/twd.mp4 X:/Desktop/twd.mp3"
subprocess.run(command.split(),shell=True)
nothing happens and no file is made
This is very strange. Absolutely no text printed on console? I agree #Rotem's suggestion, but at the minimum the version info should print on your console (assuming you are using one of prebuilt binaries). BTW, shell=True is not needed and not recommended.
If you wish, you can give my ffmpegio package a try, it might make your life a bit easier.
import ffmpegio
ffmpegio.transcode('X:/Desktop/twd.mp4','X:/Desktop/twd.mp3')
It should auto detect your ffmpeg binaries and run your example above.
I'm trying to convert one of my CCTV RTSP streams to RTMP so I can add it onto a website. I've read many articles and understand that ffmpeg for Ubuntu 18.04 is the way to go.
I my script I've added the following code into Python 3.7:
ffmpeg -i "rtsp://xx.xxx.xx.x:554/user=admin&password=123#&channel=1&stream=0.sdp" -f flv -r 25 -s 640x480 -an "rtmp://localhost:1935/uid/1/camera1"
but I get a syntax error in the quote mark at the end of the first link (rtsp link) I've searched for hours and can't see what anyone has mentioned this before. I've also reviewed the ffmpeg documentation and can't see any issues.
Please can anyone point me in the right direction?
Thanks
Chris
According to the comment, you can't do it like this, since you can't directly execute commands from Python.
The simplest way to do it is by using os.system:
import os
os.system('ffmpeg -i "rtsp://xx.xxx.xx.x:554/user=admin&password=123#&channel=1&stream=0.sdp" -f flv -r 25 -s 640x480 -an "rtmp://localhost:1935/uid/1/camera1"')
Be careful, you either have to use single quotation marks as I did, or to escape double quotation marks.
A cleaner way to do it may use subprocess, to redirect stderr and stdout into Python variables for instance.
I'm using ffmpeg to take a screenshot from a udp stream.
Due to varying bit rates while transmission, the captured screenshot has different file size everytime.400KB,500KB..Even though it is screenshot of a same static page.
Is there a way to get a specific file size every time, in ffmpeg?
Or is there a command to convert a captured file to the desired KB using Python or through Ubuntu terminal?
Here is the command I'm using.
ffmpeg -i udp://#XXX.XX.XX.XX:XXXX -vframes 1 -q:v 1 test.png
I also tried the following commands in terminal, but it did nothing.
convert -define jpeg:extent=100kb test.png output.png
I'm stuck with a little problem:
I have a website to manage videofiles for different users. Each user can upload videos to a personal folder which I don't want to change because I don't want to mix up files from different users. After uploading the video file I call a subprocess which should create a thumbnail. The subprocess fails because of an error in ffmpeg, seeming to be related to missing writing permissions. The uploaded file and the containing folder belong to www-data.
The code:
command = ("ffmpeg -ss 00:00:10 -i %s -dframes 1 %s -y" % (video_path, image_path)).split()
subprocess.call(command)
FFMPEG seems to be run as a different user because it only works if the target-folder has 777-permissions. Otherwise it fails with this message:
av_interleaved_write_frame(): I/O error occurred
Usually that means that input file is truncated and/or corrupted.
If I touch the image-file instead of creating it via ffmpeg it doesn't matter if the folder has 775 or 777. The resulting file then also belongs to www-data, which means that the subprocess itself is run as www-data, doesn't it?
I thought about creating a subfolder which has 777-permissions but I don't like it for two reasons: This folder had to be created dynamically because I want to be able to create new users (and resulting new subfolders in my uploads-folder). 777-permissions are no nice solution anyway.
Do you have any suggestions what I have to change so ffmpeg can write to the folder without opening security leaks and without having to touch anything when creating a new user/folder?
I found it!
It was not a permission-problem but something strange in error handling: If the code is run from the webserver the resulting image-file is dismissed when the error occurs. If it is run from command line the resulting file remains in the folder.
So basically I changed my command that no error message appears any more by using -vframes instead of -dframes (which only worked fine in windows):
command = ("ffmpeg -ss 00:00:10 -i %s -vframes 1 %s -y" % (video_path, image_path)).split()
Try specifying -vframes 1 as described here
However, for ffmpeg 0.9 and later both dframes and vframes are aliases for frames, so if you use newer version of ffmpeg, problem is somewhere in other place.
You could run conversion process asynchronously with Celery. Your worker process might be invoked with required permissions, and apache just needs permissions to access communication channel, such as RabbitMQ for example