
Recherche avancée
Médias (1)
-
Richard Stallman et le logiciel libre
19 octobre 2011, par
Mis à jour : Mai 2013
Langue : français
Type : Texte
Autres articles (111)
-
Script d’installation automatique de MediaSPIP
25 avril 2011, parAfin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
La documentation de l’utilisation du script d’installation (...) -
Les notifications de la ferme
1er décembre 2010, parAfin d’assurer une gestion correcte de la ferme, il est nécessaire de notifier plusieurs choses lors d’actions spécifiques à la fois à l’utilisateur mais également à l’ensemble des administrateurs de la ferme.
Les notifications de changement de statut
Lors d’un changement de statut d’une instance, l’ensemble des administrateurs de la ferme doivent être notifiés de cette modification ainsi que l’utilisateur administrateur de l’instance.
À la demande d’un canal
Passage au statut "publie"
Passage au (...) -
Initialisation de MediaSPIP (préconfiguration)
20 février 2010, parLors de l’installation de MediaSPIP, celui-ci est préconfiguré pour les usages les plus fréquents.
Cette préconfiguration est réalisée par un plugin activé par défaut et non désactivable appelé MediaSPIP Init.
Ce plugin sert à préconfigurer de manière correcte chaque instance de MediaSPIP. Il doit donc être placé dans le dossier plugins-dist/ du site ou de la ferme pour être installé par défaut avant de pouvoir utiliser le site.
Dans un premier temps il active ou désactive des options de SPIP qui ne le (...)
Sur d’autres sites (8768)
-
Combine mp4 files by order based on number from filenames in Python
14 décembre 2022, par ah bonI try to merge lots of
mp4
files from a directorytest
into oneoutput.mp4
usingffmpeg
in Python.

import os

path = '/Users/x/Documents/test'

for filename in os.listdir(path):
 if filename.endswith(".mp4"):
 print(filename)



Output :


4. 04-unix,minix,Linux.mp4
6. 05-Linux.mp4
7. 06-ls.mp4
5. 04-unix.mp4
9. 08-command.mp4
1. 01-intro.mp4
3. 03-os.mp4
8. 07-minux.mp4
2. 02-os.mp4
10. 09-help.mp4



I have tried with the solution below from the reference here : ffmpy concatenate multiple files with a file list


import os
import subprocess
import time


base_dir = "/path/to/the/files"
video_files = "video_list.txt"
output_file = "output.avi"

# where to seek the files
file_list = open(video_files, "w")

# remove prior output
try:
 os.remove(output_file)
except OSError:
 pass

# scan for the video files
start = time.time()
for root, dirs, files in os.walk(base_dir):
 for video in files:
 if video.endswith(".avi"):
 file_list.write("file './%s'\n" % video)
file_list.close()

# merge the video files
cmd = ["ffmpeg",
 "-f",
 "concat",
 "-safe",
 "0",
 "-loglevel",
 "quiet",
 "-i",
 "%s" % video_files,
 "-c",
 "copy",
 "%s" % output_file
 ]

p = subprocess.Popen(cmd, stdin=subprocess.PIPE)

fout = p.stdin
fout.close()
p.wait()

print(p.returncode)
if p.returncode != 0:
 raise subprocess.CalledProcessError(p.returncode, cmd)

end = time.time()
print("Merging the files took", end - start, "seconds.")



I have merged them and get an
output.mp4
but the files are not merged in order with the first number split by point (1, 2, 3, ...
) : which I can get byfilename.split(".")[0]
:

1. 01-intro.mp4
2. 02-os.mp4
3. 03-os.mp4
4. 04-unix,minix,Linux.mp4
5. 04-unix.mp4
6. 05-Linux.mp4
7. 06-ls.mp4
8. 07-minux.mp4
9. 08-command.mp4
10. 09-help.mp4



How can I merge them correctly and concisely in Python ? Thanks.


-
Python script fails execution on subprocess.run() call only when called from context menu
10 mars 2019, par Jesse McDonaldI have a python script that I want to call from the windows file browser context menu (https://www.howtogeek.com/107965/how-to-add-any-application-shortcut-to-windows-explorers-context-menu/)
I am currently debugging calling it from the non-specific context (HKEY_CLASSES_ROOT\Directory\Background\shell) with the command "python "D :\toolbox\mineAudio.py" 0"
(note python3 is on the path as python and the script is at D :\toolbox\mineAudio.py)When I call the script from cmd it works as expected with that command, and when I make debug modifications to the script (adding os.system("pause") to random lines) I can verify it is running correctly up to the point it hits the line
meta=cmd(['ffmpeg','-i',target])
(line 46) where it instantly and silently fails (note ffmpeg is also on the path)EDIT : it actually gets as far as line 15
result = subprocess.run(command, stdout=subprocess.PIPE,stderr=subprocess.PIPE,startupinfo=startupinfo)
I cant figure out why the program is failing there as that line works fine everywhere else I have tested the script from other than the context menu.
Here is the full script if you want to brows through it
import subprocess
import os
import sys
from sys import argv
from tree import tree
#for command line use:
#mineAudo.py [prompt=1] [dir=cwd]
#first arg prompt will prompt user for dir if 1, otherwise it wont
#second arg is the directory to use, if specified this will override prompt, if not and prompt=0, current working dir is used
def cmd(command):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
result = subprocess.run(command, stdout=subprocess.PIPE,stderr=subprocess.PIPE,startupinfo=startupinfo)
return result.stderr.decode("utf-8")
def stripStreams(meta):
i=1;
lines=[]
while i>0 :
i=meta.find("Stream",i+1)
lineEnd=meta.find("\n",i)
lines.append(meta[i:lineEnd])
return lines
def mineAudio(streams):
ret=[]
for stream in streams:
if "Audio:" in stream:
start =stream.find("#")+1
end=stream.find("(",start)
ret.append(stream[start:end])
return ret
def convDir(dirTarget):
targets=tree(dirTarget)
convList(targets,dirTarget)
def convList(targets,dirTarget):
print(targets)
#target="2018-05-31 06-16-39.mp4"
i=0
for target in targets:
i+=1
if(target[target.rfind("."):]==".mp4"):
print("("+str(i)+"/"+str(len(targets))+") starting file "+target)
meta=cmd(['ffmpeg','-i',target])
streams=stripStreams(meta)
streams=mineAudio(streams)
count=0
output=target[target.rfind("/")+1:target.rfind(".")]
file=target[target.rfind("/")+1:]
#print (output)
try:
os.mkdir(dirTarget+"\\"+output)
except:
pass
for s in streams:
print("converting track "+str(count+1)+" of "+str(len(streams)));
count+=1
cmd("ffmpeg -i \""+target+"\" -vn -sn -c:a mp3 -ab 192k -map "+s+" \""+dirTarget+"\\"+output+"\\"+output+" Track "+str(count)+".mp3\"")
print("moving "+target+" to "+dirTarget+"\\"+output+"\\"+file)
os.rename(target,dirTarget+"\\"+output+"\\"+file)
print("Finished file "+target)
else:
print("("+str(i)+"/"+str(len(targets))+") skiping non mp4 file "+target)
def prompt():
while True:
dirTarget=input("input target dir: ")
convDir(dirTarget)
if __name__ == "__main__":
sys.setrecursionlimit(2000)
if len(argv)>2:
if os.path.isdir(argv[2]):
convDir(argv[2])
else:
convList([argv[2]],os.path.dirname(argv[2]))
elif(len(argv)>1):
if int(argv[1])==1:
prompt()
else:
convDir(os.getcwd())
else:
prompt()
os.system("pause")Note that I am not married to this particular implementation, any implementation with the same effect (extracting the .mp3 tracks from an .mp4 file automatically) would be fine too
also, here is the file Tree
#Returns the paths of all files in a directory and all sub directories relative to start directory
import os
def tree(directory,target="f"):
paths=[]
for currentDir,dirs,files in os.walk(directory):
if target=="f":
for file in files:
paths.append(currentDir+"/"+file)
if target=="d":
#paths.append(currentDir)
for dir in dirs:
paths.append(currentDir+"/"+dir)
for i in range(len(paths)):
paths[i]=paths[i].replace("\\","/")
return pathsCan anyone help me get this working ?
Edit :
here is a shorter example code that crashes in the same way (still uses ffmpeg though)import subprocess
import os
def cmd(command):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
result = subprocess.run(command,stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,stderr=subprocess.PIPE,startupinfo=startupinfo)
return result.stderr.decode("utf-8")
os.system("pause")
out=cmd(['ffmpeg','-i','D:\\ffmpeg test\\test\\2018-05-31 06-16-39\\2018-05-31 06-16-39.mp4'])
print(out)
os.system("pause") -
Merge mp4 files in order based on number from filenames in Python
7 juillet 2019, par ahbonI try to merge lots of
mp4
files from a directorytest
into oneoutput.mp4
usingffmpeg
in Python.path = '/Users/x/Documents/test'
import os
for filename in os.listdir(path):
if filename.endswith(".mp4"):
print(filename)Output :
4. 04-unix,minix,Linux.mp4
6. 05-Linux.mp4
7. 06-ls.mp4
5. 04-unix.mp4
9. 08-command.mp4
1. 01-intro.mp4
3. 03-os.mp4
8. 07-minux.mp4
2. 02-os.mp4
10. 09-help.mp4I have tried with the solution below from the reference here : ffmpy concatenate multiple files with a file list
import os
import subprocess
import time
base_dir = "/path/to/the/files"
video_files = "video_list.txt"
output_file = "output.avi"
# where to seek the files
file_list = open(video_files, "w")
# remove prior output
try:
os.remove(output_file)
except OSError:
pass
# scan for the video files
start = time.time()
for root, dirs, files in os.walk(base_dir):
for video in files:
if video.endswith(".avi"):
file_list.write("file './%s'\n" % video)
file_list.close()
# merge the video files
cmd = ["ffmpeg",
"-f",
"concat",
"-safe",
"0",
"-loglevel",
"quiet",
"-i",
"%s" % video_files,
"-c",
"copy",
"%s" % output_file
]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
fout = p.stdin
fout.close()
p.wait()
print(p.returncode)
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, cmd)
end = time.time()
print("Merging the files took", end - start, "seconds.")I have merged them and get an
output.mp4
but the files are not merged in order with the first number split by point (1, 2, 3, ...
) : which I can get byfilename.split(".")[0]
:1. 01-intro.mp4
2. 02-os.mp4
3. 03-os.mp4
4. 04-unix,minix,Linux.mp4
5. 04-unix.mp4
6. 05-Linux.mp4
7. 06-ls.mp4
8. 07-minux.mp4
9. 08-command.mp4
10. 09-help.mp4How can I merge them correctly and concisely in Python ? Thanks.