Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API: exe, @ffmpeg_env, ffmpeg_exe, ffprobe_exe #1

Merged
merged 9 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
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_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
Expand All @@ -19,10 +22,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.
82 changes: 79 additions & 3 deletions src/FFMPEG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,88 @@ function versioninfo()
#println("SWResample version $(_swresample_version())")
end

function run(commands...)
"""
@ffmpeg_env arg

Runs `arg` within the build environment of FFMPEG.

## Examples

```jldoctest
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_env(arg)
return quote
withenv(execenv) do
$arg
end
end
end

"""
exe(args...)

Execute the given commands as arguments 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(args::AbstractString...; command = FFMPEG.ffmpeg)

withenv(execenv) do
Base.run(Cmd([command, args...]))
end

end

"""
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(Cmd([commands...]))
Base.run(`$command $arg`)
end

end

exe(commands...) = run(ffmpeg, commands...)
"""
ffmpeg_exe(arg::Cmd)
ffmpeg_exe(args::String...)

Execute the given arguments as arguments to the `ffmpeg` executable.
"""
ffmpeg_exe(args...) = exe(args...; command = ffmpeg)

"""
ffprobe_exe(arg::Cmd)
ffprobe_exe(args::String...)

Execute the given arguments as arguments to the `ffprobe` executable.
"""
ffprobe_exe(args...) = exe(args...; command = ffprobe)

export ffmpeg_exe, @ffmpeg_env, ffprobe_exe, ffmpeg, ffprobe

end # module