Is this a mobile app or a website?
If it's a mobile app then you can instrument the camera API to inject an image or video of your choice. This is a reliable, consistent way to substitute manual testing and expand your coverage to include various scenarios, depending on what you wish to test: different barcodes with various content, or various visual conditions such as smudging etc. You simply prepare in advance a set of images representing different scenarios.
If it's a web page then we're talking HTML5 or PWA, in which case I'd recommend using Javascript in automation to overload the action when the page wants to open the scanner and instead inject an image from a local folder. (disclaimer: I've not tried that one yet..).