How do I get the public url of a file from the uri or filename
What do you mean by &quot;public URL&quot; exactly ?
file_create_url() can give the absolute URL to the image out of the box.
$videouri = db_query('SELECT uri FROM {file_managed} WHERE fid = :nidvideo', array(':nidvideo' =&gt; $nidvideo))-&gt;fetchColumn();
//drupal_set_message('&lt;pre&gt;'. print_r($videourl, TRUE) .'&lt;/pre&gt;');
$videourl = file_create_url($videouri);

file_create_url() expects a valid uri. drupal_realpath() gives the server path which does not work.
I also changed your database query to avoid any SQL injection vulnerable.