Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Getting "TypeError : must be real number, not NoneType" whenever trying to run write_videofile to a clip in moviepy
13 mai, par SatoExample code:
from moviepy.editor import * clip = VideoFileClip('video.mp4') clip.write_videofile('video2.mp4', fps=30)
After showing the following messages, showing that the video is being built and written,
Moviepy - Building video video2.mp4. Moviepy - Writing video video2.mp4
The following error message occurs:
Traceback (most recent call last): File "
", line 1, in File "C:\Users\User\Anaconda3\lib\site-packages\decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration return f(clip, *a, **k) File "C:\Users\User\Anaconda3\lib\site-packages\decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default return f(clip, *new_a, **new_kw) File "C:\Users\User\Anaconda3\lib\site-packages\decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB return f(clip, *a, **k) File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\video\VideoClip.py", line 300, in write_videofile ffmpeg_write_video(self, filename, fps, codec, File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 213, in ffmpeg_write_video with FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec, File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 88, in __init__ '-r', '%.02f' % fps, TypeError: must be real number, not NoneType This occurs whenever I try to perform
write_videofile
to any kinds of clip in moviepy. It is strange since the exact same code worked for me yesterday, but suddenly not anymore today. Are there any suggestions what the cause is and how to resolve this? -
How to encode mp4 so that Apple devices can stream VP9 encoded Videos via fmp4 HLS ?
13 mai, par Leon SThe question is in the title...
I have not figured it out, obviously Youtube has achieved that, but how could i do it in my own app so that i can effectively stream vp9 encoded content in my app.
Would be great to get a solution, maybe some ffmpeg settings or something like that? I know that it is officially not supported, but everywhere i look they say that it is still possible, and even "quite easy", e.g. here: https://www.streamingmedia.com/Articles/ReadArticle.aspx?ArticleID=133907
Trief multiple fmp4 encodings so far for vp9 but neither my app player nor safari play the videos, even though VLC and co do.
-
How to batch process with ffmpeg script, but do each step in a loop instead of two stages
12 mai, par MattI'm a novice script editor. I convert MOV/AVI video files to MP4 format using a script with ffmpeg and then move the files after processing:
for f in *.mov; do ffmpeg -y -i "$f" "${f%}.mp4"; done mv -f *.mov /Users/me/Videos/mov mv -f *.MOV /Users/me/Videos/mov mv -f *.avi /Users/me/Videos/avi mv -f *.AVI /Users/me/Videos/avi
Currently the script converts all videos, then moves them all to the other folders. Please how can the script be adjusted so that each video is moved immediately after processing (instead of waiting until all are complete)? This would be a great improvement, as sometimes there are a lot of videos and the script gets interrupted for some reason (not a fault of the script). It will make it easier to monitor progress.
Currently I manually tweak the first line changing *.mov for *.avi Please is there an easy way to handle either video file format/extension, within the same line?
Is there a better way of handling the mv statements which have multiple lines for lower/uppercase? They also give error if there are no files of that type.
Thank you
The above script is functional but will be better with enhancements or changes.
-
piping data into an ffmpeg subprocess. Why does write() get stuck ? [closed]
12 mai, par TebyyIt displays the number of frames at the beginning and shows that there are over 300, but when I count all the frames in the loop, the last one I see is 53, and then it only displays the value of 'ret', which is always true. I'm wondering what could be causing this issue of not reading all the frames, resulting in the file not being closed after reading. From what I've read, 'ret' should return false when there are no more frames to read, but because it's not reading all the frames, this isn't happening. Does anyone have any idea what could be causing this?
Edit: I solved the problem by adding a Thread. Thanks everyone for the help!
I changed those lines of code:
recogniteAndPushFramesToFfmpeg("video-979257305707693982.mp4", ffmpeg_process) # In function "recogniteAndPushFramesToFfmpeg" process.stdin.write(frame)
to these:
ffmpeg_thread = Thread(target=recogniteAndPushFramesToFfmpeg, args=("video-979257305707693982.mp4", ffmpeg_process)) ffmpeg_thread.start() # In function "recogniteAndPushFramesToFfmpeg" process.stdin.write(frame.tobytes())
Code:
import subprocess import cv2 def recogniteAndPushFramesToFfmpeg(video_path, process): cap = cv2.VideoCapture(video_path) i = 1 print('Frames:', cap.get(cv2.CAP_PROP_FRAME_COUNT)) while cap.isOpened(): ret, frame = cap.read() print(ret) if not ret: break process.stdin.write(frame) process.stdin.flush() print('Frame:', i) i += 1 cap.release() process.stdin.close() #process.wait() return ffmpeg_command = [ 'ffmpeg', '-f', 'rawvideo', '-s:v', '1920x1080', '-r', '60', '-i', '-', '-vf', 'setpts=2.5*PTS', '-c:v', 'libvpx-vp9', '-g', '60', '-f', 'webm', '-' ] ffmpeg_process = subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1) recogniteAndPushFramesToFfmpeg("video-979257305707693982.mp4", ffmpeg_process)
Python Logs:
Frames: 328.0 ... True Frame 50 True Frame 51 True Frame 52 True Frame 53 True
I placed
cap.isOpened()
in the loop to check if it always returns true, and when I printed it, it always showed trueLink to video: Tested Video
-
Adding Dynamic Progress Bar to FFMpeg Video Output (Mac) [closed]
12 mai, par saurav tripathiI'm trying to add a dynamic progress bar to the bottom of a video using ffmpeg on my Mac. Here's the command I'm currently using:
ffmpeg -i "/Volumes/hard-drive/Auto-pilot-video/upload-ready-video/one-two-ka-four.mp4" -filter_complex \ "[0:v]drawbox=y=ih-20:color=yellow@0.5:width=iw*(t/606.15):height=20:t=fill[v]" \ -map "[v]" -map 0:a -c:a copy -preset fast output.mp4
Question:
As you can see in the image right now, it just a fixed yellow bar at the bottom of the screen. But instead of just fixed at bottom I want a dynamically moving bar at the bottom.
Is it possible to create a dynamic progress bar using ffmpeg filters on macOS? If so, could you please suggest the appropriate filter(s) and their configuration for achieving this effect?