
Recherche avancée
Autres articles (49)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Soumettre améliorations et plugins supplémentaires
10 avril 2011Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...)
Sur d’autres sites (10995)
-
TypeError : must be real number, not NoneType using spyder anaconda
13 août 2023, par faisal2kimport moviepy.editor as mp
import tkinter as tk
from tkinter import filedialog
import math
from PIL import Image
import numpy


def zoom_in_effect(clip, zoom_ratio=0.02):
 def effect(get_frame, t):
 img = Image.fromarray(get_frame(t))
 base_size = img.size

 new_size = [
 math.ceil(img.size[0] * (1 + (zoom_ratio * t))),
 math.ceil(img.size[1] * (1 + (zoom_ratio * t)))
 ]

 # The new dimensions must be even.
 new_size[0] = new_size[0] + (new_size[0] % 2)
 new_size[1] = new_size[1] + (new_size[1] % 2)

 img = img.resize(new_size, Image.LANCZOS)

 x = math.ceil((new_size[0] - base_size[0]) / 2)
 y = math.ceil((new_size[1] - base_size[1]) / 2)

 img = img.crop([
 x, y, new_size[0] - x, new_size[1] - y
 ]).resize(base_size, Image.LANCZOS)

 #result = numpy.array(img)
 result = numpy.array(img, dtype=numpy.uint8)

 img.close()

 return result

 return clip.fl(effect)


 

def make_center_video():
 
 size = (1080, 1080)

 audio_file = '/home/faisal/pythonfiles/audio/tts_voice.wav'
 audio = mp.AudioFileClip(audio_file)
 
 root = tk.Tk()
 root.withdraw()
 
 print("waiting for Image Selection....")

 img = filedialog.askopenfilename()


 slide = mp.ImageClip(img).set_fps(29).set_duration(audio.duration).resize(size)
 slide = zoom_in_effect(slide, 0.02)
 slide.write_videofile('/home/faisal/pythonfiles/videos/zoom-short.mp4',codec='libx264', fps=29)
 
 
 size = (600, 600)

 


 slide = mp.ImageClip(img).set_fps(29).set_duration(audio.duration).resize(size)
 slide = zoom_in_effect(slide, 0.02)
 slide.write_videofile('/home/faisal/pythonfiles/videos/zoom-wide.mp4',codec='libx264', fps=29)
 
import traceback

try:
 make_center_video()
except Exception as e:
 traceback.print_exc()
 print(f"An error occurred: {e}")



I'm trying to make the zoom video using image but facing


TypeError: must be real number, not NoneType.



It used was to run but I don't remember if I might have updated numpy, ffmpeg, or any thing else that is now causing the error. I have tried the code on python 3.10 and 3.11 and get the same error in both. I was previously running it on python 3.10.


An error occurred: must be real number, not NoneType
Traceback (most recent call last):
 File "/home/faisal/pythonfiles/code/zoom_video.py", line 76, in <module>
 make_center_video()
 File "/home/faisal/pythonfiles/code/zoom_video.py", line 61, in make_center_video
 slide.write_videofile('/home/faisal/pythonfiles/videos/zoom-short.mp4',codec='libx264', fps=29)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/decorator.py", line 232, in fun
 return caller(func, *(extras + args), **kw)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/moviepy/decorators.py", line 54, in requires_duration
 return f(clip, *a, **k)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/decorator.py", line 232, in fun
 return caller(func, *(extras + args), **kw)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/moviepy/decorators.py", line 135, in use_clip_fps_by_default
 return f(clip, *new_a, **new_kw)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/decorator.py", line 232, in fun
 return caller(func, *(extras + args), **kw)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
 return f(clip, *a, **k)
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/moviepy/video/VideoClip.py", line 300, in write_videofile
 ffmpeg_write_video(self, filename, fps, codec,
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_writer.py", line 213, in ffmpeg_write_video
 with FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,
 File "/home/faisal/anaconda3/envs/py-310/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_writer.py", line 88, in __init__
 '-r', '%.02f' % fps,
TypeError: must be real number, not NoneType
</module>


-
ffmpeg "End mismatch 1" warning, jpeg2000 to avi
11 avril 2023, par jklebesTrying to convert a directory of jpeg2000 grayscale images to a video with ffmpeg, I get warnings


[0;36m[jpeg2000 @ 0x55d8fa1b68c0] [0m[0;33mEnd mismatch 1



(and lots of


Last message repeated <n> times
</n>


)


The command was


ffmpeg -y -r 10 -start_number 1 -i <path>/surface_30///img_000%01d.jp2 -vcodec msmpeg4 -vf scale=1920:-1 -q:v 8 <path>//surface_30///surface_30.avi
</path></path>


The output is


ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 7.3.0 (crosstool-NG 1.23.0.449-a04d0)
 configuration: --prefix=/home/jklebes001/miniconda3 --cc=/tmp/build/80754af9/ffmpeg_1587154242452/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --disable-doc --enable-avresample --enable-gmp --enable-hardcoded-tables --enable-libfreetype --enable-libvpx --enable-pthreads --enable-libopus --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-static --enable-version3 --enable-zlib --enable-libmp3lame --disable-nonfree --enable-gpl --enable-gnutls --disable-openssl --enable-libopenh264 --enable-libx264
 libavutil 56. 31.100 / 56. 31.100
 libavcodec 58. 54.100 / 58. 54.100
 libavformat 58. 29.100 / 58. 29.100
 libavdevice 58. 8.100 / 58. 8.100
 libavfilter 7. 57.100 / 7. 57.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 5.100 / 5. 5.100
 libswresample 3. 5.100 / 3. 5.100
 libpostproc 55. 5.100 / 55. 5.100
[0;36m[jpeg2000 @ 0x55cb44144480] [0m[0;33mEnd mismatch 1

[0m Last message repeated 1 times
 Last message repeated 2 times
 Last message repeated 3 times



...


Last message repeated 73 times

Input #0, image2, from '<path>//surface_30///img_000%01d.jp2':

 Duration: 00:00:00.20, start: 0.000000, bitrate: N/A

 Stream #0:0: Video: jpeg2000, gray, 6737x4869, 25 tbr, 25 tbn, 25 tbc

Stream mapping:

 Stream #0:0 -> #0:0 (jpeg2000 (native) -> msmpeg4v3 (msmpeg4))

Press [q] to stop, [?] for help

[0;36m[jpeg2000 @ 0x55cb4418e200] [0m[0;33mEnd mismatch 1

[0m[0;36m[jpeg2000 @ 0x55cb441900c0] [0m[0;33mEnd mismatch 1
</path>


...


(about 600 lines of "end mismatch" and "last message repeated" cut)


...


[0m[0;36m[jpeg2000 @ 0x55cb4418e8c0] [0m[0;33mEnd mismatch 1

[0mOutput #0, avi, to '<path>/surface_30///surface_30.avi':

 Metadata:

 ISFT : Lavf58.29.100

 Stream #0:0: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 1920x1388, q=2-31, 200 kb/s, 10 fps, 10 tbn, 10 tbc

 Metadata:

 encoder : Lavc58.54.100 msmpeg4

 Side data:

 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1

frame= 2 fps=0.8 q=8.0 size= 6kB time=00:00:00.20 bitrate= 227.1kbits/s speed=0.0844x 
frame= 5 fps=1.7 q=8.0 size= 6kB time=00:00:00.50 bitrate= 90.8kbits/s speed=0.172x 
frame= 5 fps=1.7 q=8.0 Lsize= 213kB time=00:00:00.50 bitrate=3494.7kbits/s speed=0.172x 
video:208kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.732246%
</path>


What is the meaning of characters like [0 ;33m here ?


I thought it might have something to do with bit depth and color format. Setting
-pix_fmt gray
had no effect, and indeed the format of the jp2 images is already detected as 8-bit gray.

The output .avi exists and seems fine.


The line was previously used on jpeg files and works fine on jpeg. With jpeg, the output has the line


Input #0, image2, from '<path>/surface_30///img_000%01d.jpeg':

 Duration: 00:00:00.16, start: 0.000000, bitrate: N/A

 Stream #0:0: Video: mjpeg (Baseline), gray(bt470bg/unknown/unknown), 6737x4869 [SAR 1:1 DAR 6737:4869], 25 tbr, 25 tbn, 25 tbc

Stream mapping:

 Stream #0:0 -> #0:0 (mjpeg (native) -> msmpeg4v3 (msmpeg4))

Press [q] to stop, [?] for help

Output #0, avi, to '<path>/surface_30///surface_30.avi':

 Metadata:

 ISFT : Lavf58.29.100

 Stream #0:0: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 6737x4869 [SAR 1:1 DAR 6737:4869], q=2-31, 200 kb/s, 10 fps, 10 tbn, 10 tbc

 Metadata:

 encoder : Lavc58.54.100 msmpeg4

 Side data:

 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1

frame= 2 fps=0.0 q=8.0 size= 6662kB time=00:00:00.20 bitrate=272859.9kbits/s speed=0.334x 
frame= 3 fps=2.2 q=10.0 size= 10502kB time=00:00:00.30 bitrate=286764.2kbits/s speed=0.22x 
frame= 4 fps=1.9 q=12.3 size= 13574kB time=00:00:00.40 bitrate=277987.7kbits/s speed=0.19x 
frame= 4 fps=1.4 q=12.3 size= 13574kB time=00:00:00.40 bitrate=277987.7kbits/s speed=0.145x 
frame= 4 fps=1.4 q=12.3 Lsize= 13657kB time=00:00:00.40 bitrate=279702.3kbits/s speed=0.145x 
video:13652kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.041926%
</path></path>


detecting mjpeg format and similar, but more detailed format
gray(bt470bg/unknown/unknown), 6737x4869 [SAR 1:1 DAR 6737:4869].


What is the difference when switching input to jp2 ?


-
Python asyncio subprocess code returns "pipe closed by peer or os.write(pipe, data) raised exception."
4 novembre 2022, par Duke DougalI am trying to convert a synchronous Python process to asyncio. Any ideas what I am doing wrong ?


This is the synchronous code which successfully starts ffmpeg and converts a directory of webp files into a video.


import subprocess
import shlex
from os import listdir
from os.path import isfile, join

output_filename = 'output.mp4'
process = subprocess.Popen(shlex.split(f'ffmpeg -y -framerate 60 -i pipe: -vcodec libx265 -pix_fmt yuv420p -crf 24 output.mp4'), stdin=subprocess.PIPE)

thepath = '/home/ubuntu/webpfiles/'
thefiles = [f for f in listdir(thepath) if isfile(join(thepath, f))]
for filename in thefiles:
 absolute_path = f'{thepath}{filename}'
 with open(absolute_path, 'rb') as f:
 process.stdin.write(f.read())

process.stdin.close()
process.wait()
process.terminate()



This async code fails :


from os import listdir
from os.path import isfile, join
import shlex
import asyncio

outputfilename = 'output.mp4'

async def write_stdin(proc):
 thepath = '/home/ubuntu/webpfiles/'
 thefiles = [f for f in listdir(thepath) if isfile(join(thepath, f))]
 thefiles.sort()
 for filename in thefiles:
 absolute_path = f'{thepath}{filename}'
 with open(absolute_path, 'rb') as f:
 await proc.communicate(input=f.read())

async def create_ffmpeg_subprocess():
 bin = f'/home/ubuntu/bin/ffmpeg'
 params = f'-y -framerate 60 -i pipe: -vcodec libx265 -pix_fmt yuv420p -crf 24 {outputfilename}'
 proc = await asyncio.create_subprocess_exec(
 bin,
 *shlex.split(params),
 stdin=asyncio.subprocess.PIPE,
 stdout=asyncio.subprocess.PIPE,
 stderr=asyncio.subprocess.PIPE,
 )
 return proc

async def start():
 loop = asyncio.get_event_loop()
 proc = await create_ffmpeg_subprocess()
 task_stdout = loop.create_task(write_stdin(proc))
 await asyncio.gather(task_stdout)

if __name__ == '__main__':
 asyncio.run(start())



The output for the async code is :


pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.



etc - one line for each webp file