Documentation ¶
Overview ¶
Package ffmpegsplit is for parsing chapter information from a multimedia file using FFProbe
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetReadChaptersCommandline ¶
GetReadChaptersCommandline function builds the list of arguments used for reading chapter information via 'ffprobe' from file 'infile'. Note: this function is called by ReadFile() - as such it is only useful for debug purposes.
Types ¶
type Chapter ¶
type Chapter struct { ID int `json:"id"` TimeBase string `json:"time_base"` // float or fixnum? Not needed anyways Start int `json:"start"` StartTime string `json:"start_time"` // float or fixnum? Not needed anyways End int `json:"end"` EndTime string `json:"end_time"` // float or fixnum? Not needed anyways Tags map[string]string `json:"tags"` }
Chapter represents a single chapter in ffprobe output JSON
type ChapterFilter ¶ added in v0.1.1
type ChapterFilter struct { Description string Filter ChapterFilterFunction }
ChapterFilter is a wrapper structure for the filtering functions; besides the filter function itself, it holds a description field for clarity. The description is not necessary for the filter function, but may help in debugging.
type ChapterFilterFunction ¶ added in v0.1.1
ChapterFilterFunction is a function that determines whether a chapter is to be processed or not. The function follows 'filter' semantics, i.e the chapter is to be skiped if the ChapterFilter function returns true.
type FFProbeOutput ¶
type FFProbeOutput struct { Chapters []Chapter `json:"chapters"` // contains filtered or unexported fields }
FFProbeOutput represents the JSON structure returned by ffprobe command
func ReadChapters ¶
func ReadChapters(infile string) (FFProbeOutput, error)
ReadChapters is an alias for ReadChaptersWiithContext(context.Background(), infile)
func ReadChaptersFromJSON ¶ added in v0.1.1
func ReadChaptersFromJSON(encoded []byte) (FFProbeOutput, error)
ReadChaptersFromJSON parses the given byte sequence into a struct FFProbeOutput.
func ReadChaptersWithContext ¶ added in v0.1.2
func ReadChaptersWithContext(ctx context.Context, infile string) (FFProbeOutput, error)
ReadChaptersWithContext collects chapter information from the given file 'infile' using ffprobe. Blocks until subprocess returns. On success, parses the output (JSON) and returns the information in struct FFProbeOutput. Otherwise returns the error produced by either exec.Cmd.Run or json.Decoder.Unmarshal.
Expects the program 'ffmpeg' to be somewhere in user's $PATH.
type InputFileMetadata ¶
type InputFileMetadata struct { Path string BaseNoExt string Extension string FFProbeOutput FFProbeOutput }
InputFileMetadata tepresents all important details of the input file. Produced by ReadFile().
func ReadFile ¶
func ReadFile(infile string) (InputFileMetadata, error)
ReadFile is an alias for ReadFileWithContext(context.Background(), infile)
func ReadFileWithContext ¶ added in v0.1.2
func ReadFileWithContext(ctx context.Context, infile string) (InputFileMetadata, error)
ReadFileWithContext reads file metadata of file at path 'infile'. The associated context is used for controlling the launched subprocesses
func (InputFileMetadata) ComputeWorkItems ¶
func (imeta InputFileMetadata) ComputeWorkItems(outdir string, opts OutFileOpts) ([]WorkItem, error)
ComputeWorkItems processes struct workItem for each chapter. The workItem shall contain all the necessary information in order to extract the chapter using ffmpeg. When the sequence of workItems have been produced, the final processing step can be performed by calling workItem.Process().
func (InputFileMetadata) NumChapters ¶
func (imeta InputFileMetadata) NumChapters() int
NumChapters returns the number of chapters found in the input file.
type OutFileOpts ¶
type OutFileOpts struct { // Place chapter title in output file name? (NOTE: Only if title is available) UseTitleInName bool // Place chapter title in output file metadata? (NOTE: Only if title is available) UseTitleInMeta bool // Place chapter number in output file metadata? UseChapterNumberInMeta bool // Adjusts the starting value of filename enumeration. Sometimes it // might make more sense to start enumeration from 1 instead of 0, for example. // Negative value tells the library to choose automatically. EnumOffset int // When chapter number is used in the filename, the number may be // left-padded with zeros in order to produce constant-width "column" of chapter numbers. // This has the advantage that files can now be sorted more easily by various *nix tools. // // This flag specifies how many leading zeros should in the filename enumeration, if at all. // Set value to <0 to let the library automatically compute the appropriate padding. // Set valut to 0 to disable padding // Otherwise, the value will determine the number of leading zeros. EnumPaddedWidth int // Use this output file extension instead of the input file extension. // // WARNING: if the default file container type associated with this new extension // is incompatible with the input code, ffmpeg most likely will re-encode // the audio stream to something that IS compatible; all the parameters for // the conversion are chosen by ffmpeg (currently this library provides no support // for specifying the output codec parameters, this may change in the // future...). UseAlternateExtension string // Filters is a list of user-definable functions for filtering chapters. // To add filter, use method AddFilter(). Filters []ChapterFilter }
OutFileOpts contains user-defined options specifying how the output files will be named and what kind of metadata they shall contain (if metadata even is available in the original input file).
func DefaultOutFileOpts ¶
func DefaultOutFileOpts() OutFileOpts
DefaultOutFileOpts returns some sensible set of default values for OutFileOpts.
func (*OutFileOpts) AddFilter ¶ added in v0.1.1
func (opts *OutFileOpts) AddFilter(flt ChapterFilter)
AddFilter appends appends a filter to the list of filters in the OutFileOpts struct
func (OutFileOpts) IsFiltered ¶ added in v0.1.1
func (opts OutFileOpts) IsFiltered(ch Chapter) bool
IsFiltered invokes all configured filters for the given Chapter. If any of the filters return true, the function returns true. In other words, IsFiltered() returns false iff all the filters return false for the chapter.
type Status ¶
Status describes how many chapter extractions succeeded and how many failed. Note that successful + failed should equal submitted, otherwise an error happened somewhere.
func Process ¶
Process all workItems, i.e. do the actual extraction process. The workItems contain all the necessary information for the extractions to be performed. The processing happens in parallel, using at most 'maxConcurrent' ffmpeg worker processes.
Note: the extraction process does not re-encode the audio stream, thus the processing performance is not likely CPU-bound. However, using too many workers extracting the same file may saturate I/O, decreasing overall performance. In summary: increasing 'maxConcurrent' value may improve performance, but only up to a point.
TODO: add similar processin interface with support for context.Context (use exec.CommandContext?)
type WorkItem ¶ added in v0.1.1
type WorkItem struct { Infile string Outfile string OutDirectory string Chapter Chapter // contains filtered or unexported fields }
WorkItem represents all the required information for processing the input file into a chapter specific file. To do the actual processing, run WorkItem.Process()
func (WorkItem) FFmpegArgs ¶ added in v0.1.1
FFmpegArgs converts a WorkItem to a list of arguments that are going to be passed to ffmpeg for actual processing step.
func (WorkItem) GetCommand ¶ added in v0.1.1
GetCommand produces a list of command line arguments that would produce the chapter file specific to this workItem