From 372bdd0d77d800f10bfbad1b04881afdda6a88f0 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Tue, 9 Jul 2019 17:48:15 +0530 Subject: [PATCH 1/9] override pipeline as well --- src/FFMPEG.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 3b53a0f..339e7aa 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -63,6 +63,12 @@ function run(commands...) end end +function pipeline(commands...) + withenv(execenv) do + Base.pipeline(commands...) + end +end + exe(commands...) = run(ffmpeg, commands...) end # module From 33e55d3ad728d8ba170c844a62d76e4811e36528 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 20:38:17 +0530 Subject: [PATCH 2/9] Add macro `@ffmpeg` --- src/FFMPEG.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 339e7aa..3474ac5 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -63,9 +63,11 @@ function run(commands...) end end -function pipeline(commands...) - withenv(execenv) do - Base.pipeline(commands...) +macro ffmpeg(arg) + return quote + withenv(execenv) do + $arg + end end end From 236fe0a176ca5c3971a44542e93eb8b29cc37305 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 20:52:23 +0530 Subject: [PATCH 3/9] doc everything and export, get macro working --- src/FFMPEG.jl | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 3474ac5..3ef5955 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -57,12 +57,20 @@ function versioninfo() #println("SWResample version $(_swresample_version())") end -function run(commands...) - withenv(execenv) do - Base.run(Cmd([commands...])) - end -end +""" + @ffmpeg arg + +Runs `arg` within the build environment of FFMPEG. +## Examples + +```jldoctest +julia> @ffmpeg run(`$ffmpeg -version`) +ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers +built with clang version 6.0.1 (tags/RELEASE_601/final) +[...] +``` +""" macro ffmpeg(arg) return quote withenv(execenv) do @@ -71,6 +79,28 @@ macro ffmpeg(arg) end end -exe(commands...) = run(ffmpeg, commands...) +""" + exe(commands...) + +Execute the given commands as arguments to the `ffmpeg` executable. + +## Examples + +```jldoctest +julia> FFMPEG.exe("-version") +ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers +built with clang version 6.0.1 (tags/RELEASE_601/final) +[...] +``` +""" +function exe(commands::AbstractString...) + + withenv(execenv) do + Base.run(Cmd([ffmpeg, commands...])) + end + +end + +export ffmpeg, @ffmpeg end # module From dd9cb4e0cd878414dd6706652444c064713ed319 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 20:53:45 +0530 Subject: [PATCH 4/9] Update README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 448232e..9419b2c 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ This package simply offers: ```julia -# simple way to invoke ffmpeg: +# a simple way to invoke ffmpeg: FFMPEG.exe("-version") -FFMPEG.run(FFMPEG.ffmpeg, "-version") +@ffmpeg run(`$ffmpeg -version`) # note the $ffmpeg # the AV libraries: FFMPEG.libavcodec FFMPEG.libavformat @@ -19,10 +19,10 @@ FFMPEG.libswscale FFMPEG.libavdevice FFMPEG.libavfilter -# and for good measures: +# and for good measure: FFMPEG.versioninfo() ``` -For a high level API to the AV libraries have a look at [VideoIO](https://github.com/JuliaIO/VideoIO.jl/) +For a high level API to the AV libraries in `libav`, have a look at [VideoIO.jl](https://github.com/JuliaIO/VideoIO.jl/). -This package is aimed to be included into packages, that just need the ffmpeg binaries + executables, and don't want to take on the 3.6 second load time of VideoIO. +This package is made to be included into packages that just need the ffmpeg binaries + executables, and don't want to take on the 3.6 second load time of VideoIO. From 453312a3b248f68710524fbae83771501170bbae Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 21:27:09 +0530 Subject: [PATCH 5/9] the great refactoring --- src/FFMPEG.jl | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 3ef5955..17c380b 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -80,9 +80,9 @@ macro ffmpeg(arg) end """ - exe(commands...) + exe(args...) -Execute the given commands as arguments to the `ffmpeg` executable. +Execute the given commands as arguments to the given executable. ## Examples @@ -93,14 +93,52 @@ built with clang version 6.0.1 (tags/RELEASE_601/final) [...] ``` """ -function exe(commands::AbstractString...) +function exe(args::AbstractString...; command = FFMPEG.ffmpeg) withenv(execenv) do - Base.run(Cmd([ffmpeg, commands...])) + Base.run(Cmd([command, commands...])) end end -export ffmpeg, @ffmpeg +""" + exe(arg) + +Execute the given command literal as an argument to the given executable. + +## Examples + +```jldoctest +julia> FFMPEG.exe(``-version`) +ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers +built with clang version 6.0.1 (tags/RELEASE_601/final) +[...] +``` +""" +function exe(arg::Cmd; command = ffmpeg) + + withenv(execenv) do + Base.run(`$command $arg`) + end + +end + +""" + fmpeg(arg::Cmd) + fmpeg(args::String...) + +Execute the given arguments as arguments to the `ffmpeg` executable. +""" +fmpeg(args...) = exe(args...; command = ffmpeg) + +""" + fprobe(arg::Cmd) + fprobe(args::String...) + +Execute the given arguments as arguments to the `ffprobe` executable. +""" +fprobe(args...) = exe(args...; command = ffprobe) + +export fmpeg, @ffmpeg, fprobe end # module From b8935b9cf69d9eded18a7da0436beeb5e1324731 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 21:27:56 +0530 Subject: [PATCH 6/9] remove double backticks --- src/FFMPEG.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 17c380b..d9e6f79 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -109,7 +109,7 @@ Execute the given command literal as an argument to the given executable. ## Examples ```jldoctest -julia> FFMPEG.exe(``-version`) +julia> FFMPEG.exe(`-version`) ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers built with clang version 6.0.1 (tags/RELEASE_601/final) [...] @@ -139,6 +139,6 @@ Execute the given arguments as arguments to the `ffprobe` executable. """ fprobe(args...) = exe(args...; command = ffprobe) -export fmpeg, @ffmpeg, fprobe +export fmpeg, @ffmpeg, fprobe, ffmpeg end # module From 98129bd65d527103b8e9670f63775174116f9161 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 21:34:35 +0530 Subject: [PATCH 7/9] the greater refactoring --- src/FFMPEG.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index d9e6f79..5d78f94 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -124,21 +124,21 @@ function exe(arg::Cmd; command = ffmpeg) end """ - fmpeg(arg::Cmd) - fmpeg(args::String...) + ffmpeg_exe(arg::Cmd) + ffmpeg_exe(args::String...) Execute the given arguments as arguments to the `ffmpeg` executable. """ -fmpeg(args...) = exe(args...; command = ffmpeg) +ffmpeg_exe(args...) = exe(args...; command = ffmpeg) """ - fprobe(arg::Cmd) - fprobe(args::String...) + ffprobe_exe(arg::Cmd) + ffprobe_exe(args::String...) Execute the given arguments as arguments to the `ffprobe` executable. """ -fprobe(args...) = exe(args...; command = ffprobe) +ffprobe_exe(args...) = exe(args...; command = ffprobe) -export fmpeg, @ffmpeg, fprobe, ffmpeg +export ffmpeg_exe, @ffmpeg, ffprobe_exe, ffmpeg, ffprobe end # module From 359fa74eaa5756f87600a0bd2953610c5a2c4f87 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 21:44:58 +0530 Subject: [PATCH 8/9] the lesser refactoring --- src/FFMPEG.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 5d78f94..69f78a0 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -96,7 +96,7 @@ built with clang version 6.0.1 (tags/RELEASE_601/final) function exe(args::AbstractString...; command = FFMPEG.ffmpeg) withenv(execenv) do - Base.run(Cmd([command, commands...])) + Base.run(Cmd([command, args...])) end end From 44d0ad96ac02334a86ee5dcc2319f09806590c88 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 10 Jul 2019 21:49:29 +0530 Subject: [PATCH 9/9] rename macro --- README.md | 5 ++++- src/FFMPEG.jl | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9419b2c..ca39a73 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ This package simply offers: ```julia # a simple way to invoke ffmpeg: FFMPEG.exe("-version") -@ffmpeg run(`$ffmpeg -version`) # note the $ffmpeg +@ffmpeg_env run(`$ffmpeg -version`) # note the $ffmpeg +ffmpeg_exe("-version") +ffmpeg_exe(`-version`) +ffprobe_exe("-version") # we wrap FFPROBE too! # the AV libraries: FFMPEG.libavcodec FFMPEG.libavformat diff --git a/src/FFMPEG.jl b/src/FFMPEG.jl index 69f78a0..538e304 100644 --- a/src/FFMPEG.jl +++ b/src/FFMPEG.jl @@ -58,20 +58,20 @@ function versioninfo() end """ - @ffmpeg arg + @ffmpeg_env arg Runs `arg` within the build environment of FFMPEG. ## Examples ```jldoctest -julia> @ffmpeg run(`$ffmpeg -version`) +julia> @ffmpeg_env run(`$ffmpeg -version`) ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers built with clang version 6.0.1 (tags/RELEASE_601/final) [...] ``` """ -macro ffmpeg(arg) +macro ffmpeg_env(arg) return quote withenv(execenv) do $arg @@ -139,6 +139,6 @@ Execute the given arguments as arguments to the `ffprobe` executable. """ ffprobe_exe(args...) = exe(args...; command = ffprobe) -export ffmpeg_exe, @ffmpeg, ffprobe_exe, ffmpeg, ffprobe +export ffmpeg_exe, @ffmpeg_env, ffprobe_exe, ffmpeg, ffprobe end # module