
Recherche avancée
Autres articles (67)
-
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...) -
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 (...) -
Des sites réalisés avec MediaSPIP
2 mai 2011, parCette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.
Sur d’autres sites (4153)
-
Python cv2 script that scans a giant image to a video. Raises error : Unknown C++ exception from OpenCV code
26 avril 2022, par NolreneaI wrote a script that scans a giant image to make a video. Normally I just post my scripts straight to my Code Review account, but this script is ugly, needs to be refactored, implements only horizontal scrolling and contains a bug that I can't get rid of.


It is working but not perfect, I can't get the last line at the bottom of the image, with height of
image_height % 1080
. If I ignore it, the code is working fine, if I try to fix it, it throws exceptions.

Example :


Original image (Google Drive)


Video Output (Google Drive)


As you can see from the video, everything is working properly except the fact that I can't get the bottom line.


Full working code



import cv2
import numpy as np
import random
import rpack
from fractions import Fraction
from math import prod

def resize_guide(image_size, target_area):
 aspect_ratio = Fraction(*image_size).limit_denominator()
 horizontal = aspect_ratio.numerator
 vertical = aspect_ratio.denominator
 unit_length = (target_area/(horizontal*vertical))**.5
 return (int(horizontal*unit_length), int(vertical*unit_length))

fourcc = cv2.VideoWriter_fourcc(*'h264')
FRAME = np.zeros((1080, 1920, 3), dtype=np.uint8)

def new_frame():
 return np.ndarray.copy(FRAME)

def center(image):
 frame = new_frame()
 h, w = image.shape[:2]
 yoff = round((1080-h)/2)
 xoff = round((1920-w)/2)
 frame[yoff:yoff+h, xoff:xoff+w] = image
 return frame

def image_scanning(file, fps=60, pan_increment=64, horizontal_increment=8, fast_decrement=256):
 image = cv2.imread(file)
 height, width = image.shape[:2]
 assert width*height >= 1920*1080
 video_writer = cv2.VideoWriter(file+'.mp4', fourcc, fps, (1920, 1080))
 fit_height = True
 if height < 1080:
 width = width*1080/height
 image = cv2.resize(image, (width, 1080), interpolation = cv2.INTER_AREA)
 aspect_ratio = width / height
 zooming_needed = False
 if 4/9 <= aspect_ratio <= 16/9:
 new_width = round(width*1080/height)
 fit = cv2.resize(image, (new_width, 1080), interpolation = cv2.INTER_AREA)
 zooming_needed = True
 
 elif 16/9 < aspect_ratio <= 32/9:
 new_height = round(height*1920/width)
 fit = cv2.resize(image, (1920, new_height), interpolation = cv2.INTER_AREA)
 fit_height = False
 zooming_needed = True
 
 centered = center(fit)
 for i in range(fps):
 video_writer.write(centered)
 if fit_height:
 xoff = round((1920 - new_width)/2)
 while xoff:
 if xoff - pan_increment >= 0:
 xoff -= pan_increment
 else:
 xoff = 0
 frame = new_frame()
 frame[0:1080, xoff:xoff+new_width] = fit
 video_writer.write(frame)
 else:
 yoff = round((1080 - new_height)/2)
 while yoff:
 if yoff - pan_increment >= 0:
 yoff -= pan_increment
 else:
 yoff = 0
 frame = new_frame()
 frame[yoff:yoff+new_height, 0:1920] = fit
 video_writer.write(frame)
 
 if zooming_needed:
 if fit_height:
 width_1, height_1 = new_width, 1080
 else:
 width_1, height_1 = 1920, new_height
 new_area = width_1 * height_1
 original_area = width * height
 area_diff = original_area - new_area
 unit_diff = area_diff / fps
 for i in range(1, fps+1):
 zoomed = cv2.resize(image, resize_guide((width_1, height_1), new_area+unit_diff*i), interpolation=cv2.INTER_AREA)
 zheight, zwidth = zoomed.shape[:2]
 zheight = min(zheight, 1080)
 zwidth = min(zwidth, 1920)
 frame = new_frame()
 frame[0:zheight, 0:zwidth] = zoomed[0:zheight, 0:zwidth]
 video_writer.write(frame)
 y, x = 0, 0
 completed = False
 while y != height - 1080:
 x = 0
 while x != width - 1920:
 if x + horizontal_increment + 1920 <= width:
 x += horizontal_increment
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 else:
 x = width - 1920
 frame = image[y:y+1080, x:x+1920]
 for i in range(round(fps/3)):
 video_writer.write(frame)
 if y == height - 1080:
 completed = True
 while x != 0:
 if x - fast_decrement - 1920 >= 0:
 x -= fast_decrement
 else:
 x = 0
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 if y + 2160 <= height:
 y += 1080
 else:
 y = height - 1080
 cv2.destroyAllWindows()
 video_writer.release()
 del video_writer



The above the the code needed to produce the example video. It is working but the bottom line is missing.


Now if I change the last few lines to this :


if y + 2160 <= height:
 y += 1080
 else:
 y = height - 1080
 x = 0
 while x != width - 1920:
 if x + horizontal_increment + 1920 <= width:
 x += horizontal_increment
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 cv2.destroyAllWindows()
 video_writer.release()
 del video_writer



I expect it to include the bottom line, but it just throws exceptions instead :


OpenCV: FFMPEG: tag 0x34363268/'h264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
---------------------------------------------------------------------------
error Traceback (most recent call last)
 in <module>
----> 1 image_scanning("D:/collages/91f53ebcea2a.png")

 in image_scanning(file, fps, pan_increment, horizontal_increment, fast_decrement)
 122 x += horizontal_increment
 123 frame = image[y:y+1080, x:x+1920]
--> 124 video_writer.write(frame)
 125 cv2.destroyAllWindows()
 126 video_writer.release()

error: Unknown C++ exception from OpenCV code
</module>


(If you can't get the example code working I can't help you, but I am using Python 3.9.10 x64 on Windows 10, and I have this file : "C :\Windows\System32\openh264-1.8.0-win64.dll", the '.avi' format generates video files with Gibibytes (binary unit, not SI Gigabyte) of size)


How to get rid of the exception ?


-
Concatenating audio files and superimposing over video
25 avril 2022, par kahI'm trying to write a program that takes a bunch of videos from a folder, compiles them, and then takes another bunch of audio files from a folder and concatenates them to then overlay the combined audio on top of the final video (hope that makes sense). I'm able to process the videos into one final output video, but I keep running into trouble combining the audio. Below I've provided two small sections of code pertaining to audio comp, I'm using moviepy to process the videos and attempting to use it for audio as well.


songDirectory = './songs/'
songList = []
songs = []
audioclip=''

def makeCompilation():
 for filename in os.listdir(songDirectory):
 f = os.path.join(songDirectory, filename)
 if os.path.isfile(f) and filename.endswith(".mp3"):
 audioclip = moviepy.editor.AudioFileClip(f)
 songList.append(filename)


 for song in os.listdir(songDirectory):
 c = os.path.join(songDirectory, song)
 audio_clips = moviepy.editor.AudioFileClip(c)
 audio_output = moviepy.editor.concatenate_audioclips(audio_clips)
 finalClip = concatenate_videoclips(videos, method="compose")
 final_duration = finalClip.duration 
 final_audio_output = audio_output.set_duration(final_duration)
 final_output= finalClip.set_audio(final_audio_output).fx(afx.audio_fadein, 3.0)


 audio_path = "./songs/tempaudiofile.m4a"

 #print(description)
 # Create compilation
 final_output.write_videofile(outputFile, threads=8, temp_audiofile=audio_path, remove_temp=True, codec="libx264", audio_codec="aac")

 return description



The program appeared to be able to find the audio directory, but I needed to be able to use os.path.join(songDirectory, filename) to point directly to each mp3 file so I messed around with it until I got the above code. And when I attempted to iterate through songList, I, as expected, got an error saying that 'str' wasn't iterable, and other errors saying that 'str' has no attribute 'duration'. Essentially, all I need it to do is iterate though the input folder and combine the files by whatever means. Code currently returns the output :


🌲Free Fredobagz x Aflacko x Flint type beat - 'Default_Dance' [prod. kah]-jro0v6ogZ0Y.mp4
225.05
Total Length: 225.05
225.05
Traceback (most recent call last):
 File "/Users/daddyK/Desktop/comp_ bot/make_compilation3.py", line 127, in <module>
makeCompilation(path = "./videos/",
 File "/Users/daddyK/Desktop/comp_ bot/make_compilation3.py", line 110, in makeCompilation
audio_output = moviepy.editor.concatenate_audioclips(audio_clips)
 File "/Users/daddyK/Library/Python/3.10/lib/python/site-packages/moviepy/audio/AudioClip.py", line 315, in concatenate_audioclips
durations = [c.duration for c in clips]
TypeError: 'AudioFileClip' object is not iterable
</module>



At this point I'm a bit stumped, so if anybody could offer some insight as to what I should do to resolve the error and/or if I'm headed in the right direction code-wise I'd greatly appreciate it ! Sorry if the code doesn't make any sense I'll post the whole .py file if needed


-
Upload video in php without compress [closed]
23 avril 2022, par i0x4rMy brother @MARKUS_AO
He solved a problem, related to displaying messages after the upload is completed, but there is a problem, I was relying on dropzone as it does not compress the video that I want to upload to the server, and the ffmpeg code also does




I attached the code, I want in a simple way to upload a video completely without compression, as it used to do dropzone, I want any software or anything else for a problem, the goal is that the video is not under compress (it is preferable to upload only one video, not multiple)


<form action="so-upload-71955097" method="post" enctype="multipart/form-data">
 Select file to upload:
 <input type="file" />
 <input type="submit" value="Upload File" />
</form>

<?php
/* 
 MCVE for: https://stackoverflow.com/questions/71955097/how-to-show-result-after-uploaded-file-in-php
*/

//upload.php

$folder_name = 'tmp/';
// $tumb_name = 'thumb/';
// $imageext = '.png';

if(!empty($_FILES)) {

 $temp_file = $_FILES['file']['tmp_name'];
 $location = $folder_name . $_FILES['file']['name'];
 move_uploaded_file($temp_file, $location);
 $upload = $_FILES['file']['name'];
 $uploadStr = str_replace(" ", "\ ",$upload);
 $locationStr = str_replace(" ","\ ",$location);
 // $cmd = "ffmpeg -y -i {$locationStr} -ss 00:00:15 -vframes 1 thumb/{$uploadStr}.png 2>&1";
 // echo shell_exec($cmd);
 
 // These lines need to be *INSIDE* the "uploading" condition
 
 echo "The file " . $location . " has been uploaded";
 // not working
 echo "<br />";
 echo "The file " . $upload . " has been uploaded";
 // not working
 echo "<br />";
 echo "The file " . $uploadStr . " has been uploaded";
 // not working
 echo "<br />";
 echo "The file " . $locationStr . " has been uploaded";
}
?>



Edit :


In this project
https://github.com/AjayACST/PHP-Video-Uploader


It uploads high quality videos without reducing the quality or size of the video
and it appears in its original form without changes.


But the problem of the project :
The message "The file has been uploaded successfully and path" does not appear


So MARKUS AO its changes and the project became similar but Without the dropzone.js


which is characterized as fully uploading the video, unlike the traditional upload


I just need to integrate the dropzone library, and after the upload is complete, the message "The video file123.mov has been uploaded successfully" appears.


Maybe that needs ffmpeg
but that's attached to the code in the post that my brother MARKUS AO edited.