
Recherche avancée
Médias (91)
-
Spitfire Parade - Crisis
15 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Wired NextMusic
14 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
-
Video d’abeille en portrait
14 mai 2011, par
Mis à jour : Février 2012
Langue : français
Type : Video
-
Sintel MP4 Surround 5.1 Full
13 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
-
Carte de Schillerkiez
13 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
-
Publier une image simplement
13 avril 2011, par ,
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (82)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
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 -
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 (14235)
-
How does FFMPEG command works in the following code ?
3 août 2021, par Tariq HussainHow does FFMPEG working here ?


import sys, os, pdb
import numpy as np
import subprocess
from tqdm import tqdm
 

def extract(vid_dir, frame_dir, start, end, redo=False):
 class_list = sorted(os.listdir(vid_dir))[start:end]

 print("Classes =", class_list)
 
 for ic,cls in enumerate(class_list): 
 vlist = sorted(os.listdir(vid_dir + cls))
 print("")
 print(ic+1, len(class_list), cls, len(vlist))
 print("")
 for v in tqdm(vlist):
 outdir = os.path.join(frame_dir, cls, v[:-4])
 
 # Checking if frames already extracted
 if os.path.isfile( os.path.join(outdir, 'done') ) and not redo: continue
 try: 
 os.system('mkdir -p "%s"'%(outdir))
 # check if horizontal or vertical scaling factor
 o = subprocess.check_output('ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 "%s"'%(os.path.join(vid_dir, cls, v)), shell=True).decode('utf-8')
 lines = o.splitlines()
 width = int(lines[0].split('=')[1])
 height = int(lines[1].split('=')[1])
 resize_str = '-1:256' if width>height else '256:-1'

 # extract frames
 os.system('ffmpeg -i "%s" -r 25 -q:v 2 -vf "scale=%s" "%s" > /dev/null 2>&1'%( os.path.join(vid_dir, cls, v), resize_str, os.path.join(outdir, '%05d.jpg')))
 nframes = len([ fname for fname in os.listdir(outdir) if fname.endswith('.jpg') and len(fname)==9])
 if nframes==0: raise Exception 

 os.system('touch "%s"'%(os.path.join(outdir, 'done') ))
 except:
 print("ERROR", cls, v)

if __name__ == '__main__':
 vid_dir = sys.argv[1]
 frame_dir = sys.argv[2]
 start = int(sys.argv[3])
 end = int(sys.argv[4])
 extract(vid_dir, frame_dir, start, end, redo=True)

os.system('ffmpeg -i "%s" -r 25 -q:v 2 -vf "scale=%s" "%s" > /dev/null 2>&1'%( os.path.join(vid_dir, cls, v), resize_str, os.path.join(outdir, '%05d.jpg')))



-i —> Input_file (320x240)


-r —> frame rate (it will extract 25 frame of every video)


-q —> what does this mean ?


"scale=%s —> Unable to understand this ? how does this work for -1:256 ratio [will it resize the video to 256x256 dimension] ?


Can anyone explain me this ?


-
Python script doesn't work properly when ran through terminal, but works fine in Jupyter and Visual Studio
21 octobre 2018, par Ivan NovikovI have a script to extract the audio from all video files in a folder.
The folder with videos is located at : /Users/MyName/Downloads/Video_Audio_files
When I try to run it through terminal and I’m prompted for the folder path
folder = input("Path to folder:")
, I drag and drop it there (which is how I got the above path), but the script doesn’t seem to be working (stuck at 0 out of 7 and no output files).When I input exactly the same path when prompted in Jupyter Notebook or in Visual Studio it works perfectly !
Edit : I think I have found the issue, when I drag and drop the folder, there is an extra space (’Downloads/folder ’ instead of ’Downloads/folder’).
pbar = ProgressBar()
files = []
extensions = []
folder = input("Path to folder:")
#folder = 'Video_Audio_files'
pathlist = Path(folder).glob('**/*.mp4')
for path in pathlist:
path_in_str = str(path)
name = path_in_str.split("/")[1]
files.append(path_in_str.split(".")[0])
extensions.append(path_in_str.split(".")[1])
os.system('cd ' + folder)
for i in pbar(range(len(files))):
video_format = extensions[i]
video_name = files[i]
output_format = 'flac'
output_name = video_name + '_audio'
bashCommand = 'ffmpeg -i ' + video_name + '.' + video_format + ' -f ' + output_format + ' -ab 192000 -vn ' + output_name + '.' + output_format
#should be of this format: bashCommand = 'ffmpeg -i Video.mp4 -f flac -ab 192000 -vn ExtractedAudio.flac'
os.system(bashCommand) -
Running ffmpeg on cmd works, but integrating it with PHP gives out an error
11 juin 2022, par digiboyRunning ffmpeg to covert files to mp4 works normally when ran from a command line prompt, but
upon trying to integrate it into a php code I keep getting errors and I am not sure why that is. The error says :


'-i' is not recognized as an internal or external command,
operable program or batch file.
Upload failed 



This is the function that is responsible for running ffmpeg code that converts the file :


public function convertVideoToMp4($tempFilePath, $finalFilePath) {
 $cmd = "$this->ffmpegPath -i $tempFilePath $finalFilePath 2>&1";

 $outputLog = array();
 exec($cmd, $outputLog, $returnCode);

 if($returnCode != 0) {
 //Command failed
 foreach($outputLog as $line) {
 echo $line . "<br />";
 }
 return false;
 }

 return true;
}



and since my code is returning an error pointing to a command line command being faulty, I am guessing it is triggering the
echo $line . "<br />";
from the function above.
However, right under this error output, I have an errorUpload failed

which points to a different function in the program, mainly the one responsible for the upload of the file itself :

if(move_uploaded_file($videoData["tmp_name"], $tempFilePath)) {
 $finalFilePath = $targetDir . uniqid() . ".mp4";

 if(!$this->insertVideoData($videoUploadData, $finalFilePath)) {
 echo "Insert query failed\n";
 return false;
 }

 if(!$this->convertVideoToMp4($tempFilePath, $finalFilePath)) {
 echo "Upload failed\n";
 return false;
 }

 if(!$this->deleteFile($tempFilePath)) {
 echo "Upload failed\n";
 return false;
 }

 if(!$this->generateThumbnails($finalFilePath)) {
 echo "Upload failed - could not generate thumbnails\n";
 return false;
 }

 }



But even though I get the output saying Upload failed, my file DOES get transfered into the folder that is dedicated as the "Upload folder" but the file is NOT converted from flv to mp4 before being uploaded, so I am left very confused.


For those who are wondering what the whole code looks like, this is VideoProcessor.php :


<?php
class VideoProcessor {

 private $con;
 private $sizeLimit = 500000000;
 private $allowedTypes = array("mp4", "flv", "webm", "mkv", "vob", "ogv", "ogg", "avi", "wmv", "mov", "mpeg", "mpg");

 private $ffmpegPath;

 private $ffprobePath;

 public function __construct($con) {
 $this->con = $con;
 $this->ffmpegPath = realpath("C:\Program Files\ffmpeg\bin\ffmpeg");
 $this->ffprobePath = realpath("C:\Program Files\ffmpeg\bin\ffprobe");

 }

 public function upload($videoUploadData) {

 $targetDir = "uploads/videos/";
 $videoData = $videoUploadData->videoDataArray;

 $tempFilePath = $targetDir . uniqid() . basename($videoData["name"]);
 $tempFilePath = str_replace(" ", "_", $tempFilePath);

 $isValidData = $this->processData($videoData, $tempFilePath);

 if(!$isValidData) {
 return false;
 }

 if(move_uploaded_file($videoData["tmp_name"], $tempFilePath)) {
 $finalFilePath = $targetDir . uniqid() . ".mp4";

 if(!$this->insertVideoData($videoUploadData, $finalFilePath)) {
 echo "Insert query failed\n";
 return false;
 }

 if(!$this->convertVideoToMp4($tempFilePath, $finalFilePath)) {
 echo "Upload failed\n";
 return false;
 }

 if(!$this->deleteFile($tempFilePath)) {
 echo "Upload failed\n";
 return false;
 }

 if(!$this->generateThumbnails($finalFilePath)) {
 echo "Upload failed - could not generate thumbnails\n";
 return false;
 }

 }
 }

 private function processData($videoData, $filePath) {
 $videoType = pathInfo($filePath, PATHINFO_EXTENSION);

 if(!$this->isValidSize($videoData)) {
 echo "File too large. Can't be more than " . $this->sizeLimit . " bytes";
 return false;
 }
 else if(!$this->isValidType($videoType)) {
 echo "Invalid file type";
 return false;
 }
 else if($this->hasError($videoData)) {
 echo "Error code: " . $videoData["error"];
 return false;
 }

 return true;
 }

 private function isValidSize($data) {
 return $data["size"] <= $this->sizeLimit;
 }

 private function isValidType($type) {
 $lowercased = strtolower($type);
 return in_array($lowercased, $this->allowedTypes);
 }

 private function hasError($data) {
 return $data["error"] != 0;
 }

 private function insertVideoData($uploadData, $filePath) {
 $query = $this->con->prepare("INSERT INTO videos(title, uploadedBy, description, privacy, category, filePath)
 VALUES(:title, :uploadedBy, :description, :privacy, :category, :filePath)");

 $query->bindParam(":title", $uploadData->title);
 $query->bindParam(":uploadedBy", $uploadData->uploadedBy);
 $query->bindParam(":description", $uploadData->description);
 $query->bindParam(":privacy", $uploadData->privacy);
 $query->bindParam(":category", $uploadData->category);
 $query->bindParam(":filePath", $filePath);

 return $query->execute();
 }

 public function convertVideoToMp4($tempFilePath, $finalFilePath) {
 $cmd = "$this->ffmpegPath -i $tempFilePath $finalFilePath 2>&1";

 $outputLog = array();
 exec($cmd, $outputLog, $returnCode);

 if($returnCode != 0) {
 //Command failed
 foreach($outputLog as $line) {
 echo $line . "<br />";
 }
 return false;
 }

 return true;
 }

 private function deleteFile($filePath) {
 if(!unlink($filePath)) {
 echo "Could not delete file\n";
 return false;
 }

 return true;
 }

 public function generateThumbnails($filePath) {

 $thumbnailSize = "210x118";
 $numThumbnails = 3;
 $pathToThumbnail = "uploads/videos/thumbnails";

 $duration = $this->getVideoDuration($filePath);

 echo "duration: $duration";
 }

 private function getVideoDuration($filePath) {
 return shell_exec("$this->ffprobePath -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $filePath");
 }
}
?>