Hi, I am using an IP camera, it runs on an 12v 1A adapter.
It can also run on from a 5V 2A powerbank, or adapter.
When there is no main AC power, I want to switch the power source into the 5V.
Whenever there is 12V supply, the IP camera should be able to use that, because the WiFi and night vision seems to be better with 12V source.
I am not even sure if it is possible using Arduino..
May be using a relay ? The Arduino can draw power from the same 5V powerbank... ?
Simple SPDT relays are sufficient, no controller required. Use a 12V relay, that is activated when a 12V power source is connected, and make the device switch to that supply. The same for the 5V power source. Take care to prevent short-circuits between the power sources, in every possible state of the relays.
Also take care that the device will continue working while the relays switch, using big enough caps on the device's Vcc. You may have less problems when switching with MOSFETs instead of mechanical relays, like the Uno mainboard switches between the USB and power jack supplies.
Won't two diodes be able to do the job?

How I imagine this: if the 12V supply is available, power is drawn through D1, and D2 blocks this voltage from reaching the 5V supply. It also blocks the 5V supply from supplying any current.
When the 12V supply is not available (so drops to 0V), it works opposite.
You probably still need a serious capacitor to bridge the switch-over, and I do assume your device takes both voltages on the same power input, so has some form of regulator built in.
The diode solution will work for the 5V and 12V supplies. The rest depends on the role of the mains supply. If it's the 12V supply, everything is fine. Else, if it is a third supply, another diode will help only if the supplied voltage is higher than 12V, else the 12V source will be drained even if mains power is available.
From the way OP is written I take it that "mains" here is equivalent to "12V supply" as OP mentioned using an adapter.
One problem if the diode solution may be that a diode means a voltage drop of around 0.6V. So your 5V supply is reduced to around 4.4V.
I started to think of how to use a MOSFET to switch between the two but putting a p-channel MOSFET in the 5V line means you still need a diode to stop the 12V from reaching the 5V supply, as they conduct in DS direction.
wvmarle:
Won't two diodes be able to do the job?

D1 is unnecessary.
wvmarle:
I started to think of how to use a MOSFET to switch between the two but putting a p-channel MOSFET in the 5V line means you still need a diode to stop the 12V from reaching the 5V supply, as they conduct in DS direction.
Connect the gate to the 12V line with a pulldown resistor to GND. Connect the drain (not source) to the 5V input, so that the body diode is forward-biased with respect to the 5V power flow. Remember that you aren't using the MOSFET to stop the 5V supply from delivering power, you're stopping the 12V supply from backfeeding power into the 5V. The MOSFET conduction channel actually works both ways, as long as you are mindful of the VGS polarity and the body diode.
When you plug in just the 5V, the gate will be at 0V (due to the pulldown) and the source will be at 5V minus diode drop, due to the body diode. The negative VGS turns the MOSFET on, giving you a low resistance path to provide power.
When 12V is plugged in at the same time, the gate is pulled up to 12V. The positive VGS turns the MOSFET off, preventing current from being forced backwards into the 5V power supply. The body diode is also reverse-biased.
For a practical example, view the schematic on page 2 of this Application Note: http://ww1.microchip.com/downloads/en/AppNotes/01149c.pdf