Python and terminal in macOS return different results

Hello,

I’m new to python and so I assume I’d doing something wrong here. I’m using macOS 13.6 with python3.

I’m trying to understand why in terminal and python I get different results for the following command:
ffmpeg -f avfoundation -list_devices true -i “”

When in terminal I perform the following command I get:

[AVFoundation indev @ 0x7fbe79804500] AVFoundation video devices:
[AVFoundation indev @ 0x7fbe79804500] [0] PureThermal (fw:v1.3.0)
[AVFoundation indev @ 0x7fbe79804500] [1] FaceTime HD Camera (Built-in)
[AVFoundation indev @ 0x7fbe79804500] [2] OBS Virtual Camera
[AVFoundation indev @ 0x7fbe79804500] [3] Capture screen 0
[AVFoundation indev @ 0x7fbe79804500] [4] Capture screen 1
[AVFoundation indev @ 0x7fbe79804500] AVFoundation audio devices:
[AVFoundation indev @ 0x7fbe79804500] [0] MacBook Pro Microphone

When running the following in a python script:

command = ['ffmpeg','-f', 'avfoundation','-list_devices','true','-i','""']
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
for item in result.stderr.splitlines():
    print (item)

I get:

[AVFoundation indev @ 0x7fbf43804540] AVFoundation video devices:
[AVFoundation indev @ 0x7fbf43804540] [0] FaceTime HD Camera (Built-in)
[AVFoundation indev @ 0x7fbf43804540] [1] OBS Virtual Camera
[AVFoundation indev @ 0x7fbf43804540] [2] PureThermal (fw:v1.3.0)
[AVFoundation indev @ 0x7fbf43804540] [3] Capture screen 0
[AVFoundation indev @ 0x7fbf43804540] [4] Capture screen 1
[AVFoundation indev @ 0x7fbf43804540] AVFoundation audio devices:
[AVFoundation indev @ 0x7fbf43804540] [0] MacBook Pro Microphone

As you can see the camera indexes are mixed up :confused: Am I doing something wrong above? Thanks!

The python script simply returns the ffmpeg call output; it’s fine - it’s equivalent to running the command line you showed. If you are getting different output, it logically follows that ffmpeg itself (AVFoundation really) can return the devices in different orders. I don’t know why it does that but assume this is because the ordering really doesn’t matter or doesn’t really have meaning. There is an Apple Developer Forum for AVFoundation where you could ask that question - if it matters to you :slight_smile: