
Recherche avancée
Autres articles (105)
-
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...) -
Gestion des droits de création et d’édition des objets
8 février 2011, parPar défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;
-
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 (11017)
-
Revision 49231 : google plus one
2 juillet 2011, par yaquoi@… — Loggoogle plus one
-
ffmpeg not reading string correctly in Swift MacOS app
21 octobre 2019, par NCrusherI’m so close to having a working app that does a simple audio conversion calling ffmpeg but I’m stuck on what appears to be the silliest error.
in the Console, ffmpeg prints the following error when I try to run the conversion :
"Unrecognized option ’c copy’. Error splitting the argument list :
Option not found"Which is strange because that’s not the argument I’m giving it. My method for producing the string it’s getting its argument from is as follows :
func conversionSelection() {
if inputFileUrl != nil {
let conversionChoice = conversionOptionsPopup.indexOfSelectedItem
switch conversionChoice {
case 1 :
outputExtension = ".mp3"
ffmpegFilters = "-c:a libmp3lame -ac 1 -ar 22050 -q:a 9"
case 2 :
outputExtension = ".mp3"
ffmpegFilters = "-c:a libmp3lame -ac 2 -ar 44100 -q:a 5"
case 3 :
outputExtension = ".mp3"
ffmpegFilters = "-c:a libmp3lame -ac 1 -ar 22050 -b:a 32k"
case 4:
outputExtension = ".flac"
ffmpegFilters = "-c:a flac"
default :
outputExtension = ".m4b"
ffmpegFilters = "-c copy"
}
}
}Then the code I use to launch ffmpeg is as follows :
func ffmpegConvert(inputPath: String, filters: String, outputPath: String) {
guard let launchPath = Bundle.main.path(forResource: "ffmpeg", ofType: "") else { return }
do {
let compressTask: Process = Process()
compressTask.launchPath = launchPath
compressTask.arguments = [
"-y",
"-i", inputPath,
filters,
outputPath
]
compressTask.standardInput = FileHandle.nullDevice
compressTask.launch()
compressTask.waitUntilExit()
}
}Which I call when my "Start Conversion" button is clicked :
@IBAction func startConversionClicked(_ sender: Any) {
ffmpegConvert(inputPath: inputFilePath, filters: ffmpegFilters, outputPath: outputFilePath)
}(
inputFilePath
andoutputFilePath
are strings obviously generated by other methods which appear to be working fine.)So it appears the only obstacle to my having a working app here is that for some reason, I’m losing that hyphen at the start of the
ffmpegFilters
string.How is that happening and what do I need to do to fix it ?
EDIT : Having tried the basic script I’m trying to create in XCode from the Terminal, I realized I’d forgotten to take into account the fact that paths with spaces in them need to have the spaces converted to "\ ". So that may actually be the cause and the error is misleading ? Which is strange because ffmpeg gives me the exact error in Terminal so maybe not ?
FURTHER EDIT : Upon further experimentation, I discovered it would recognize the hyphen at the beginning of the argument string as long as I used two hyphens—which I should have realized sooner because duh, mathematical operator, just like && and ==.
But it’s still telling me
Unrecognized option '-c copy'
which really makes no sense, because "-c copy" is definitely a valid ffmpeg argument.I tried converting the file paths with the .addingPercentEncoding option, and it was still giving me the error about the argument rather than saying the file/directory being invalid, so either XCode was already passing a perfectly formatted file path string to ffmpeg, or ffmpeg is too busy complaining about the invalid argument to get around to telling me I have an invalid path.
AND A STILL FURTHER EDIT : I’m still battering my head against this issue, because I’m convinced it’s going to be something stupid and minor. I’m just throwing things at the wall and seeing what sticks.
I put a whitespace at the beginning of the arguments string inside my quotes for the filters argument (so it reads
" -c copy"
instead of"-c copy"
) and that seemed to make a little headway. It actually read the metadata of my input file before telling me :Unable to find a suitable output format for ’ -c copy’
-c copy : Invalid argumentWhich suggests to me that the issue is that the method for stringing together all the strings might not be either putting (or not putting ?) whitespace between the adjacent strings where appropriate ?
Because of course a whitespace needs to go between the inputFilePath string and the
ffmpegFilters
string. A whitespace also needs to go between theffmpegFilters
string and theoutputFilePath
string, but NOT between the individual components comprising the output string.If that’s the issue, it’s actually going to a little tough to troubleshoot at my current level of understanding, because the output path is composed of different components derived from different methods.
This is the method I use to pull it all together, which yields a string that gets displayed in a text field, and also provides the
outputFilePath
I use in theffmpegConvert
process.func updateOutputText(outputString: String, outputField: NSTextField) {
if inputFileUrl != nil && outputDirectoryUrl == nil {
// derive output path and filename from input and tack on a new extension if a different output format is chosen
let outputFileUrl = inputFileUrl!.deletingPathExtension()
let outputPath = outputFileUrl.path
outputFilePath = outputPath + "\(outputExtension)"
} else if inputFileUrl != nil && outputDirectoryUrl != nil {
// derive output directory from outputBrowseButton action, derive filename from input file, and derive output extension from conversion format selection
let outputFile = inputFileUrl!.deletingPathExtension()
let outputFilename = outputFile.lastPathComponent
let outputDirectory = outputDirectoryPath
outputFilePath = outputDirectory + "/" + outputFilename + "\(outputExtension)"
}
outputTextDisplay.stringValue = outputFilePath
}From the error ffmpeg kicked back this time, either there’s NOT a space between the
ffmpegFilters
string and theoutputFilePath
string, or there IS an unwanted space between theoutputFilename
and"\(outputExtension)"
components of theoutputFilePath
string.And it’s such a strangely put together string that I’m not sure what to do if that’s the case.
-
Swift - Workaround/Alternative to M3u8 to play mp4 segment or merge segments into mp4
14 mai 2020, par STerrierI used AVAssetExportSession to download a session URL but the issue that you can't download live stream so to get around it, the live stream is split into 10 seconds mp4 segments that are downloaded using an m3u8 to create the URLs. I then use AVAssetExportSession to merge those mp4 segments.



I can merge those clips one by one into one mp4 file which is what I want but as the file gets bigger, the longer it takes as I am dealing with thousands of segments which becomes unpractical.



I thought about using AVplayerLooper but I cannot scrub, rewind or forward through the mp4 segment like a single video.



Is there a way to combine the mp4 clips together to play as one video as the m3u8 does without merging ? or is there a fast way to merge videos ?



Note : The server uses FFmpeg but I am not allowed to use FFmpeg or pods in the app.



below is the function to merge videos



var mp4Array: [AVAsset] = []
var avAssetExportSession: AVAssetExportSession?

var firstAsset: AVAsset?
var secondAsset: AVAsset?

func mergeVideos() {

 firstAsset = mp4Array.first
 secondAsset = mp4Array[1]

 guard let firstAsset = firstAsset, let secondAsset = secondAsset else { return }
 let mixComposition = AVMutableComposition()

 guard let firstTrack = mixComposition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)) else {return}

 do {

 try firstTrack.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: firstAsset.duration),
 of: firstAsset.tracks(withMediaType: .video)[0],
 at: CMTime.zero)

 } catch {
 print("Couldn't load track 1")
 return
 }

 guard let secondTrack = mixComposition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)) else {return}

 do {
 try secondTrack.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: secondAsset.duration),
 of: secondAsset.tracks(withMediaType: .video)[0],
 at: firstAsset.duration)
 } catch {
 print("couldn't load track 2")
 return
 }

 let mainInstruction = AVMutableVideoCompositionInstruction()
 mainInstruction.timeRange = CMTimeRangeMake(start: CMTime.zero, duration: CMTimeAdd(firstAsset.duration, secondAsset.duration))

 let firstAssetInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: firstTrack)
 firstAssetInstruction.setOpacity(0.0, at: firstAsset.duration)

 let secondAssetInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: secondTrack)

 mainInstruction.layerInstructions = [firstAssetInstruction, secondAssetInstruction]
 let mainComposition = AVMutableVideoComposition()
 mainComposition.instructions = [mainInstruction]
 mainComposition.frameDuration = CMTimeMake(value: 1, timescale: 30)
 mainComposition.renderSize = firstTrack.naturalSize

 guard let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
 let url = documentDirectory.appendingPathComponent("MergedVideos/mergeVideo\(videoInt).mp4")

 guard let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality) else {return}

 exporter.outputURL = url
 exporter.outputFileType = AVFileType.mp4
 exporter.shouldOptimizeForNetworkUse = true
 exporter.videoComposition = mainComposition

 exporter.exportAsynchronously {

 if exporter.status == .completed {
 let avasset = AVAsset(url:url)
 self.mergeUrl = avasset
 if self.mp4Array.count > 1{
 print("This add the merged video to the front of the mp4array")
 self.mp4Array.remove(at: 1)
 self.mp4Array.removeFirst()
 self.videoInt = self.videoInt + 1
 self.mp4Array.append(self.mergeUrl!)
 self.mp4Array.bringToFront(item: self.mp4Array.last!)
 }

 if (self.mp4Array.count > 1){
 if self.mergeUrl != nil {
 self.mergeVideos()
 }
 } else {
 var numberofvideosdeleted = 0
 while (numberofvideosdeleted < self.videoInt - 1){
 do {
 print("deleting")
 let url = documentDirectory.appendingPathComponent("MergedVideos/mergeVideo\(numberofvideosdeleted).mp4")
 try FileManager.default.removeItem(at: url)
 numberofvideosdeleted = numberofvideosdeleted + 1
 } catch {
 print("Error removing videos")
 }
 }

 self.deleteCurrentSegementsInFolder()
 }
 }
 }
}