
Recherche avancée
Autres articles (105)
-
La sauvegarde automatique de canaux SPIP
1er avril 2010, parDans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...) -
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 (...) -
Utilisation et configuration du script
19 janvier 2011, parInformations spécifiques à la distribution Debian
Si vous utilisez cette distribution, vous devrez activer les dépôts "debian-multimedia" comme expliqué ici :
Depuis la version 0.3.1 du script, le dépôt peut être automatiquement activé à la suite d’une question.
Récupération du script
Le script d’installation peut être récupéré de deux manières différentes.
Via svn en utilisant la commande pour récupérer le code source à jour :
svn co (...)
Sur d’autres sites (10915)
-
FFMPEG With PHP Upload
27 décembre 2014, par Will S.I’ve created an upload form that uses Ajax to dynamically upload image files to my webserver, and then uses shell_exec and ffmpeg to resize the images (and convert them to jpg, if they are already the correct size), and then save the resulting file. I’m getting really strange behaviour with it. It works about 50% of the time (so far I’ve only tested with JPG and PNG files). Whenever it fails, I get this results :
ffmpeg version 2.5.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Dec 23 2014 16:55:38 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration:
libavutil 54. 15.100 / 54. 15.100
libavcodec 56. 13.100 / 56. 13.100
libavformat 56. 15.102 / 56. 15.102
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
/tmp/phpU0pnje: Invalid data found when processing inputHere’s the PHP code :
if ($file_info[0] == 'image'){
$image_info = getimagesize($_FILES['upload_media_hidden']['tmp_name'][$i]);
$longest_edge = ($image_info[0] > $image_info[1]) ? $image_info[0] : $image_info[1];
$aspect_ratio = $image_info[0]/$image_info[1];
$aspect_ratio_s = ($image_info[0] > $image_info[1]) ? '200x' . (int)(200/$aspect_ratio) : (int)(200*$aspect_ratio) . 'x200';
$aspect_ratio_m = ($image_info[0] > $image_info[1]) ? '400x' . (int)(400/$aspect_ratio) : (int)(400*$aspect_ratio) . 'x400';
$aspect_ratio_l = ($image_info[0] > $image_info[1]) ? '700x' . (int)(700/$aspect_ratio) : (int)(700*$aspect_ratio) . 'x700';
if ($longest_edge > 200){
$file_s = shell_exec('ffmpeg -i ' . escapeshellarg($_FILES['upload_media_hidden']['tmp_name'][$i]) . ' -f image2 -s ' . $aspect_ratio_s . ' - 2>&1');
}
................more processing belowSo the ffmpeg command essentially looks like this :
ffmpeg -i ’SOMEFILE.jpg’ -f image2 -s 400x200 -
When I run that command in bash to the actual file (not the temporary file when I upload it to my form), it works fine. I’m guessing the issue is with the pipe, but I’m not sure. Any ideas ?
Thanks !
Update :
When I run this code :if ($file_info[0] == 'image'){
$image_info = getimagesize($_FILES['upload_media_hidden']['tmp_name'][$i]);
$longest_edge = ($image_info[0] > $image_info[1]) ? $image_info[0] : $image_info[1];
$aspect_ratio = $image_info[0]/$image_info[1];
$aspect_ratio_s = ($image_info[0] > $image_info[1]) ? '200x' . (int)(200/$aspect_ratio) : (int)(200*$aspect_ratio) . 'x200';
$aspect_ratio_m = ($image_info[0] > $image_info[1]) ? '400x' . (int)(400/$aspect_ratio) : (int)(400*$aspect_ratio) . 'x400';
$aspect_ratio_l = ($image_info[0] > $image_info[1]) ? '700x' . (int)(700/$aspect_ratio) : (int)(700*$aspect_ratio) . 'x700';
if ($longest_edge > 200){
move_uploaded_file($_FILES['upload_media_hidden']['tmp_name'][$i],'/tmp/TEST.jpg');
system('ffmpeg -i /tmp/TEST.jpg -f image2 -s ' . $aspect_ratio_s . ' - 2>&1');
$file_s = system('ffmpeg -i ' . escapeshellarg($_FILES['upload_media_hidden']['tmp_name'][$i]) . ' -f image2 -s ' . $aspect_ratio_s . ' - 2>&1');I get this result from php :
ffmpeg version 2.5.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Dec 23 2014 16:55:38 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration:
libavutil 54. 15.100 / 54. 15.100
libavcodec 56. 13.100 / 56. 13.100
libavformat 56. 15.102 / 56. 15.102
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
Input #0, image2, from '/tmp/TEST.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 54530 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1024x1432 [SAR 1:1 DAR 128:179], 25 tbr, 25 tbn, 25 tbc
[swscaler @ 0x2bce0c0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'pipe:':
Metadata:
encoder : Lavf56.15.102
Stream #0:0: Video: mjpeg, yuvj420p(pc), 143x200 [SAR 25600:25597 DAR 128:179], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc56.13.100 mjpeg
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
�����JFIF��d�c������Lavc56.13.100����C�
----FILE OUTPUT...edited out for clarity---
���frame= 1 fps=0.0 q=3.7 Lsize=N/A time=00:00:00.04 bitrate=N/A
video:5kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
ffmpeg version 2.5.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Dec 23 2014 16:55:38 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration:
libavutil 54. 15.100 / 54. 15.100
libavcodec 56. 13.100 / 56. 13.100
libavformat 56. 15.102 / 56. 15.102
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
/tmp/phpxqYzHN: No such file or directory
/tmp/phpxqYzHN: No such file or directorySo it seems to work if I move the file first ? It’s really important that I don’t have any extra disk io, so this solution wouldn’t be acceptable...
SOLUTION :
So the problem was that ffmpeg was not able to recognize the input file type, since PHP’s tmp files don’t end with an extension (seems like a bug that ffmpeg looks at the extension rather than the internal mime type/headers). The solution was that I needed to add "-f image2" to the beginning of my command, so it ended up looking something like this :ffmpeg -f image2 -i '/tmp/PHP_TMP_FILE' -f image2 -s 400x200 -
Hopefully this will save someone the many hours it took me to figure this out...
-
Python-FFMPEG Corruption Problems
11 juillet 2023, par Gabriel Ruben GuzmanI'm repurposing some python code to generate gifs/mp4s showcasing nba player movements dot form. (With the 'frames' used in the gifs being generated by matplotlib).


The repo comes with two different functions for generating the gifs, watch_play and animate_play. Both of which use python command line functionalities to run ffmpeg and generate the mp4s.
I've been able to use the watch_play succesfully, bot every time I try using animate_play, which according to the documention is meant to be significantly faster than watch play, I run into the error showcased here.(I printed the cmd string being passed into the pipe, in the hopes it would make debugging easier)


I've tried generating gifs/mp4s of various size and added a decent bit of code to lessen the volume of data being processed. (I'm essentially repurposing the code just to generate clips, so I've been able to remove a lot of the pbp/tracking data logs to speed up the run time) But no matter what I've done, gotten some variation of the screenshotted error.


pipe: : corrupt input packet in stream 0
[rawvideo @ 0x55ccc0e2bb80] Invalid buffer size, packet size 691200 < expected frame_size 921600
Error while decoding stream #0:0 : Invalid argument


The code for animate_play


def animate_play(self, game_time=None, length=None, highlight_player=None,
 commentary=True, show_spacing=None):
 """
 Method for animating plays in game.
 Outputs video file of play in {cwd}/temp.
 Individual frames are streamed directly to ffmpeg without writing them
 to the disk, which is a great speed improvement over watch_play

 Args:
 game_time (int): time in game to start video
 (seconds into the game).
 Currently game_time can also be an tuple of length two
 with (starting_frame, ending_frame)if you want to
 watch a play using frames instead of game time.
 length (int): length of play to watch (seconds)
 highlight_player (str): If not None, video will highlight
 the circle of the inputed player for easy tracking.
 commentary (bool): Whether to include play-by-play commentary in
 the animation
 show_spacing (str) in ['home', 'away']: show convex hull
 spacing of home or away team.
 If None, does not show spacing.

 Returns: an instance of self, and outputs video file of play
 """
 if type(game_time) == tuple:
 starting_frame = game_time[0]
 ending_frame = game_time[1]
 else:
 game_time= self.start +(self.quarter*720)
 end_time= self.end +(self.quarter*720)
 length = end_time-game_time
 # Get starting and ending frame from requested 
 # game_time and length
 print('hit')
 print(len(self.moments))
 print(game_time)
 print(end_time)
 print(length)
 print(game_time+length)
 
 print(self.moments.game_time.min())
 print(self.moments.game_time.max())

 sys.exit()
 starting_frame = self.moments[self.moments.game_time.round() ==
 game_time].index.values[0]
 ending_frame = self.moments[self.moments.game_time.round() ==
 game_time + length].index.values[0]

 # Make video of each frame
 filename = "./temp/{game_time}.mp4".format(game_time=game_time)
 if commentary:
 size = (960, 960)
 else:
 size = (480, 480)
 cmdstring = ('ffmpeg',
 '-y', '-r', '20', # fps
 '-s', '%dx%d' % size, # size of image string
 '-pix_fmt', 'argb', # Stream argb data from matplotlib
 '-f', 'rawvideo','-i', '-',
 '-vcodec', 'libx264', filename)
 #print(pipe)
 #print(cmdstring)
 
 

 # Stream plots to pipe
 pipe = Popen(cmdstring, stdin=PIPE)
 print(cmdstring)
 for frame in range(starting_frame, ending_frame):
 print(frame)
 self.plot_frame(frame, highlight_player=highlight_player,
 commentary=commentary, show_spacing=show_spacing,
 pipe=pipe)
 print(cmdstring)
 pipe.stdin.close()
 pipe.wait()
 return self



The code for watch play


def watch_play(self, game_time=None, length=None, highlight_player=None,
 commentary=True, show_spacing=None):

 """
 DEPRECIATED. See animate_play() for similar (fastere) method

 Method for viewing plays in game.
 Outputs video file of play in {cwd}/temp

 Args:
 game_time (int): time in game to start video
 (seconds into the game).
 Currently game_time can also be an tuple of length
 two with (starting_frame, ending_frame) if you want
 to watch a play using frames instead of game time.
 length (int): length of play to watch (seconds)
 highlight_player (str): If not None, video will highlight
 the circle of the inputed player for easy tracking.
 commentary (bool): Whether to include play-by-play
 commentary underneath video
 show_spacing (str in ['home', 'away']): show convex hull
 of home or away team.
 if None, does not display any convex hull

 Returns: an instance of self, and outputs video file of play
 """
 print('hit this point ')
 warnings.warn(("watch_play is extremely slow. "
 "Use animate_play for similar functionality, "
 "but greater efficiency"))

 if type(game_time) == tuple:
 starting_frame = game_time[0]
 ending_frame = game_time[1]
 else:
 # Get starting and ending frame from requested game_time and length
 game_time= self.start +(self.quarter*720)
 end_time= self.end +(self.quarter*720)
 length = end_time-game_time


 starting_frame = self.moments[self.moments.game_time.round() ==
 game_time].index.values[0]
 ending_frame = self.moments[self.moments.game_time.round() ==
 game_time + length].index.values[0]
 #print(self.moments.head(2))
 #print(starting_frame)
 #print(ending_frame)
 print(len(self.moments))
 # Make video of each frame
 title = str(starting_frame)+'-'+str(ending_frame)
 for frame in range(starting_frame, ending_frame):
 print(frame)
 self.plot_frame(frame, highlight_player=highlight_player,
 commentary=commentary, show_spacing=show_spacing)
 command = ('ffmpeg -framerate 20 -start_number {starting_frame} '
 '-i %d.png -c:v libx264 -r 30 -pix_fmt yuv420p -vf '
 '"scale=trunc(iw/2)*2:trunc(ih/2)*2" {title}'
 '.mp4').format(starting_frame=starting_frame,title=title)
 os.chdir('temp')
 os.system(command)
 os.chdir('..')

 # Delete images
 for file in os.listdir('./temp'):
 if os.path.splitext(file)[1] == '.png':
 os.remove('./temp/{file}'.format(file=file))

 return self'



-
How to send time stamps to ffmpeg when encoding uncompressed video frames via stdin ?
7 août 2023, par SpacyI'm writing a C# application, but this question applies to any programming language.
I know it is possible to pass uncompressed video frames (in yuv420p format) via stdin to ffmpeg.exe, but I recorded these frames to RAM from a webcam that has a variable frame rate. I have the exact time stamps for each frame. How do I send the time stamps to ffmpeg.exe together with the uncompressed frame data ?


I would prefer if it was possible to send them within the stdin byte stream, but I could also provide them up front when invoking ffmpeg.exe (this might become a very long argument list though). I could also write them to a text file on disk if nothing else works.