diff --git a/ffmpeg.go b/ffmpeg.go index e909bd1..3df2f9f 100644 --- a/ffmpeg.go +++ b/ffmpeg.go @@ -13,12 +13,12 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3manager" ) -// Input file URL (ffmpeg ``-i`` option) +// Input file URL (ffmpeg “-i“ option) // -// Any supplied kwargs are passed to ffmpeg verbatim (e.g. ``t=20``, -// ``f='mp4'``, ``acodec='pcm'``, etc.). +// Any supplied kwargs are passed to ffmpeg verbatim (e.g. “t=20“, +// “f='mp4'“, “acodec='pcm'“, etc.). // -// To tell ffmpeg to read from stdin, use ``pipe:`` as the filename. +// To tell ffmpeg to read from stdin, use “pipe:“ as the filename. // // Official documentation: `Main options `__ func Input(filename string, kwargs ...KwArgs) *Stream { @@ -33,7 +33,7 @@ func Input(filename string, kwargs ...KwArgs) *Stream { return NewInputNode("input", nil, args).Stream("", "") } -// Add extra global command-line argument(s), e.g. ``-progress``. +// Add extra global command-line argument(s), e.g. “-progress“. func (s *Stream) GlobalArgs(args ...string) *Stream { if s.Type != "OutputStream" { panic("cannot overwrite outputs on non-OutputStream") @@ -41,7 +41,7 @@ func (s *Stream) GlobalArgs(args ...string) *Stream { return NewGlobalNode("global_args", []*Stream{s}, args, nil).Stream("", "") } -// Overwrite output files without asking (ffmpeg ``-y`` option) +// Overwrite output files without asking (ffmpeg “-y“ option) // // Official documentation: `Main options `_ func (s *Stream) OverwriteOutput(stream *Stream) *Stream { @@ -56,28 +56,28 @@ func MergeOutputs(streams ...*Stream) *Stream { return NewMergeOutputsNode("merge_output", streams).Stream("", "") } -//Output file URL +// Output file URL // -// Syntax: -// `ffmpeg.Output([]*Stream{stream1, stream2, stream3...}, filename, kwargs)` +// Syntax: +// `ffmpeg.Output([]*Stream{stream1, stream2, stream3...}, filename, kwargs)` // -// Any supplied keyword arguments are passed to ffmpeg verbatim (e.g. -// ``t=20``, ``f='mp4'``, ``acodec='pcm'``, ``vcodec='rawvideo'``, -// etc.). Some keyword-arguments are handled specially, as shown below. +// Any supplied keyword arguments are passed to ffmpeg verbatim (e.g. +// ``t=20``, ``f='mp4'``, ``acodec='pcm'``, ``vcodec='rawvideo'``, +// etc.). Some keyword-arguments are handled specially, as shown below. // -// Args: -// video_bitrate: parameter for ``-b:v``, e.g. ``video_bitrate=1000``. -// audio_bitrate: parameter for ``-b:a``, e.g. ``audio_bitrate=200``. -// format: alias for ``-f`` parameter, e.g. ``format='mp4'`` -// (equivalent to ``f='mp4'``). +// Args: +// video_bitrate: parameter for ``-b:v``, e.g. ``video_bitrate=1000``. +// audio_bitrate: parameter for ``-b:a``, e.g. ``audio_bitrate=200``. +// format: alias for ``-f`` parameter, e.g. ``format='mp4'`` +// (equivalent to ``f='mp4'``). // -// If multiple streams are provided, they are mapped to the same -// output. +// If multiple streams are provided, they are mapped to the same +// output. // -// To tell ffmpeg to write to stdout, use ``pipe:`` as the filename. +// To tell ffmpeg to write to stdout, use ``pipe:`` as the filename. // -// Official documentation: `Synopsis `__ -// """ +// Official documentation: `Synopsis `__ +// """ func Output(streams []*Stream, fileName string, kwargs ...KwArgs) *Stream { args := MergeKwArgs(kwargs) if !args.HasKey("filename") { @@ -90,6 +90,34 @@ func Output(streams []*Stream, fileName string, kwargs ...KwArgs) *Stream { return NewOutputNode("output", streams, nil, args).Stream("", "") } +// Output file URL +// +// Syntax: +// `ffmpeg.Output(ctx, []*Stream{stream1, stream2, stream3...}, filename, kwargs)` +// +// Any supplied keyword arguments are passed to ffmpeg verbatim (e.g. +// ``t=20``, ``f='mp4'``, ``acodec='pcm'``, ``vcodec='rawvideo'``, +// etc.). Some keyword-arguments are handled specially, as shown below. +// +// Args: +// video_bitrate: parameter for ``-b:v``, e.g. ``video_bitrate=1000``. +// audio_bitrate: parameter for ``-b:a``, e.g. ``audio_bitrate=200``. +// format: alias for ``-f`` parameter, e.g. ``format='mp4'`` +// (equivalent to ``f='mp4'``). +// +// If multiple streams are provided, they are mapped to the same +// output. +// +// To tell ffmpeg to write to stdout, use ``pipe:`` as the filename. +// +// Official documentation: `Synopsis `__ +// """ +func OutputContext(ctx context.Context, streams []*Stream, fileName string, kwargs ...KwArgs) *Stream { + output := Output(streams, fileName, kwargs...) + output.Context = ctx + return output +} + func (s *Stream) Output(fileName string, kwargs ...KwArgs) *Stream { if s.Type != "FilterableStream" { log.Panic("cannot output on non-FilterableStream") @@ -97,7 +125,7 @@ func (s *Stream) Output(fileName string, kwargs ...KwArgs) *Stream { if strings.HasPrefix(fileName, "s3://") { return s.outputS3Stream(fileName, kwargs...) } - return Output([]*Stream{s}, fileName, kwargs...) + return OutputContext(s.Context, []*Stream{s}, fileName, kwargs...) } func (s *Stream) outputS3Stream(fileName string, kwargs ...KwArgs) *Stream {