sunlubo / SwiftFFmpeg

A Swift wrapper for the FFmpeg API
Apache License 2.0
521 stars 83 forks source link

Muxing a chapter metadata file #39

Closed NCrusher74 closed 4 years ago

NCrusher74 commented 4 years ago

I'm new to using SwiftFFmpeg and I'm having trouble translating the basic FFmpeg terminal commands for use with SwiftFFMpeg.

What I need to do is very basic and straightforward. Following this process, I want to create chapter metadata, formatted like so:

;FFMETADATA1
title=MyVideo

[CHAPTER]
TIMEBASE=1/1000
START=0
#chapter ends at 00:30
END=30000
title=Chapter 1

[STREAM]
title=MyVideo

and then mux it into a file using these command-line arguments:

ffmpeg -i MyVideo.mp4 -i metadata -map_metadata 1 MyVideo_1.mp4

How would I accomplish that?

sunlubo commented 4 years ago

Use AVFormatContext.chapters.

  let formatContext = try AVFormatContext(format: nil, filename: output)
  formatContext.chapters = [
    AVChapter(id: 0, timeBase: AVRational(num: 1, den: 1000), start: 0, end: 2000, metadata: ["title": "Chapter 1"]),
    AVChapter(id: 1, timeBase: AVRational(num: 1, den: 1000), start: 2000, end: 4000, metadata: ["title": "Chapter 2"]),
    AVChapter(id: 2, timeBase: AVRational(num: 1, den: 1000), start: 4000, end: 10000, metadata: ["title": "Chapter 3"]),
  ]
NCrusher74 commented 4 years ago

Thank you so much!

NCrusher74 commented 4 years ago

I'm sorry, upon experimenting with this, AVChapter isn't being recognized as a valid identifier. Do I need to import something other than just SwiftFFmpeg?

sunlubo commented 4 years ago

The AVChapter related API was just added yesterday, maybe you need to update the dependency.

NCrusher74 commented 4 years ago

Thank you so much!