MP4-видео, созданные с помощью AVMutableComposition и AVAssetExportSession, работают в Quicktime, но выглядят поврежденными во всех других видеоинструментах. - PullRequest
0 голосов
/ 17 декабря 2018

Я пытаюсь редактировать сегменты нескольких фильмов вместе в один клип, используя Swift, AVFoundation и AVKit на macOS.Следующий код Swift является хорошим примером того, что я пытаюсь сделать:

import AVFoundation
import AVKit

let source1 = AVAsset(url: URL(string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")!)
let source2 = AVAsset(url: URL(string: "http://techslides.com/demos/sample-videos/small.mp4")!)

let comp = AVMutableComposition()

comp.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)
comp.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid)

func cmtime(_ i: Double) -> CMTime {
    return CMTime(seconds: i, preferredTimescale: 600)
}

func insertSecond(into: AVMutableComposition, from: AVAsset, start: CMTime, at: CMTime) throws {
    let videoTrack = into.tracks(withMediaType: .video).first!
    let audioTrack = into.tracks(withMediaType: .audio).first!
    try videoTrack.insertTimeRange(
        CMTimeRange(start: start , duration: cmtime(1.0)),
        of: from.tracks(withMediaType: .video).first!,
        at: at
    )
    try audioTrack.insertTimeRange(
        CMTimeRange(start: start, duration: cmtime(1.0)),
        of: from.tracks(withMediaType: .audio).first!,
        at: at
    )
}

try insertSecond(into: comp, from: source1, start: cmtime(3.0), at: cmtime(0.0))
try insertSecond(into: comp, from: source2, start: cmtime(2.0), at: cmtime(1.0))
try insertSecond(into: comp, from: source1, start: cmtime(100.0), at: cmtime(2.0))
try insertSecond(into: comp, from: source2, start: cmtime(3.0), at: cmtime(3.0))
try insertSecond(into: comp, from: source1, start: cmtime(350.0), at: cmtime(4.0))


if let sess = AVAssetExportSession(asset: comp, presetName: "AVAssetExportPresetHighestQuality") {
    sess.outputURL = URL(fileURLWithPath: "/tmp/output.mp4")
    sess.outputFileType = .mp4
    sess.exportAsynchronously {
        print("done")
        print(sess.error ?? "success")
    }
}

Запуск этого кода действительно приводит к созданию файла output.mp4, и этот файл может быть воспроизведен в Quicktime без проблем.Вы должны быть в состоянии вставить вышеуказанный код в игровую площадку для воспроизведения видео (исходные видео - это общедоступные примеры видео, размещенные в Интернете).Я также загрузил его на S3 здесь , так что вы можете загрузить и проанализировать его без необходимости запуска кода самостоятельно.

Однако, пытаясь открыть или обработать его с помощью любого другого видео программного обеспеченияприводит к ошибкам.

VLC попытается воспроизвести файл, но у него очень трудное время.Видео часто зависает, десинхронизируется со звуком, включает кадры, которые Quicktime вообще не показывает, и полностью пропускает некоторые разделы.

Firefox также пытается воспроизвести файл, но явно не может его декодироватьправильно и имеет глючный видеовыход.Chrome зависает после первой секунды воспроизведения.

Я попытался провести дальнейшую диагностику с помощью ffprobe и ffmpeg.

Запуск ffprobe -show_frames output.mp4 1>/dev/null показывает:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fe841801800] DTS -24000 < 24000 out of order
[h264 @ 0x7fe843022800] reference count overflow
[h264 @ 0x7fe843022800] decode_slice_header error
[h264 @ 0x7fe843022800] no frame!
[h264 @ 0x7fe843022800] deblocking_filter_idc 6 out of range
[h264 @ 0x7fe843022800] decode_slice_header error
[h264 @ 0x7fe843022800] no frame!
[h264 @ 0x7fe843022800] deblocking_filter_idc 6 out of range
[h264 @ 0x7fe843022800] decode_slice_header error
[h264 @ 0x7fe843022800] no frame!
[h264 @ 0x7fe843022800] top block unavailable for requested intra mode -1
[h264 @ 0x7fe843022800] error while decoding MB 5 0, bytestream 947
[h264 @ 0x7fe843022800] concealing 3600 DC, 3600 AC, 3600 MV errors in P frame
[h264 @ 0x7fe843022800] mmco: unref short failure
[h264 @ 0x7fe843022800] cabac_init_idc 4 overflow
[h264 @ 0x7fe843022800] decode_slice_header error
[h264 @ 0x7fe843022800] no frame!
[h264 @ 0x7fe843022800] deblocking filter parameters -43 0 out of range
[h264 @ 0x7fe843022800] decode_slice_header error
[h264 @ 0x7fe843022800] no frame!

Попыткадля перекодирования в другой формат с помощью ffmpeg (ffmpeg -i output.mp4 output.avi) есть много предупреждений и ошибок:

[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 73, current: 71; changing to 74. This may result in incorrect timestamps in the output file.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fe1f4802800] DTS -24000 < 24000 out of order
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 74, current: 72; changing to 75. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 75, current: 73; changing to 76. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 76, current: 74; changing to 77. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 77, current: 75; changing to 78. This may result in incorrect timestamps in the output file.
[h264 @ 0x7fe1f4849600] reference count overflow
[h264 @ 0x7fe1f4849600] decode_slice_header error
[h264 @ 0x7fe1f4849600] no frame!
Error while decoding stream #0:1: Invalid data found when processing input
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 145, current: 143; changing to 146. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 146, current: 144; changing to 147. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 147, current: 145; changing to 148. This may result in incorrect timestamps in the output file.
[h264 @ 0x7fe1f483d800] deblocking_filter_idc 6 out of range
[h264 @ 0x7fe1f483d800] decode_slice_header error
[h264 @ 0x7fe1f483d800] no frame!
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 148, current: 146; changing to 149. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 149, current: 147; changing to 150. This may result in incorrect timestamps in the output file.
[h264 @ 0x7fe1f4849600] deblocking_filter_idc 6 out of range
[h264 @ 0x7fe1f4849600] decode_slice_header error
[h264 @ 0x7fe1f4849600] no frame!
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 150, current: 148; changing to 151. This may result in incorrect timestamps in the output file.
Error while decoding stream #0:1: Invalid data found when processing input
    Last message repeated 1 times
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 151, current: 149; changing to 152. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 152, current: 150; changing to 153. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 153, current: 151; changing to 154. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 154, current: 152; changing to 155. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 155, current: 153; changing to 156. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 156, current: 154; changing to 157. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 157, current: 155; changing to 158. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 158, current: 156; changing to 159. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 159, current: 157; changing to 160. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 160, current: 158; changing to 161. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 161, current: 159; changing to 162. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 162, current: 160; changing to 163. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 163, current: 161; changing to 164. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 164, current: 162; changing to 165. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 165, current: 163; changing to 166. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 166, current: 164; changing to 167. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 167, current: 165; changing to 168. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 168, current: 166; changing to 169. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 169, current: 167; changing to 170. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 170, current: 168; changing to 171. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 171, current: 169; changing to 172. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 172, current: 170; changing to 173. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 173, current: 171; changing to 174. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 174, current: 172; changing to 175. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 175, current: 173; changing to 176. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 176, current: 174; changing to 177. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 177, current: 175; changing to 178. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 178, current: 176; changing to 179. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 179, current: 177; changing to 180. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 180, current: 178; changing to 181. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 181, current: 179; changing to 182. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 182, current: 180; changing to 183. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 183, current: 181; changing to 184. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 184, current: 182; changing to 185. This may result in incorrect timestamps in the output file.
[h264 @ 0x7fe1f483d800] top block unavailable for requested intra mode -1
[h264 @ 0x7fe1f483d800] error while decoding MB 5 0, bytestream 947
[h264 @ 0x7fe1f483d800] concealing 3600 DC, 3600 AC, 3600 MV errors in P frame
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 185, current: 183; changing to 186. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 186, current: 184; changing to 187. This may result in incorrect timestamps in the output file.
[h264 @ 0x7fe1f4849600] mmco: unref short failure
[h264 @ 0x7fe1f4849600] cabac_init_idc 4 overflow
[h264 @ 0x7fe1f4849600] decode_slice_header error
[h264 @ 0x7fe1f4849600] no frame!
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 187, current: 185; changing to 188. This may result in incorrect timestamps in the output file.
[h264 @ 0x7fe1f485fa00] deblocking filter parameters -43 0 out of range
[h264 @ 0x7fe1f485fa00] decode_slice_header error
[h264 @ 0x7fe1f485fa00] no frame!
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 188, current: 186; changing to 189. This may result in incorrect timestamps in the output file.
Error while decoding stream #0:1: Invalid data found when processing input
    Last message repeated 1 times
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 189, current: 187; changing to 190. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 190, current: 188; changing to 191. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 191, current: 189; changing to 192. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 192, current: 190; changing to 193. This may result in incorrect timestamps in the output file.
[avi @ 0x7fe1f5804e00] Non-monotonous DTS in output stream 0:1; previous: 193, current: 191; changing to 194. This may result in incorrect timestamps in the output file.

Приведенный выше код является лишь одним примером, я видел похожие проблемы с различной степенью серьезности в партияхвариаций в этом коде.Я пробовал много вещей, в том числе:

  • с использованием локальных URL-адресов файлов вместо URL-адресов HTTPS
  • с использованием .mov вместо .mp4 файлов
  • с использованием AVMovie и AVMutableMovie (и различные настройки, например, установив для AVURLAssetPreferPreciseDurationAndTimingKey значение true) вместо AVMutableComposition
  • настройки (предустановки и т. Д.) В AVAssetExportSession
  • конструирование CMTime объектов различными способами

, но безрезультатно - я не могу заставить AVFoundation создать видеофайл, который могут обрабатывать другие инструменты.

Любая помощьприветствую даже любые мысли о том, что необычно в кодировке выходного файла, которую вы можете скачать здесь , если вы не можете или не хотите запускать вышеуказанный код Swift, чтобы воспроизвести его самостоятельно.

Ответы [ 3 ]

0 голосов
/ 17 декабря 2018

Как говорит @RhythmicFistman, ваш видеопоток представляет собой совокупность нескольких потоков H264 с различными свойствами.Параметры потока H264 могут храниться, как правило, либо в полосе (называемой Приложением B), либо в глобальных метаданных при хранении в контейнере, подобном MP4 (stsd).AVF сделал здесь добавление нескольких записей stsd.

stsd: s=       326 (0x00000146), o=   1982552 (0x001e4058)
                      version: 0
                      flags: 0x000000
                      sample_descriptions (0x00000002):
                        size: 0000009b
                        data_format: avc1 (61 76 63 31)
                        ...
                        size: 0000009b
                        data_format: avc1 (61 76 63 31)
                        ...

Большинство проигрывателей игнорируют дополнительные записи, но декодер нуждается в этой конфигурации потока битов для (повторной) инициализации.

Существует два способаforward.

Повторное кодирование каждого отдельного сегмента с одинаковыми свойствами кодирования, так что постконкатное, отсутствие повторного запуска декодера фактически не является проблемой,

или

либополучите AVF или другой инструмент, такой как mp4box, для объединения потоков в виде потока avc3, в результате чего параметры потока битов также сохраняются внутри полосы.Декодер должен встретиться с новыми наборами параметров и переустановить.

0 голосов
/ 17 декабря 2018

Я согласен с тем, что проблемы с воспроизведением в других проигрывателях возникают из-за того, что в каждой дорожке больше описания форматаНо на самом деле нет необходимости в дорогом перекодировании треков перед компоновкой, AVFoundation может сделать это для вас ... если вы готовы перепрыгнуть через несколько обручей.

Ключ в том, что AVMutableCompositionможет иметь более одной дорожки определенного типа мультимедиа, и AVAssetExportSession может «микшировать» такие композиции до одной дорожки для каждого типа мультимедиа.Тип AVFoundation подтверждает проблему с несколькими описаниями форматов для каждой дорожки, предоставляя mutableTrackCompatibleWithTrack:.Поэтому, если вы хотите вставить сегмент из заданной исходной дорожки, вы можете запросить у AVMutableComposition подходящую целевую дорожку, а если ни одна не возвращается, добавьте новую.

Как уже упоминалось, есть нескольковещи, которые нужно иметь в виду:

  • вы не можете вставить в заданную дорожку назначения где-то в «пустое время» за ее текущим концом.Чтобы обойти это, обратите внимание на текущее время окончания дорожки назначения, добавьте сегмент в это время, а после этого вставьте пустой сегмент нужной продолжительности на прежнем конце дорожки.Пример ниже показывает это в упрощенном предположении, что вы всегда добавляете.Если вы хотите вставить что-либо в существующую дорожку, вам понадобится немного более продуманная логика.

  • , чтобы на самом деле иметь AVAssetExportSession для микширования всего до одной дорожки на носительтипа, вы должны установить AVAudioMix и AVVideoComposition в сеансе экспорта.

Пример кода ниже, на основе вашего исходного примера, создает файл output.mp4, который корректно воспроизводится в VLC,Chrome и Firefox и не выдает ошибок при проверке с помощью ffmpeg.

import AVFoundation
import Foundation

let source0 = AVAsset(url: URL(string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")!)
let source1 = AVAsset(url: URL(string: "http://techslides.com/demos/sample-videos/small.mp4")!)

let comp = AVMutableComposition()

func cmtime(_ i: Double) -> CMTime {
    return CMTime(seconds: i, preferredTimescale: 600)
}

func insertTrackSecond( srcAsset: AVAsset, dstComp: AVMutableComposition, mediaType: AVMediaType, start: CMTime, at: CMTime) throws {
    let srcTrack: AVAssetTrack = srcAsset.tracks(withMediaType: mediaType).first!

    // get a compatible destination track or, if not available, create a new one
    let dstTrack: AVMutableCompositionTrack = dstComp.mutableTrack(compatibleWith: srcTrack) ?? dstComp.addMutableTrack(withMediaType: mediaType, preferredTrackID: kCMPersistentTrackID_Invalid)!

    // can't insert into "void" time beyond the current end of track. Instead, note current end time, append there, and *after* appending, insert empty range
    var dstTrackEnd: CMTime = CMTimeRangeGetEnd( dstTrack.timeRange)
    if CMTIME_IS_INVALID( dstTrackEnd) {
        dstTrackEnd = kCMTimeZero
    }

    try dstTrack.insertTimeRange( CMTimeRangeMake( start, cmtime( 1.0)), of: srcTrack, at: dstTrackEnd)

    // now add empty range, if necessary
    if CMTimeCompare( dstTrackEnd, at) == -1 {
        dstTrack.insertEmptyTimeRange( CMTimeRangeFromTimeToTime( dstTrackEnd, at))
    }
}

func insertSecond( srcAsset: AVAsset, dstComp: AVMutableComposition, start: CMTime, at: CMTime) throws
{
    try insertTrackSecond(srcAsset: srcAsset, dstComp: dstComp, mediaType: .video, start: start, at: at)
    try insertTrackSecond(srcAsset: srcAsset, dstComp: dstComp, mediaType: .audio, start: start, at: at)
}

try insertSecond( srcAsset: source0, dstComp: comp, start: cmtime(3.0), at: cmtime(0.0))
try insertSecond( srcAsset: source1, dstComp: comp, start: cmtime(2.0), at: cmtime(1.0))
try insertSecond( srcAsset: source0, dstComp: comp, start: cmtime(100.0), at: cmtime(2.0))
try insertSecond( srcAsset: source1, dstComp: comp, start: cmtime(3.0), at: cmtime(3.0))
try insertSecond( srcAsset: source0, dstComp: comp, start: cmtime(350.0), at: cmtime(4.0))


if let sess = AVAssetExportSession(asset: comp, presetName: "AVAssetExportPresetHighestQuality") {
    sess.outputURL = URL(fileURLWithPath: "/tmp/output.mp4")
    sess.outputFileType = .mp4

    // this leaves smaller videotracks at the origin, in their "natural" size. Manipulate the "preferredTransform" property of the mutable composition tracks for nicer results
    sess.videoComposition = AVVideoComposition.init(propertiesOf: comp)

    // not assigning an audio mix results in an output with multiple audio tracks
    var inputParameters = [AVAudioMixInputParameters]()
    for audioTrack: AVAssetTrack in comp.tracks(withMediaType:.audio) {
        inputParameters.append( AVMutableAudioMixInputParameters.init(track:audioTrack))
    }
    let audioMix: AVMutableAudioMix = AVMutableAudioMix();
    audioMix.inputParameters = inputParameters;
    sess.audioMix = audioMix;

    let semaphore: DispatchSemaphore = DispatchSemaphore(value:0);

    sess.exportAsynchronously {
        print("done")
        print(sess.error ?? "success")
        semaphore.signal()
    }

    semaphore.wait()
}
0 голосов
/ 17 декабря 2018

Эта проблема почти наверняка связана с тем, что форматы клипов, как видео, так и аудио, не совпадают:

multiple video & audio formats

Есть много вещей AVAssetExportSessionмог бы сделать, но, кажется, решил сбросить все форматы, что, вероятно, объясняет ваши проблемы с совместимостью.Я понимаю, почему проигрыватель может быть сбит с толку, потому что два формата видео даже не имеют одинакового соотношения сторон.Возможно, это поведение является ошибкой, или, может быть, оно имеет смысл в какой-то ситуации.Я не знаю.

Так что вы можете:

  1. убедиться, что все ваши клипы имеют соответствующие форматы (мне нравится этот, и, возможно, вы не хотите, чтобы ваш прыжок с помощью мэшапа клипамежду стилями почтовых ящиков / изменениями соотношения сторон)
  2. для соответствия форматов используйте AVMutableVideoCompositionLayerInstruction + AVAssetExportSession или AVAssetReader + AVAssetWriter

ps Я подозреваю несоответствия видеоздесь важнее, чем аудио, поэтому, возможно, тестирование покажет, что вы можете игнорировать звук?

...