【问题标题】:Can I Crop GIF like video?我可以像视频一样裁剪 GIF 吗?
【发布时间】:2016-09-13 04:08:14
【问题描述】:

我有裁剪视频的方法..

func cropVideo(sourceURL1: NSURL?, statTime:Float, endTime:Float)
    {

        let manager = NSFileManager.defaultManager()

        guard let documentDirectory = try? manager.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true) else {return}

        guard let url = sourceURL1 else {return}

            let asset = AVAsset(URL: url)
        print(asset)
            let length = Float(asset.duration.value) / 1000
            print("video length: \(length) seconds")

            let start = statTime
            let end = endTime
            var outputURL = documentDirectory.URLByAppendingPathComponent("output")
            do {
                try manager.createDirectoryAtURL(outputURL, withIntermediateDirectories: true, attributes: nil)
                outputURL = outputURL.URLByAppendingPathComponent("outPut.mov")
            }catch let error {
                print(error)
            }

            guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {return}
            exportSession.outputURL = outputURL
            exportSession.outputFileType = AVFileTypeMPEG4

            let startTime = CMTime(seconds: Double(start ?? 0), preferredTimescale: 1000)
            let endTime = CMTime(seconds: Double(end ?? length), preferredTimescale: 1000)
            let timeRange = CMTimeRange(start: startTime, end: endTime)

            exportSession.timeRange = timeRange
            exportSession.exportAsynchronouslyWithCompletionHandler{
                switch exportSession.status {
                case .Completed:
                    print("exported at \(outputURL)")

                case .Failed:
                    print("failed \(exportSession.error)")

                case .Cancelled:
                    print("cancelled \(exportSession.error)")

                default: break
                }
        }
    }

在这里,我得到长度 = 0.0 也得到文件不支持错误。有什么解决办法吗?或任何其他方法请告诉我...谢谢。

【问题讨论】:

    标签: ios swift video gif


    【解决方案1】:

    找到解决方案。实际上,我正在从视频中制作 Gif。

    所以我首先根据需要裁剪该视频,然后将裁剪后的视频转换为 GIF。

    解决了!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-29
      • 2014-04-07
      • 1970-01-01
      • 2013-12-22
      • 2011-03-24
      • 1970-01-01
      • 2012-05-15
      相关资源
      最近更新 更多