
Recherche avancée
Autres articles (16)
-
Que fait exactement ce script ?
18 janvier 2011, parCe script est écrit en bash. Il est donc facilement utilisable sur n’importe quel serveur.
Il n’est compatible qu’avec une liste de distributions précises (voir Liste des distributions compatibles).
Installation de dépendances de MediaSPIP
Son rôle principal est d’installer l’ensemble des dépendances logicielles nécessaires coté serveur à savoir :
Les outils de base pour pouvoir installer le reste des dépendances Les outils de développements : build-essential (via APT depuis les dépôts officiels) ; (...) -
Encodage et transformation en formats lisibles sur Internet
10 avril 2011MediaSPIP transforme et ré-encode les documents mis en ligne afin de les rendre lisibles sur Internet et automatiquement utilisables sans intervention du créateur de contenu.
Les vidéos sont automatiquement encodées dans les formats supportés par HTML5 : MP4, Ogv et WebM. La version "MP4" est également utilisée pour le lecteur flash de secours nécessaire aux anciens navigateurs.
Les documents audios sont également ré-encodés dans les deux formats utilisables par HTML5 :MP3 et Ogg. La version "MP3" (...) -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs
Sur d’autres sites (3382)
-
PyQt QGraphicsScene Render Scene As Video Format
28 mai 2024, par AlexI'm trying to allow the user to export the scene as an mp4 (video format), the items of the scene consists of QGraphicsVideoItem and multiple QGraphicsTextItem, I need to export the scene as it will allow the user to save the video with the text items. I've found one of the ways to do this but the issue is that it will take hours for a simple 5 seconds videos as it saves every image to a byte to create a video, every image is a millisecond. If I change from millisecond to seconds it could speed up but the video will not look as smooth, is there a more efficient way of doing this, without it taking so long ?


from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from PySide6.QtSvgWidgets import *
from PySide6.QtMultimediaWidgets import QGraphicsVideoItem
from PySide6.QtMultimedia import QMediaPlayer, QAudioOutput, QMediaMetaData 

import subprocess

import sys

class ExportVideo(QThread):
 def __init__(self, video_item, video_player, graphics_scene, graphics_view):
 super().__init__()
 self.video_item = video_item
 self.video_player = video_player
 self.graphics_scene = graphics_scene
 self.graphics_view = graphics_view
 
 def run(self):
 self.video_player.pause()
 duration = self.video_player.duration()
 meta = self.video_player.metaData()


 # Prepare a pipe for ffmpeg to write to
 ffmpeg_process = subprocess.Popen(['ffmpeg', '-y', '-f', 'image2pipe', '-r', '1000', '-i', '-', '-c:v', 'libx265', '-pix_fmt', 'yuv420p', 'output.mp4'], stdin=subprocess.PIPE)

 for duration in range(0, duration):
 self.video_player.setPosition(duration)

 # Add logic to render the frame here
 print("Exporting frame:", duration) 

 image = QImage(self.graphics_scene.sceneRect().size().toSize(), QImage.Format_ARGB32)
 painter = QPainter(image)
 self.graphics_scene.render(painter)
 painter.end()

 # Convert QImage to bytes
 byte_array = QByteArray()
 buffer = QBuffer(byte_array)
 buffer.open(QIODevice.WriteOnly)
 image.save(buffer, 'JPEG')

 # Write image bytes to ffmpeg process
 ffmpeg_process.stdin.write(byte_array.data())

 # Close the pipe to signal ffmpeg that all frames have been processed
 ffmpeg_process.stdin.close()
 ffmpeg_process.wait()


class PyVideoPlayer(QWidget):
 
 def __init__(self):
 super().__init__()

 self.text_data = []

 self.mediaPlayer = QMediaPlayer()
 self.audioOutput = QAudioOutput()

 self.graphics_view = QGraphicsView()
 self.graphic_scene = QGraphicsScene()

 self.graphics_view.setScene(self.graphic_scene)
 self.graphic_scene.setBackgroundBrush(Qt.black)
 self.graphics_view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
 self.graphics_view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

 self.video_item = QGraphicsVideoItem()
 self.graphic_scene.addItem(self.video_item)
 self.save_video = QPushButton()
 
 layout = QVBoxLayout()
 layout.addWidget(self.graphics_view, stretch=1)
 layout.addWidget(self.save_video)
 self.setLayout(layout)

 # Slots Section
 self.mediaPlayer.setVideoOutput(self.video_item)
 self.mediaPlayer.positionChanged.connect(self.changeVideoPosition)
 self.save_video.clicked.connect(self.saveVideo)

 def setMedia(self, fileName):
 self.mediaPlayer.setSource(QUrl.fromLocalFile(fileName))
 self.mediaPlayer.setAudioOutput(self.audioOutput)
 self.play()
 self.video_item.setSize(self.mediaPlayer.videoSink().videoSize())

 self.text_item = QGraphicsTextItem()
 self.text_item.setPlainText("Test Dummy")
 self.text_item.setDefaultTextColor(Qt.white)
 font = QFont()
 font.setPointSize(90) 
 self.text_item.setFont(font)
 self.text_item.setPos(self.graphic_scene.sceneRect().x() + self.text_item.boundingRect().width(), self.graphic_scene.sceneRect().center().y() - self.text_item.boundingRect().height())
 self.graphic_scene.addItem(self.text_item)
 self.text_data.append("Test Dummy")

 def play(self):
 if self.mediaPlayer.playbackState() == QMediaPlayer.PlaybackState.PlayingState:
 self.mediaPlayer.pause()
 else:
 self.mediaPlayer.play()

 def changeVideoPosition(self, duration):
 if duration > 1000 and self.text_item.isVisible():
 print("Hide Text")
 self.text_item.hide()

 def resize_graphic_scene(self):
 self.graphics_view.fitInView(self.graphic_scene.sceneRect(), Qt.KeepAspectRatio)

 def showEvent(self, event):
 self.resize_graphic_scene()

 def resizeEvent(self, event):
 self.resize_graphic_scene()

 def saveVideo(self):
 self.videoExport = ExportVideo(self.video_item, self.mediaPlayer, self.graphic_scene, self.graphics_view)
 self.videoExport.start()

 


if __name__ == "__main__":
 app = QApplication(sys.argv)
 window = PyVideoPlayer()
 window.setMedia("example.mp4")
 window.setGeometry(100, 100, 400, 300) # Set the window size
 window.setWindowTitle("QGraphicsView Example")
 window.show()
 sys.exit(app.exec())




- 

- EDIT : Changed from PNG to JPEG, it speeds up the image.save, I also get this issue :
Assertion fctx->async_lock failed at C:/ffmpeg-n6.0/libavcodec/pthread_frame.c:155.
I think it must have to do with setting the video player position.




- EDIT : Changed from PNG to JPEG, it speeds up the image.save, I also get this issue :
-
Anomalie #4562 : Suite #4468 : Unification des CSS pour les boutons et les icônes
9 octobre 2020, par RastaPopoulos ♥Pour SVP/Composer, de ce que je sais pour l’instant, on n’est pas encore prêt à avoir un truc complet, comprenant l’interface pour les lambdas. Car au delà de la structure des plugins et leurs dépendances (utiliser le json, composer), ya toujours que les gens doivent pouvoir chercher/récupérer/mettre à jour sans être admin sys, sans avoir accès au serveur, aux fichiers (sans même savoir comment ça marche l’hébergement), juste en étant admin d’un site et en voulant ajouter une fonctionnalité.
Or, en attendant d’avoir trouvé la super solution (cf les pistes qu’on avait dessiné lors de la formation composer), ya vraiment un gros bug ergonomique et même fonctionnel, en obligeant les gens à mettre à jour à la version la plus haute, sans leur montrer à la fois les mises à jour sécu/mineure et les mises à jour majeure, et en pouvant choisir à laquelle monter, et aussi en avertissant pour les majeures que c’est dangereux à vérifier (bref cf le ticket sur les mises à jour). Des gens pètent leur site avec ça, alors qu’ils auraient pu rester à une branche plus basse toujours maintenue (et ça oblige à faire des contorsions sur les plugins d’intégration de libs avec plusieurs préfixes donc plugins pour une même lib). Bref ça me semble au contraire plutôt urgent d’améliorer SVP car ça cause du soucis à pas mal de gens (tous ceux qui ne sont pas chez Nursit, et qui n’ont pas la liste des plugins déjà là bloquée, maintenue par d’autres :p )
-
FFMPEG library's some command not working on android
21 février 2014, par Saurabh PrajapatiI need following 2 commands to work on android platform. I found many article on this site where they inform these command works fine for them but it is not working at my end
For Fedding Effect :
"ffmpeg -i filename1 fade=in:5:8 output.mp4"For Concate Video Files :
"ffmpeg -i concat : filename1|filename2 -codec copy output.mp4"Error : App throws error like unknown command "concate" and "fad-in5:8".
My Goal : I need to concate 2 "mp4" video files on android platform with Fed In/Fed Out effects.
Following is my code
public class VideoTest extends Activity
public static final String LOGTAG = "MJPEG_FFMPEG";
byte[] previewCallbackBuffer;
boolean recording = false;
boolean previewRunning = false;
File jpegFile;
int fileCount = 0;
FileOutputStream fos;
BufferedOutputStream bos;
Button recordButton;
Camera.Parameters p;
NumberFormat fileCountFormatter = new DecimalFormat("00000");
String formattedFileCount;
ProcessVideo processVideo;
String[] libraryAssets = {"ffmpeg","ffmpeg.so",
"libavcodec.so", "libavcodec.so.52", "libavcodec.so.52.99.1",
"libavcore.so", "libavcore.so.0", "libavcore.so.0.16.0",
"libavdevice.so", "libavdevice.so.52", "libavdevice.so.52.2.2",
"libavfilter.so", "libavfilter.so.1", "libavfilter.so.1.69.0",
"libavformat.so", "libavformat.so.52", "libavformat.so.52.88.0",
"libavutil.so", "libavutil.so.50", "libavutil.so.50.34.0",
"libswscale.so", "libswscale.so.0", "libswscale.so.0.12.0"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for (int i = 0; i < libraryAssets.length; i++) {
try {
InputStream ffmpegInputStream = this.getAssets().open(libraryAssets[i]);
FileMover fm = new FileMover(ffmpegInputStream,"/data/data/com.mobvcasting.mjpegffmpeg/" + libraryAssets[i]);
fm.moveIt();
} catch (IOException e) {
e.printStackTrace();
}
}
Process process = null;
try {
String[] args = {"/system/bin/chmod", "755", "/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg"};
process = new ProcessBuilder(args).start();
try {
process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
process.destroy();
} catch (IOException e) {
e.printStackTrace();
}
File savePath = new File(Environment.getExternalStorageDirectory().getPath() + "/com.mobvcasting.mjpegffmpeg/");
savePath.mkdirs();
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
processVideo = new ProcessVideo();
processVideo.execute();
}
@Override
public void onConfigurationChanged(Configuration conf)
{
super.onConfigurationChanged(conf);
}
private class ProcessVideo extends AsyncTask {
@Override
protected Void doInBackground(Void... params) {
Log.d("test", "VideoTest doInBackground Start");
/*String videofile = Environment.getExternalStorageDirectory().getPath() + "/com.mobvcasting.mjpegffmpeg/splitter.mp4";
File file = new File(videofile);
if(file.exists())
file.delete();
file=null;*/
Process ffmpegProcess = null;
try {
String filename1 = Environment.getExternalStorageDirectory().getPath()+ "/com.mobvcasting.mjpegffmpeg/test.mp4";
String filename2 = Environment.getExternalStorageDirectory().getPath()+ "/com.mobvcasting.mjpegffmpeg/splitter.mp4";
String StartPath = Environment.getExternalStorageDirectory().getPath() + "/com.mobvcasting.mjpegffmpeg/";
//String[] ffmpegCommand = {"/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg", "-i", "concat:\""+ filename1+"|"+ filename2+"\"", "-codec", "copy", Environment.getExternalStorageDirectory().getPath() + "/com.mobvcasting.mjpegffmpeg/output.mp4"};
//String[] ffmpegCommand = {"/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg", "-i", filename1, "fade=in:5:8", Environment.getExternalStorageDirectory().getPath() + "/com.mobvcasting.mjpegffmpeg/output.mp4"};
ffmpegProcess = new ProcessBuilder(ffmpegCommand).redirectErrorStream(true).start();
OutputStream ffmpegOutStream = ffmpegProcess.getOutputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(ffmpegProcess.getInputStream()));
String line;
Log.d("test", "***Starting FFMPEG***");
while ((line = reader.readLine()) != null)
{
Log.d("test", "***"+line+"***");
}
Log.d("test", "***Ending FFMPEG***");
} catch (IOException e) {
e.printStackTrace();
}
if (ffmpegProcess != null) {
ffmpegProcess.destroy();
}
Log.d("test", "doInBackground End");
return null;
}
protected void onPostExecute(Void... result) {
Log.d("test", "onPostExecute");
Toast toast = Toast.makeText(VideoTest.this, "Done Processing Video", Toast.LENGTH_LONG);
toast.show();
}
}Just for your information, I have copy source from following library
https://github.com/pvskalyan/Android-MJPEG-Video-Capture-FFMPEG?source=c