
Recherche avancée
Médias (2)
-
Core Media Video
4 avril 2013, par
Mis à jour : Juin 2013
Langue : français
Type : Video
-
Video d’abeille en portrait
14 mai 2011, par
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (50)
-
Personnaliser les catégories
21 juin 2013, parFormulaire de création d’une catégorie
Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
On peut modifier ce formulaire dans la partie :
Administration > Configuration des masques de formulaire.
Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...) -
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 -
Les tâches Cron régulières de la ferme
1er décembre 2010, parLa gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
Le super Cron (gestion_mutu_super_cron)
Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)
Sur d’autres sites (8186)
-
Popen subprocess giving wrong ffmpeg process ID when trying to close
28 octobre 2023, par GokuI'm trying to create a Video Management System application using
Python
andDjango
, that displays live camera stream and do video recording. For this, I add cameras using POST request and everything works fine.

But when I am required to update a camera's details, like IP address or password, then first I delete the camera and then create a new instance with same camera name. The problem I'm facing is that the process ID of the camera (
ffmpeg
instance here) is not updating, e.g. if initially the process ID was 10, then it remains 10 (in terminate() function in the code) even when I re-create the camera with new details but I do get new process ID in start() function.

Below is the code :


import subprocess
from subprocess import Popen
import os, sys
import threading
import time
from datetime import datetime
import pytz
import os, signal


"""This class is used to create camera objects to display live stream and recordings,
 it is also used to manage recordings files by deleting them at the given time"""
class CameraStream:
 
 def __init__(self, device_name, username, password, ip_address, storage_days):

 self.cam_name = device_name
 self.username = username
 self.password = password
 self.cam_ip = ip_address
 self.storage_days = storage_days
 self.p1 = None
 self.p2 = None
 self.p1_id = None
 self.p2_id = None

 self.recordings_list = []

 folder_name = f"videos/Recordings/{self.cam_name}"
 folder_name2 = f"videos/LiveStreams/{self.cam_name}"

 if not os.path.exists(folder_name):
 os.mkdir(folder_name)
 if not os.path.exists(folder_name2):
 os.mkdir(folder_name2)

 self.directory = folder_name

 t = threading.Thread(target=self.maintain_recordings, args=())
 t.start()

 self.live_stream = f"ffmpeg -fflags nobuffer -rtsp_transport tcp -i rtsp://{self.username}:{self.password}@{self.cam_ip}:554/stream1 -copyts -vcodec copy -acodec copy -hls_flags delete_segments+append_list -f hls -hls_time 6 -hls_list_size 5 -hls_segment_type mpegts -hls_segment_filename videos/LiveStreams/{self.cam_name}/%d.ts videos/LiveStreams/{self.cam_name}/index.m3u8".split(" ")
 self.recording = f"ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://{self.username}:{self.password}@{self.cam_ip}:554/stream1 -vcodec copy -acodec copy -f segment -reset_timestamps 1 -segment_time 1800 -segment_format mp4 -segment_atclocktime 1 -strftime 1 videos/Recordings/{self.cam_name}/%Y%m%dT%H%M%S.mp4".split(" ")

 self.start()


 def start(self):
 self.p1 = Popen(self.live_stream)
 self.p2 = Popen(self.recording)
 # self.p1.wait() # wait() is not letting the POST request to complete. Hence, using time.sleep() to get process id
 # self.p2.wait()
 time.sleep(2)
 self.p1_id = self.p1.pid
 self.p2_id = self.p2.pid
 print("In start func: ", self.p1_id, self.p2_id) # gives new process ID here

 def terminate_process(self):
 print("you have awakened me!")
 try:
 try:
 print("In terminate func: ", self.p1_id, self.p2_id) # gives older process ID here
 os.kill(int(self.p1_id), signal.SIGKILL)
 os.kill(int(self.p2_id), signal.SIGKILL)
 print("terminated by process id!")
 except:
 print("could not delete by process id!")
 try:
 self.p1.terminate()
 self.p2.terminate()
 print("terminated by terminate()")
 except:
 print("could not delete by terminate()")
 try:
 self.p1.kill()
 self.p2.kill()
 print("terminated by kill()")
 except:
 print("could not delete by kill()")
 except Exception as e:
 print("Failed to stop ffmpeg: ", e)



I think I'm making a mistake when deleting the
ffmpeg
subprocess but can't figure out what it is. Have tried many methods to stop/kill the subprocess but I'm still facing the problem.
I believe there is a problem with the terminate_process() function.

I'm deleting the object by using the
del
keyword, e.g.del
, maybe it's keeping the object in the memory but only destroying the reference to that object.

-
FFMPEG : Explain parameters of any codecs function pointers
7 juillet 2014, par ZaxI’m going through the article, How to integrate a codec in FFMPEG multimedia framework.
According to it, every codec needs to have 3 basic functions to be defined and these functions are assigned to function pointers of the structureAVCodec
.The 3 function pointers specified in the above article are :
.init -> takes care of allocations and other initializations
.close -> freeing the allocated memory and de-initializations
.decode -> frame by frame decoding.For the function pointer
.decode
, the function assigned is :static int cook_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size) {
...The details of these parameters are specified in the above article. However, in the latest code, when the same function is taken as an example, its declaration is as shown below :
static int cook_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)I need to perform some mapping operations on the memory. So, i request if anyone could kindly explain the above parameters in the function declarations. Also, which parameter has the input buffer for decoding the frame ? And after decoding a frame, to which parameter is the decoded frame mapped ?
-
"method DESCRIBE failed : 401 Unauthorized" in Ffmpeg, yet VLC accepts the exact same RTSP URL
30 septembre 2021, par IpsRichI've an RTSP URL that includes the username and password (i.e. of the form
rtsp://username:password@server:554/path
) and this works in VLC, but using this as an input to Ffmpeg, I get back the above DESCRIBE error and it aborts.

I wondered if it might be the version of Ffmpeg I've got, but I used a fresh one via Docker (
alfg/ffmpeg:latest
) and the result was the same.

Is there something I have to do, perhaps some extra information/hint I have to provide to Ffmpeg, to get it to accept the credentials and get past the DESCRIBE ? Or if it's the DESCRIBE bit that's the problem, can I get it to skip that (perhaps by providing all the source stream details manually) so that it doesn't fail ?


I'd hoped that this might be the same problem, but it's not - my URL is quoted and doesn't contain anything like
?
or*
.

(In case it has any bearing, I'm trying to take an RTSP stream that requires credentials, resize it on the fly using Ffmpeg, and "pipe" the new RTSP to RTSP Simple Server. Most of this I can do : it's just the credentials that are tripping me up.)


UPDATE : One thing I didn't mention previously (because it didn't seem relevant) is that the RTSP stream comes from Milestone's Open Network Bridge server. It seems that ONB does not now allow URLs containing credentials, although this does not explain why the same URL works in VLC. Perhaps VLC extracts the credentials and provides them another way ? I've a support case open on this to try to get to the bottom of it. I'll update here if I discover anything helpful...