ch00k / ffmpy Goto Github PK
View Code? Open in Web Editor NEWPythonic interface for FFmpeg/FFprobe command line
License: MIT License
Pythonic interface for FFmpeg/FFprobe command line
License: MIT License
What is the license for this code? I plan on forking it and making it use asyncio-subprocess
instead of standard subprocess
as I have a project that necessitates the use of coroutines and I'd rather not introduce multithreading when it isn't necessary.
Is there a way to specify that I want to replace the file if there's already a file with the same name and I am doing it with PysimpleGUI and ffmpy
Is this still being supported
I have been trying to troubleshoot this for a couple days but without success. All I am trying to do is log the printing output from the ffmpeg terminal. There are more reasons I need to read from the console, but logging is just a simple place to start and get things working.
I saw in the source code notes that there is an argument you can pass for stdout=subprocess.PIPE in order to reroute the printing, but it still fails to communicate properly to the pipe I open.
Here is an example:
"ffmpy_test.py"
ff = ffmpy.FFmpeg(
inputs={'song.mp3':
'-y'},
outputs={'converted.wav':
'-frames:a 441000 '
'-sample_fmt s16 '}
)
ff.run(stdout=subprocess.PIPE)
...And "string_handler.py"
with subprocess.Popen(["python", "ffmpy_test.py"], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
logger.info(line)
This prints absolutely nothing in the log. However, it will still stream the ffmpeg output to the main working terminal window. I have also tried adding the shell=True
to Popen but it made no difference when trying to actually log the ffmpeg instance.
I have also tried something less eligent to talk to it, such as:
p = subprocess.Popen(['python', 'ffmpy_test.py'], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True)
line = p.communicate()[0]
while True:
logger.info(line)
This only prints empty break-line statements to the log, which indicates that it is only reading it after the ffmpeg script has finished running OR that ffmpy's output is still routed somewhere completely different.
And when I saw buslas issue on making communicate() unblocked here,, I went into the ffmpy.py source code and added the """ """ and return statements where described. But doing this had no effect on the behavior described above. What is it that I am missing? Why on earth can I not read from what ffmpeg is printing out?
solved... no issue
please remove
Hello.
Some useful information I guess:
I usually am running ffmpy.FFprobe
to get the dimensions of a video (amongst other things):
import ffmpy
ff = ffmpy.FFprobe(inputs={
'': ('-v error -show_entries stream=width,height '
'-of default=noprint_wrappers=1:nokey=1 '
'{video_path}').format(video_path=video_path)
})
ff.run()
The result has been (640,320)
or similar before but now it only produces (None,None)
and prints out the result:
>>> result = ff.run()
640
360
>>> print(result)
(None, None)
I could intercept the stdout and use the result from there (I guess.... because why shouldn't I? Workarounds ftw. 😄 ) but I thought I first ask/post my issue here to understand know, whether this is intended behaviour? 😃
I'm available for feedback/discussion on this. 😉
How can i set the loglevel
? I can not get it in the Docs.
First, thank you for the awesome wrapper to make the coding easier.
I am wondering if there's a way to overwrite the existing file automatically (or say yes directly to the command line). For now, I need to delete the file first, then execute the script. Thanks.
Thanks for contributing 👍
Using this:
ff_probe = ffmpy.FFprobe(
inputs = {
'myurl': None,
},
global_options = [
'-print_format json',
'-show_format',
'-show_streams',
]
)
Runs this command:
ffprobe "-print_format json" -show_format -show_streams -i http://myurl.me
And gives me this error:
Failed to set value '-show_format' for option 'print_format json': Option not found
As you can see the print_format json gets wrapped in double quotes.
Would be great to see an implementation of a class method to kill the process gracefully (with 'q').
I´m trying to stop the ffmpeg process by killing it with SIGINT. Here is a stripped down code of my threading class:
def is_process_running(self, process_name):
p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if bytes(process_name, 'utf-8') in line:
pid = line.split()[0]
return pid
return False
def kill_process(self):
logger.info('Stopping FFMPEG')
proc = is_process_running('ffmpeg')
if proc:
os.kill(proc, signal.SIGINT)
Here is the traceback:
Exiting normally, received signal 2.
Exception in thread ffmpeg-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "observer.py", line 45, in run
self.ff_stream.run()
File "/Users/levy/Code/streampimp/venv/lib/python3.5/site-packages/ffmpy.py", line 104, in run
raise FFRuntimeError(self.cmd, ff_command.returncode, out[0], out[1])
ffmpy.FFRuntimeError: `ffmpeg -re -i [the-input-output-parameters]` exited with status 255
I´m curious to know how you are dealing with stopping ffmpeg. Note that I´m running ffmpeg in a separate thread.
I am trying to run the following Ffmpeg command in ffmpy '-vf "curves=psfile=/filepath/file.acv" -c:a copy -f mp4'
. I keep getting the error exited with status 1
.
I noticed the command being printed in the error message and that the double quotes were missing.
I have tried the different variations shown in the docs under complex commands. But can't seem to get the double quotes where I want. It either surrounds the whole command or the last part.
Here is the code I use:
ff = ffmpy.FFmpeg(
inputs={input_path: None},
outputs={output_path: fc}
)
ff.run()
fc is fetched from a dictionary.
from ffmpy import FFmpeg
I have added both the ffmpeg bin and the ffmpeg exe to my system PATH, but my program keeps showing:
ImportError: cannot import name 'FFmpeg'
how to add overwrite output features ?
Hello Andrii Yurchuk,
Is it possible to use ffmpeg extracted frames in jpg to numpy using FFMPY?
hello
is it possible to load images sequence from a folder and convert them to video ?
Deprecation warning due to invalid escape sequences. Using raw strings or escaping them again helps in resolving this. Check https://github.com/asottile/pyupgrade/ for automatic fix of this.
find . -iname '*.py' | grep -Ev 'rdf4|tool|doc' | xargs -P4 -I{} python3.8 -Wall -m py_compile {}
./tests/test_cmd_compilation.py:84: DeprecationWarning: invalid escape sequence \:
"timecode='09\:57\:00\:00': "
Hello,
I have a few questions relating to RTMP streaming:
ff.run()
blocking?Thanks in advance!
Hi i am using FFmpeg on huge data set of videos and I might have some damaged videos in it?
Typically through the command line, I would do something like
ffmpeg -v error -i 3.mp4 -f null - &> test15.log
But how can I do this through the python library?
Hi,
I was working on a transcoding platform and I found your module to wrapping ffmpeg. I'm interested to make improvements that would be useful to everyone involved in this niche.
I'm planning to replace Popen.communicate call to achieve the goals:
Popen.communicate() is inefficient because of stdout and stderr buffering. Let's see some cases:
you want to send transcoded data over network as fast as available. If communicate() is used, you must to accumulate the entire transcoded movie on a memory buffer to send it.
you want to know the transcoding state (output size, time, bitrate) in real time. If communicate() is used, you can't do it because this method is consuming the stderr pipe
I have a experimental branch with a on_progress callback implemented here:
https://github.com/astroza/ffmpy/tree/progress_support
An usage example is:
def on_progress(state):
print state.time
ff = ffmpy.FFmpeg(
global_options="-hide_banner -nostdin -y -stats",
inputs={local_input_path: None},
outputs={local_output_path: None},
on_progress=on_progress
)
ff.run(stderr=subprocess.PIPE)
Now I'm working to make it backwards compatible. The branch break your API
UPDATE
https://github.com/astroza/ffmpy/tree/progress_support_v2 keeps backward compatibility
Usage:
def on_progress(state):
print state.time
ff = ffmpy.FFmpeg(
global_options="-hide_banner -nostdin -y -stats",
inputs={local_input_path: None},
outputs={local_output_path: None}
)
print(ff.run(on_progress=on_progress)[1])
ffmpy not installing ffprobe after installing from pip getting error:
ffmpy.FFExecutableNotFoundError: Executable 'ffprobe' not found
I tried passing subprocess.DEVNULL
to run()
without success.
ff = FFmpeg(
inputs={file_name: None},
outputs={new_file_name: None}
)
ff.run(stdout=subprocess.DEVNULL)
For downstream distributions that want to run tests which are only available on GitHub it would be quite handy to have tags on GitHub.
Is it possible to get the video-conversion progress in ffmpy? Like from 0 to 100 or "timecode"/"video length"
When I called ff.run()
in PyCharm on MacOS Catalina within conda environment, I got this error:
Traceback (most recent call last):
File "/Users/myname/.conda/envs/xiaoetong/lib/python3.7/site-packages/ffmpy.py", line 95, in run
stderr=stderr
File "/Users/myname/.conda/envs/xiaoetong/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/Users/myname/.conda/envs/xiaoetong/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg': 'ffmpeg'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/myname/Documents/Projects/xiaoetong/ffmpy_test.py", line 8, in <module>
ff.run()
File "/Users/myname/.conda/envs/xiaoetong/lib/python3.7/site-packages/ffmpy.py", line 99, in run
raise FFExecutableNotFoundError("Executable '{0}' not found".format(self.executable))
ffmpy.FFExecutableNotFoundError: Executable 'ffmpeg' not found
Process finished with exit code 1
This literally implies that either ffmpeg
is not installed or the command is not added to path. However, I did install it, and I was able to call ffmpeg
command successfully in the zsh terminal. I could also run that python script without error in terminal within exactly the same conda environment (and using exactly the same python interpreter).
The same code could also be run without error within the same conda environment in PyCharm on Windows 10.
Version I was using: python==3.7.5, ffmpeg==4.2, ffmpy==0.2.2, pycharm==2019.3.1(professional edition)
I also posted a question here:
https://stackoverflow.com/questions/59586913/ffmpy-cannot-find-ffmpeg-when-running-in-pycharm-on-mac-using-conda-env
import ffmpy
ff = ffmpy.FFmpeg(
inputs={'input_dir/video.m3u8': ['-protocol_whitelist', 'crypto,file,http,https,tcp,tls']},
outputs={'output_dir/ffmpy_test.mp4': None}
)
print(ff.cmd)
ff.run()
create conda environment, install ffmpeg, ffmpy
run that python script in PyCharm within that conda environment
Hello, I am going to use ffmpy to push the camera and microphone, but I did not find the relevant syntax.
The cmd commands required are:
ffmpeg -s 320x240 -f dshow -i video="USB2.0 HD UVC WebCam" -f dshow -i audio="立体声混音 (Conexant SmartAudio HD)" -r 5 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec libmp3lame -f flv rtmp://localhost:8086/myapp/1727405069
The code of ppmpy I use is:
ff=ffmpy.FFmpeg(
global_options=['-s 320x240'],
inputs={'video="USB2.0 HD UVC WebCam"':'-f dshow','audio="立体声混音 (Conexant SmartAudio HD)"':'-f dshow'},
outputs={'rtmp://localhost:8086/myapp/1727405069':'-r 5 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec libmp3lame -f flv'}
)
print(ff.cmd)
The output is
ffmpeg -s 320x240 -f dshow -i "video=\"USB2.0 HD UVC WebCam\"" -f dshow -i "audio=\"立体声混音 (Conexant SmartAudio HD)\"" -r 5 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec libmp3lame -f flv rtmp://localhost:8086/myapp/1727405069
Because -i "video = \" USB2.0 HD UVC WebCam \ ""
and -i "audio=\"立体声混音 (Conexant SmartAudio HD)\""
do not match the actual required cmd command, an error that the device cannot be found is reported.
So what is the correct code?
Thank you.
Hi there!
Is it possible to first do a color palette run when generating a .gif conversion? Currently the default generates a sort of bi-color .gif.
If I run ffmpeg from the terminal with this first:
ffmpeg -i input.mp4 -vf palettegen palette.png
And then:
ffmpeg -i input.mp4 -i palette.png -lavfi "paletteuse" output.gif
Then I get the desired result. Can this be emulated in ffmpy
?
hi i finally success with it and it is very useful
now it is easy to choose input folder and output with pyqt4
in the output is it possible to control settings with pyqt ? frame ; size..etc like the input/output
On my local mac its working great, however on aws linux (installed with pip) i get this error.
I guess it has something to do with the PATH.
File "converter.py", line 14, in <module>
ff.run()
File "/usr/local/lib/python2.7/site-packages/ffmpy.py", line 99, in run
raise FFExecutableNotFoundError("Executable '{0}' not found".format(self.executable))
ffmpy.FFExecutableNotFoundError: Executable 'ffmpeg' not found
PS C:\ComfyUI_windows_portable\python_embeded> ./python -s -m pip install ffmpy
Collecting ffmpy
Using cached ffmpy-0.3.0.tar.gz (4.8 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\jorda\AppData\Local\Temp\pip-install-xxpmvq8x\ffmpy_14f9e068f9a54218b76e7156b7c315f8\setup.py", line 4, in <module>
from ffmpy import __version__
ModuleNotFoundError: No module named 'ffmpy'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
I want to be able to date/time the filenames in my segments, unfortunately this does not seem to be working for me.
The full command being run is:
ffmpeg -rtsp_transport tcp -i rtsp://admin:[email protected]:554/Streaming/Channels/1 -map 0 -c copy -f segment -segment_time 300 /footage/xyz-%Y%m%d-%s.mp4
Is there a special way that I need to escape the variables?
Here is my code:
class MyOutput(object):
def init(self, url):
self.url = url
def write(self, buf):
print('start publish rtmp stream...')
ff = FFmpeg(inputs={'pipe:0':'-vcodec libx264'}, outputs={self.url:'-r 24 -s 640x480 -f flv'})
print(ff.cmd)
ff.run(input_data=buf)
Please help me! what has happend to me?
Would it be possible to pipe subsequent frames to the subprocess? I would like to do something like this:
< initialize ffmpy in "pipe mode" >
for i in range(0,100):
< generate a frame >
< pipe the frame to the subprocess >
< close the pipe >
I think this is related to #13.
I am attempting to use ffmpy and ffmpeg to screen capture the desktop, then send the frames to another device.
from ffmpy import FFmpeg
import numpy as np
import subprocess
ff = FFmpeg(
executable=os.path.join('ffmpeg', 'bin', 'ffmpeg.exe'),
inputs={'desktop': '-f gdigrab -framerate 30'},
outputs={'pipe:1': '-c:v h264'}
)
pipe = ff.run(stdout=subprocess.PIPE)
while True:
# read 1920*1080*3 bytes (= 1 frame)
raw_image = pipe.stdout.read(1920 * 1080 * 3)
# transform the byte read into a numpy array
frame = np.fromstring(raw_image, dtype='uint8')
# throw away the data in the pipe's buffer.
pipe.stdout.flush()
I get the following:
(venv) C:\Users\ReenigneArcher\Documents\GitHub\RetroArcher\py_stream>python test.py
ffmpeg version n5.0.1-5-g240d82f26e-20220626 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.2.0 (crosstool-NG 1.24.0.533_681aaef)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads
--enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disa
ble-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-l
ibass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopen
h264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --d
isable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20220626
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
[gdigrab @ 000002c5622b2980] Capturing whole desktop as 1920x1080x32 at (0,0)
[gdigrab @ 000002c5622b2980] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, gdigrab, from 'desktop':
Duration: N/A, start: 1656372396.709033, bitrate: 1990668 kb/s
Stream #0:0: Video: bmp, bgra, 1920x1080, 1990668 kb/s, 30 fps, 1000k tbr, 1000k tbn
[NULL @ 000002c560479080] Unable to find a suitable output format for 'pipe:1'
pipe:1: Invalid argument
Traceback (most recent call last):
File "C:\Users\ReenigneArcher\Documents\GitHub\RetroArcher\py_stream\test.py", line 31, in <module>
pipe = ff.run(stdout=subprocess.PIPE)
File "C:\Users\ReenigneArcher\Documents\GitHub\RetroArcher\py_stream\venv\lib\site-packages\ffmpy.py", line 106, in run
raise FFRuntimeError(self.cmd, self.process.returncode, out[0], out[1])
ffmpy.FFRuntimeError: `ffmpeg5\bin\ffmpeg.exe -f gdigrab -framerate 30 -i desktop -c:v h264 pipe:1` exited with status 1
STDOUT:
STDERR:
This command works in command line.
ffmpeg -f gdigrab -framerate 30 -i desktop output.mkv
How do you suggest that FFmpeg should be killed gracefully from ffmpy?
This is my function call:
os.kill([the-pid-of-ffmpeg], signal.SIGKILL)
That results in:
Exiting normally, received signal 15.
Traceback (most recent call last):
File "xml_test.py", line 174, in <module>
record_stream(root)
File "xml_test.py", line 135, in record_stream
run_ffmpeg(start_time, stop_time, event.find('title'))
File "xml_test.py", line 106, in run_ffmpeg
ff_stream.run()
File "/Users/jon/code/streampimp/venv/lib/python3.5/site-packages/ffmpy.py", line 92, in run
raise FFRuntimeError(self.cmd, ff_command.returncode, out[0], out[1])
File "/Users/jon/code/streampimp/venv/lib/python3.5/site-packages/ffmpy.py", line 141, in __init__
stdout.decode() or '',
AttributeError: 'NoneType' object has no attribute 'decode'
The script is wonderful but a bit slow, can you add support for Nvidea FFmpeg Cuda Nvenc conversion?
Here's a link which might be useful - Zulko/moviepy#1014
Hey people.
I wrote an small service that receive a .dav (video format for CCTV) and convert it to a handy .mp4 that can be played on browsers. Unfortunately ffmpy doesn't recognize the format (but ffmpeg, the tool, does). Here is an example of the working command:
ffmpeg -i raw_video.dav -vcodec copy test.mp4
or even ffmpeg -i raw_video.dav -c:v libx264 -crf 30 -preset veryfast -filter:v fps=fps=10 test.mp4
, if I am felling like saving space and cpu usage is not an issue.
As I said, ffmpeg recognize the file as dhav:
Input #0, dhav, from 'raw_video.dav': Duration: N/A, start: 1609124514.000000, bitrate: N/A Stream #0:0: Video: hevc (Main), yuvj420p(pc, bt709), 960x480, 30 fps, 30 tbr, 1k tbn
But when I try to use ffmpy, It just complain about invalid data:
raw_video.dav: Invalid data found when processing input
I used the Issue search but I only found a question not related to my problem...
Any Idea? I am calling ffmpeg as a subprocess, but would be much nicer to use ffmpy.
Hi everyone,
I've been trying to use ffmpy on a headless Raspberry Pi for the last two days. After many trial and error, I'll post here the succesful method for me. Since I'm a beginner, I like exhaustive tutorials, and that will be the scope used here. Nevertheless, this is github, and I assume that many of the things here are redundant and well-known for the majority of users :)
I basically followed the sections 1 and 2 on:
https://engineer2you.blogspot.com.es/2016/10/rasbperry-pi-ffmpeg-install-and-stream.html
1) Prerequisites on Raspbian Lite
I wanted to install ffmpy on Raspbian Jessie Lite, which is the light version of Raspbian Jessie, a distro in turn based on Debian (Raspberry + Debian = Raspbian). So I'd assume this works for Debian users too.
git is not installed by default on this tiny OS. Maybe a bit obvious, but simply run on the command line:
sudo apt-get install git
2) Install library
Using the command line, run sequentially:
cd /usr/src
sudo git clone git://git.videolan.org/x264
cd x264
sudo ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
sudo make
sudo make install
Note that the ./configure command will be demanding for the RPi hardware. It'll look that the RPi stopped working: simply wait 5 to 10 minutes until you get a response and recover the command prompt.
3) Install ffmpeg
This installs the basic files on which ffmpy depends (if you run it without this installed, you'll get some error like "ffmpeg executable not found"). So, simply follow:
cd /usr/src
sudo git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg/
sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
sudo make
This last ./configure will take its time too. But then the last line, the make step, will take about 4-5 hours (on RPi's hardware without any overclocking). So maybe you'd like to install ffmpeg before going to sleep or going for a walk!
4) Finally: install ffmpy
We now have all the files you need to install ffmpy as usual. Run:
sudo pip install ffmpy
or
sudo pip3 install ffmpy
in case you are using python 3.*.
Specifically, I am trying to get various pieces of info from ffprobe. Calling FFprobe.run() does not return all of the same information as running ffprobe from the cli.
Running from CLI gets me data such as:
Duration: 00:00:06.37, start: 0.000000, bitrate: 2812 kb/s
Stream #0:00x1: Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 2096 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:10x2: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Which includes stuff like video stream fps, duration, total bitrate, video stream bitrate, audio stream bitrate, audio stream codec.
The output from FFProbe.run() is missing this information. Is there a way to get the more detailed output that the cli command provides?
Here is my code currently:
source = os.path.join('d:\\', 'capstone', 'test_vids', 'input_jesse.mp4') ff_probe = ffmpy.FFprobe( inputs={source: None}, global_options='-print_format json -show_format -show_streams' ) metadata = ff_probe.run(stdout=subprocess.PIPE) print(metadata)
Update: My apologies. I'm not sure how to add code to this so it will display properly. Here is an image of that snippet.
Hello there!
I would like to know how I can transfer PIL images to FFMPY to save it as video, or gif, since the PIL library's quantization method has strong quality losses in certain cases.
I did not find any information on the topic online, beside one post with PIL to FFMPEG that I wasn't able to apply to my case.
What is the right way to code to do this?
If I have for example this setup to begin with:
import ffmpy
import PIL
from PIL import Image as Img
images = [Img.open('frame 1.png'),Img.open('frame 2.png')]
ff = ffmpy.FFmpeg(
inputs={images ?: None},#How do I insert PIL images here?
outputs={'output.gif': None},
executable='ffmpeg\\bin\\ffmpeg.exe')
ff.run()
How would I proceed to convert and save the images as a video using FFMPY?
Currently the functionality only allows it to be written to an output file. Since the process runs with Popen()
within the run()
function, it's not feasible to redirect the stdout
or stderr
without additional complex processes.
EDIT:
I was mistaken. Supplying stderr=subprocess.PIPE
in the run()
function gives the correct return values as a bytes
string since you already use communicate()
as the return output.
This issue should be closed.
On a side note, maybe it would be easier to understand if you mention in the documentation that the actual output of stdout
is media data and stderr
is for logging/progress information (which is what most people want). I learned about it from http://stackoverflow.com/a/748006/5812876. I read about your procedures on https://media.readthedocs.org/pdf/ffmpy/latest/ffmpy.pdf and was mislead by the last sentence of the first paragraph of the run()
function specifying the stdout output as mentioned below.
Personally, I would simply state on the run()
documentation that if you want to capture the stdout
or stderr
as a string then supply subprocess.PIPE
to the respective stdout=
or stderr=
parameter and assign the run()
function to the desired variable. This is because I didn't know what you meant by "f FFmpeg pipe protocol" since that usually refers to something like pipe:0
, pipe:1
or pipe:2
for stdin, stdout, and stderr respectively. This may still just be confusion on my part though.
One last thing I would add is that I didn't need in a bytes
string, so maybe you could provide the option to have it decoded before returning or make it the default, though that's just a personal preference.
Anyways, thank you for the amazing FFmpeg wrapper.
I have to concatenate multiple videos. I can do this on shell by following instructions at:
https://trac.ffmpeg.org/wiki/Concatenate
But I am not able to find api for concatenate in ffmpy.
Am I missing something or in current implementation concatenate is not done yet?
I have this problem, I can't find a solution. I tried to do it through Command Prompt
usage: streamlink [OPTIONS] [STREAM]
streamlink: error: argument -o/--output: expected one argument
pipe:0: Invalid data found when processing input
C:\Windows\System32>
When running ffmpy in the background I needed to remove the communicate()
call in https://github.com/Ch00k/ffmpy/blob/master/ffmpy.py#L103.
I think I´m not understanding the subprocess module properly so do you have any suggestions on how to make the subprocess non-blocking?
Cheers.
Hey I have this ffmpeg shell script working to overlay a png file, use a color key filter to create a green screen and then overlay the png with an input .mp4 file.
I was wondering if you'd be able to tell me how to transfer this command line to your python wrapper. I think I have the hang of most of, from reading the documentation, but I was unable to figure out how to use -map in the way I'm using it in the above screenshot. Thanks!
inputs={src+"/"+file:None for file in files}
outputs={dst+"/"+file: '-vf transpose=clock' for file in files}
ff = FFmpeg(
inputs=inputs,
outputs=outputs
)
Expected: Every input file gets converted to corresponding output file.
I thought the API supports this because the variable is named inputs
(though the ffmpeg binary doesn't)
But it is not supported and results in multiple files with same contents.
This is very confusing and should be mentioned on the wiki.
When there is an space in the absolute path of file name it does not work.
E.g. "/var/www/etb-xxx-01.info/public_html/downloads/[email protected]/Pretty Face Blonde /princessa_v_klopovnike.avi_VIRTUAL_FILE_"
Here the space between "Pretty Face Blonde" is creating issue.
I checked the same query with no space. It works.
Is there an example for use named pipe for Audio (raw) and Video (raw) and create a hls output from Python ? Both inputs (audio and video) are all raw numpy arrays: audio is array with 1920 byte chunk, images are array with 640x480x3 bytes chunk.
Thanks,
Steve
Hello, i'm using ffmpy on Windows. And i got no output in ffmpeg window, when i run my program. I used no modifications due to manual, like this:
ff = ffmpy.FFmpeg(inputs=inputs, outputs={output:None})
ff.run()
I assume, this is regual question you got, but i failed to find an answer. Please give me ready-to-work solution. Hope i sounded not mean, it's about lack of languague skills.
Hi, I am new with ffmpy
I use FFprobe in the windows shell console for determine the position of keyframes in the video:
ffprobe -show_frames C:\myuser\documents\myvideo.avi > c:\myuser\documents\myvideodata.txt
(this code make a txt file with info for all keyframes)
How can I use this code with ffmpy in python?
Edit:
ffmpy version 0.2.1
python 2.7.12
I tried:
import ffmpy
ff = ffmpy.FFprobe(inputs={
'': ('-show_frames C:/myuser/documents/myvideo.avi > c:/myuser/documents/myvideodata.txt')
})
ff.cmd
ff.run()
But I get:
FFRuntimeError: `ffprobe -show_frames C:/myuser/documents/myvideo.avi > C:/myuser/documents/myvideodata.txt' exited with status 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.