# Running External Programs in windows

**URL:** <https://discourse.julialang.org/t/running-external-programs-in-windows/72353>\
**Category:** New to Julia\
**Created:** [December 1, 2021, 9:06am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353 "2021-12-01T09:06:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Lewis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel_lewis/32/31250_2.png) [@Daniel\_Lewis](https://discourse.julialang.org/u/Daniel_Lewis)\
**Post date:** [December 1, 2021, 9:06am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353/1 "2021-12-01T09:06:47Z")

</div>

hello,  
I’m trying to capture an image from a webcam using Windows 10.  
I have FFmpeg install and I can capture an image using the cmd command:  
`ffmpeg -f dshow -video_size 1920x1080 -i "video=HD Pro Webcam C920" -frames:v 1 org_img.jpg`.  
What I fail doing is running this command using the `run` command in julia script.  
I tried calling it as follow:

```julia
        mycmd = @cmd """ffmpeg -f dshow -video_size 1920x1080 -i "video=HD Pro Webcam C920" -frames:v 1 org_img.jpg"""
        run(`cmd /c $mycmd`)

```

but I get the following error

```julia
'ffmpeg' is not recognized as an internal or external command,
operable program or batch file.
ERROR: failed process: Process(`cmd /c ffmpeg -f dshow -video_size 1920x1080 -i 'video=HD Pro Webcam C920' -frames:v 1 org_img.jpg`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ .\process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base .\process.jl:440
 [3] run(::Cmd)
   @ Base .\process.jl:438
 [4] top-level scope
   @ REPL[13]:1

```

so I tried:

```julia
        run(mycmd)

```

and got the following error

```julia
ERROR: IOError: could not spawn `ffmpeg -f dshow -video_size 1920x1080 -i 'video=HD Pro Webcam C920' -frames:v 1 org_img.jpg`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Any})
   @ Base .\process.jl:99
 [2] #637
   @ .\process.jl:112 [inlined]
 [3] setup_stdios(f::Base.var"#637#638"{Cmd}, stdios::Vector{Any})
   @ Base .\process.jl:196
 [4] _spawn
   @ .\process.jl:111 [inlined]
 [5] run(::Cmd; wait::Bool)
   @ Base .\process.jl:439
 [6] run(::Cmd)
   @ Base .\process.jl:438
 [7] top-level scope
   @ REPL[17]:1

```

I found that `VideoIO.jl` can capture images from a Webcam, so I tried that to, and faild ☹

```julia
import VideoIO
cam = VideoIO.opencamera()

```

and got the following error

```julia
ERROR: MethodError: no method matching unsafe_convert(::Type{Ptr{Ptr{VideoIO.libffmpeg.AVDictionary}}}, ::VideoIO.AVDict)
Closest candidates are:
  unsafe_convert(::Type{Ptr{T}}, ::Base.ReshapedArray{T, N, P, MI} where {N, P<:AbstractArray, MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}, N} where N}}) where T at reshapedarray.jl:281
  unsafe_convert(::Type{Ptr{T}}, ::LinearAlgebra.Transpose{var"#s832", var"#s831"} where {var"#s832", var"#s831"<:(AbstractVecOrMat{T} where T)}) where T at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\adjtrans.jl:222
  unsafe_convert(::Type{Ptr{T}}, ::OffsetArrays.OffsetArray{T, N, AA} where {N, AA<:AbstractArray{T, N}}) where T at C:\Users\KOBIED\.julia\packages\OffsetArrays\I5Pfg\src\OffsetArrays.jl:454
  ...
Stacktrace:
 [1] avformat_open_input(ps::VideoIO.NestedCStruct{VideoIO.libffmpeg.AVFormatContext}, url::String, fmt::Ptr{VideoIO.libffmpeg.AVInputFormat}, options::VideoIO.AVDict)
   @ VideoIO.libffmpeg C:\Users\KOBIED\.julia\packages\VideoIO\EsW3Z\lib\libffmpeg.jl:8571
 [2] open_avinput(avin::VideoIO.AVInput{String}, source::String, input_format::Ptr{VideoIO.libffmpeg.AVInputFormat}, options::VideoIO.AVDict)
   @ VideoIO C:\Users\KOBIED\.julia\packages\VideoIO\EsW3Z\src\avio.jl:195
 [3] VideoIO.AVInput(source::String, input_format::Ptr{VideoIO.libffmpeg.AVInputFormat}, options::VideoIO.AVDict; avio_ctx_buffer_size::Int64)
   @ VideoIO C:\Users\KOBIED\.julia\packages\VideoIO\EsW3Z\src\avio.jl:218
 [4] VideoIO.AVInput(source::String, input_format::Ptr{VideoIO.libffmpeg.AVInputFormat}, options::VideoIO.AVDict)
   @ VideoIO C:\Users\KOBIED\.julia\packages\VideoIO\EsW3Z\src\avio.jl:207
 [5] opencamera(::String, ::Ptr{VideoIO.libffmpeg.AVInputFormat}, ::VideoIO.AVDict; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ VideoIO C:\Users\KOBIED\.julia\packages\VideoIO\EsW3Z\src\avio.jl:1016
 [6] opencamera(::String, ::Ptr{VideoIO.libffmpeg.AVInputFormat}, ::VideoIO.AVDict) (repeats 2 times)
   @ VideoIO C:\Users\KOBIED\.julia\packages\VideoIO\EsW3Z\src\avio.jl:1016
 [7] top-level scope
   @ REPL[20]:1

```

The `VideoIO.jl` documentation and examples are quite poor so I have no idea how to continue.  
Please Help !!!

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [December 1, 2021, 9:16am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353/2 "2021-12-01T09:16:53Z")

</div>

> [@Daniel\_Lewis](#):
>
> ```julia
> mycmd = @cmd """ffmpeg -f dshow -video_size 1920x1080 -i "video=HD Pro Webcam C920" -frames:v 1 org_img.jpg"""
> run(`cmd /c $mycmd`)
> 
> ```

It’s probably missing the path to the ffmpeg executable. Try to provide the complete path to ffmpeg, e.g. in my case this works except that it doesn’t find the webcam 😉 :

```julia
julia> mycmd = @cmd """D:/Data/Downloads/ffmpeg-4.2.1-win64-static/bin/ffmpeg -f dshow -video_size 1920x1080 -i "video=HD Pro Webcam C920" -frames:v 1 org_img.jpg"""
`D:/Data/Downloads/ffmpeg-4.2.1-win64-static/bin/ffmpeg -f dshow -video_size 1920x1080 -i 'video=HD Pro Webcam C920'
 -frames:v 1 org_img.jpg`

julia> run(`cmd /c $mycmd`)
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
...

```

---

<div class="post-metadata">

**Author:** ![Daniel\_Lewis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel_lewis/32/31250_2.png) [@Daniel\_Lewis](https://discourse.julialang.org/u/Daniel_Lewis)\
**Post date:** [December 1, 2021, 9:25am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353/3 "2021-12-01T09:25:26Z")

</div>

thanks for the quick reply, that worked 🎉 🎉  
I also found the `FFMPEG.jl` package, which did exactly as you suggested.

```julia
using MMFPEG
mycmd = @cmd """-f dshow -video_size 1920x1080 -i "video=HD Pro Webcam C920" -frames:v 1 org_img.jpeg"""
ffmpeg_exe(mycmd)

```

thanks again 🙂

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [December 1, 2021, 11:48am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353/4 "2021-12-01T11:48:12Z")

</div>

Daniel, please do not be so quick to give up on VideoIO  
In the early days VideoIO was a bear to use, I have done a lot of testing with it on Windows and found that it ‘just works’ now. Being honest I have not tried it for several months though , and not in 1.7

---

<div class="post-metadata">

**Author:** ![Daniel\_Lewis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel_lewis/32/31250_2.png) [@Daniel\_Lewis](https://discourse.julialang.org/u/Daniel_Lewis)\
**Post date:** [December 2, 2021, 5:43am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353/5 "2021-12-02T05:43:20Z")

</div>

Johnh hello, on the contrary, I would be more then happy to be able to use the `VidioIO.jl` package.  
Unfortunately I don’t understand way it’s not working. Using the `run()` command directly is a poor solution but it work for me.  
If someone can help me with the `VideoIO.jl` package I’ll be more then happy to use it.  
p.s. I’m working with julia v1.6

---

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [December 21, 2021, 2:42am UTC](https://discourse.julialang.org/t/running-external-programs-in-windows/72353/6 "2021-12-21T02:42:56Z")

</div>

Update  
`Base.convert(::Type{Ref{Ptr{AVDictionary}}}, d::AVDict) = d.ref_ptr_dict`  
to  
`Base.cconvert(::Type{Ptr{Ptr{AVDictionary}}}, d::AVDict) = d.ref_ptr_dict`

in avdictionary.jl which can be found at .julia/packages/videoio/somethingrandom/ src/avddictionary.jl , should start working hopefully
