Download like browser using CURL for ffmpeg
I want input HTTP file in ffmpeg parameter and I have tried this code
<?php
$fname=time().'_myfile.mp3';
$cmd = "/usr/local/bin/ffmpeg -i 'http://tinyurl.com/url' -vn -b 64k -f mp3 -acodec libmp3lame - $fname";
header('Content-type: audio/mpeg');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$fname\"");
passthru($cmd);
>?
I tried to pass tinyurl URL but ffmpeg开发者_高级运维 failed to create file. This code work fine if I pass some other direct URL to parameter.
I thinking of creating one PHP file and using CURL with proper headers and pass that PHP file in input parameter will that work? In simple words ffmpeg failed if input is not direct link. What should I do?
Can anybody help me on this?
Based on a comment from http://getsatisfaction.com/soup/topics/reverse_lookup_for_tinyurls you can use the below curl function to get the real URL from which you should be able to carry on as planned.
function resolve($url)
{
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "spider",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
CURLOPT_NOBODY => 1
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
return $header['url'];
}
精彩评论