
Recherche avancée
Autres articles (64)
-
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 ;
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Contribute to a better visual interface
13 avril 2011MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.
Sur d’autres sites (4655)
-
How to check live stream is still alive use "ffprobe" command ?
17 août 2018, par Yin JianFengI want to schedule a job script to check a live stream is still alive use "ffprobe" command. So that I can change database state for those steam already dead.
I tried the command :
ffprobe -v quiet -print_format json -show_streams rtmp://xxxx
but when the stream is not avaiable, the command will hang.
I tried add -timeout argument, but still cannot work properly. -
Pause a FFmpeg encoding in a Python Popen subprocess on Windows
5 décembre 2020, par CasualDemonI am trying to pause an encode of FFmpeg while it is in a non-shell subprocess (This is important to how it plays into a larger program). This can be done by presssing the "Pause / Break" key on the keyboard by itself, and I am trying to send that to Popen.


The command itself must be cross platform compatible, so I cannot wrap it in any way, but I can send signals or run functions that are platform specific as needed.


I looked at how to send a "Ctrl+Break" to a subprocess via pid or handler and it suggested to send a signal, but that raised a "ValueError : Unsupported signal : 21"


from subprocess import Popen, PIPE
import signal


if __name__ == '__main__':
 command = "ffmpeg.exe -y -i example_video.mkv -map 0:v -c:v libx265 -preset slow -crf 18 output.mkv"
 proc = Popen(command, stdin=PIPE, shell=False)

 try:
 proc.send_signal(signal.SIGBREAK)
 finally:
 proc.wait()



Then attempted to use GenerateConsoleCtrlEvent to create a Ctrl+Break event as described here https://docs.microsoft.com/en-us/windows/console/generateconsolectrlevent


from subprocess import Popen, PIPE
import ctypes


if __name__ == '__main__':
 command = "ffmpeg.exe -y -i example_video.mkv -map 0:v -c:v libx265 -preset slow -crf 18 output.mkv"
 proc = Popen(command, stdin=PIPE, shell=False)

 try:
 ctypes.windll.kernel32.GenerateConsoleCtrlEvent(1, proc.pid)
 finally:
 proc.wait()



I have tried
psutil
pause feature, but it keeps the CPU load really high even when "paused".

Even though it wouldn't work with the program overall, I have at least tried setting
creationflags=CREATE_NEW_PROCESS_GROUP
which makes the SIGBREAK not error, but also not pause it. For the Ctrl-Break event will entirely stop the encode instead of pausing it.

-
Python opencv ffmpeg threading exit functions
29 novembre 2020, par scacchii'm trying to finish the audio/video recording loop by pressing a key (or by other event), if i use the simple time.sleep() in the main loop work perfectly, after 5 second stop video and create file, if i use the function keyboard_pressed() doesnt execute stop_AVrecording() correctly and file_manager().
What's im doing wrong ?
Thanks in advance


from __future__ import print_function, division
import numpy as np
import cv2
import pyaudio
import wave
import threading
import time
import subprocess
import os
import keyboard

class VideoRecorder:
 "Video class based on openCV"
 def __init__(self, name="temp_video.avi", fourcc="MJPG", sizex=640, sizey=480, fps=30):
 self.open = True
 self.fps = fps # fps should be the minimum constant rate at which the camera can
 self.fourcc = fourcc # capture images (with no decrease in speed over time; testing is required)
 self.frameSize = (sizex, sizey) # video formats and sizes also depend and vary according to the camera used
 self.video_filename = name
 self.video_cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
 self.video_writer = cv2.VideoWriter_fourcc(*self.fourcc)
 self.video_out = cv2.VideoWriter(self.video_filename, self.video_writer, self.fps, self.frameSize)
 self.frame_counts = 1
 self.start_time = time.time()

 def record(self):
 "Video starts being recorded"
 counter = 1
 timer_start = time.time()
 timer_current = 0
 while self.open:
 ret, video_frame = self.video_cap.read()
 if ret:
 self.video_out.write(video_frame)
 # print(str(counter) + " " + str(self.frame_counts) + " frames written " + str(timer_current))
 self.frame_counts += 1
 counter += 1
 timer_current = time.time() - timer_start
 #time.sleep(1/self.fps)
 # gray = cv2.cvtColor(video_frame, cv2.COLOR_BGR2GRAY)
 cv2.imshow('video_frame', video_frame)
 cv2.waitKey(1)
 else:
 break

 def stop(self):
 "Finishes the video recording therefore the thread too"
 if self.open:
 self.open=False
 self.video_out.release()
 self.video_cap.release()
 cv2.destroyAllWindows()

 def start(self):
 "Launches the video recording function using a thread"
 video_thread = threading.Thread(target=self.record)
 video_thread.start()

class AudioRecorder():
 "Audio class based on pyAudio and Wave"
 def __init__(self, filename="temp_audio.wav", rate=44100, fpb=1024, channels=2):
 self.open = True
 self.rate = rate
 self.frames_per_buffer = fpb
 self.channels = channels
 self.format = pyaudio.paInt16
 self.audio_filename = filename
 self.audio = pyaudio.PyAudio()
 self.stream = self.audio.open(format=self.format,
 channels=self.channels,
 rate=self.rate,
 input=True,
 frames_per_buffer = self.frames_per_buffer)
 self.audio_frames = []

 def record(self):
 "Audio starts being recorded"
 self.stream.start_stream()
 while self.open:
 data = self.stream.read(self.frames_per_buffer)
 self.audio_frames.append(data)
 if not self.open:
 break

 def stop(self):
 "Finishes the audio recording therefore the thread too"
 if self.open:
 self.open = False
 self.stream.stop_stream()
 self.stream.close()
 self.audio.terminate()
 waveFile = wave.open(self.audio_filename, 'wb')
 waveFile.setnchannels(self.channels)
 waveFile.setsampwidth(self.audio.get_sample_size(self.format))
 waveFile.setframerate(self.rate)
 waveFile.writeframes(b''.join(self.audio_frames))
 waveFile.close()

 def start(self):
 "Launches the audio recording function using a thread"
 audio_thread = threading.Thread(target=self.record)
 audio_thread.start()

def start_AVrecording(filename="test"):
 global video_thread
 global audio_thread
 video_thread = VideoRecorder()
 audio_thread = AudioRecorder()
 audio_thread.start()
 video_thread.start()
 return filename


def start_video_recording(filename="test"):
 global video_thread
 video_thread = VideoRecorder()
 video_thread.start()
 return filename

def start_audio_recording(filename="test"):
 global audio_thread
 audio_thread = AudioRecorder()
 audio_thread.start()
 return filename

def stop_AVrecording(filename="test"):
 audio_thread.stop()
 frame_counts = video_thread.frame_counts
 elapsed_time = time.time() - video_thread.start_time
 recorded_fps = frame_counts / elapsed_time
 print("total frames " + str(frame_counts))
 print("elapsed time " + str(elapsed_time))
 print("recorded fps " + str(recorded_fps))
 video_thread.stop()

 # Makes sure the threads have finished
 while threading.active_count() > 1:
 time.sleep(1)

 # Merging audio and video signal
 if abs(recorded_fps - 6) >= 0.01: # If the fps rate was higher/lower than expected, re-encode it to the expected
 print("Re-encoding")
 cmd = "ffmpeg -r " + str(recorded_fps) + " -i temp_video.avi -pix_fmt yuv420p -r 6 temp_video2.avi"
 subprocess.call(cmd, shell=True)
 print("Muxing")
 cmd = "ffmpeg -y -ac 2 -channel_layout stereo -i temp_audio.wav -i temp_video2.avi -pix_fmt yuv420p " + filename + ".avi"
 subprocess.call(cmd, shell=True)
 else:
 print("Normal recording\nMuxing")
 cmd = "ffmpeg -y -ac 2 -channel_layout stereo -i temp_audio.wav -i temp_video.avi -pix_fmt yuv420p " + filename + ".avi"
 subprocess.call(cmd, shell=True)
 print("..")

def file_manager(filename="test"):
 "Required and wanted processing of final files"
 local_path = os.getcwd()
 if os.path.exists(str(local_path) + "/temp_audio.wav"):
 os.remove(str(local_path) + "/temp_audio.wav")
 if os.path.exists(str(local_path) + "/temp_video.avi"):
 os.remove(str(local_path) + "/temp_video.avi")
 if os.path.exists(str(local_path) + "/temp_video2.avi"):
 os.remove(str(local_path) + "/temp_video2.avi")
 # if os.path.exists(str(local_path) + "/" + filename + ".avi"):
 # os.remove(str(local_path) + "/" + filename + ".avi")

def keyboard_pressed():
 while True:
 if keyboard.is_pressed('q'): # if key 'q' is pressed
 print('------------You Pressed Q Key!--------------')
 #time.sleep(5)
 break


if __name__ == '__main__':
 start_AVrecording()
 #time.sleep(5)
 keyboard_pressed()
 print('-------------Time Sleep-------------------')
 time.sleep(5)
 print('-------------Stop AVrecording-------------')
 stop_AVrecording()
 print('-------------File Manager-----------------')
 file_manager()
 print('-----------------End----------------------')



'''