echoprint-codegen
echoprint-codegen copied to clipboard
Calling 'echoprint-codegen' from PHP Script
I've been playing around with the codegen program locally on my machine today and yesterday. I was just experimenting by creating a PHP app that calls codegen. It took the longest time figuring out why PHP would recognize the 'echoprint-codegen' program, but if I ran 'echoprint-codegen' from terminal it would work just.
I finally was able to make the php script recognize it work by giving it an exact path to the program, something like the following:
<?php
echo shell_exec('/usr/local/bin/echoprint-codegen /Users/MyUser/Music/iTunes/iTunes\ Music/AlbumName/SongName.m4a 10 30');
?>
However, I keep getting the following error:
[ {"error":"could not decode", "tag":0, "metadata":{"filename":"/Users/MyUser/Music/iTunes/iTunes Music/AlbumName/SongName.m4a"}} ]
But if I run it from terminal, it works just fine and returns the metadata and generated code as you would expect. Any ideas?
Thanks, Chad
I cannot reproduce this issue with the information you've given. However, I think the issue might be with spaces in the audio filename. Can you try with the filename quoted - e.g.
echo shell_exec('/usr/local/bin/echoprint-codegen "/Users/MyUser/Music/iTunes/iTunes\ Music/AlbumName/SongName.m4a" 10 30');
and also with the filename double quoted -
echo shell_exec('/usr/local/bin/echoprint-codegen "\"/Users/MyUser/Music/iTunes/iTunes\ Music/AlbumName/SongName.m4a\"" 10 30');
Also, see if the script works if you give it a path to an audio file that has no spaces in the name.
Thanks
Dang, that's unfortunate. Thanks for giving it a look though.
I tried your suggestions, but nothing worked.
I'm using an audio file with no spaces in the name or path, and I tried several different types of quote combinations. See below:
Example 1
<?php
echo shell_exec('/usr/local/bin/codegen /Users/chadhutchins/Downloads/zacbrown.m4a 10 30');
?>
// response
[{"error":"could not decode", "tag":0, "metadata":{"filename":"/Users/chadhutchins/Downloads/zacbrown.m4a"}}]
Example 2
<?php
echo shell_exec('/usr/local/bin/codegen "/Users/chadhutchins/Downloads/zacbrown.m4a" 10 30');
?>
// response
[{"error":"could not decode", "tag":0, "metadata":{"filename":"/Users/chadhutchins/Downloads/zacbrown.m4a"}}]
Example 3
<?php
echo shell_exec('/usr/local/bin/codegen ""/Users/chadhutchins/Downloads/zacbrown.m4a"" 10 30');
?>
// response
[{"error":"could not decode", "tag":0, "metadata":{"filename":"/Users/chadhutchins/Downloads/zacbrown.m4a"}}]
Example 4
<?php
echo shell_exec('/usr/local/bin/codegen "\"/Users/chadhutchins/Downloads/zacbrown.m4a"\" 10 30');
?>
// response
[{"error":"could not decode", "tag":0, "metadata":{"filename":"\"/Users/chadhutchins/Downloads/zacbrown.m4a\""}}]
However, if I run the commands inside any of the shell_exec() functions in Terminal, I get the following as expected:
[{
"metadata": {
"artist": "",
"release": "",
"title": "",
"genre": "",
"bitrate": 64,
"sample_rate": 44100,
"duration": 35,
"filename": "/Users/chadhutchins/Downloads/zacbrown.m4a",
"samples_decoded": 283382,
"given_duration": 30,
"start_offset": 10,
"version": 4.11,
"codegen_time": 0.093334,
"decode_time": 0.577078
},
"code_count": 702,
"code": "eJy1mU1yJSkMhK-E-BM6DiBx_yPMx1vMxDji4UVHbzJsU1VUSanMpDslWT09wNsLYj4g5_yCel6w8wNKeoLEC4q_wOwFS1_g_QGVej1gxAv2foCs-YIoD8h5vODdo2EPKNJf8O5C2y-w8YJL2-9w6gNqkRf084LhL5j7AbLGCyIekKW9YNQHFPEXqL3gT7pwxeMr_DIpPV7w7sKZD2j3-V_hlx7t-YI4D_hFJ3t5gcYDSi4v0PWCv9dfyS_4RSef_d3rARL-gF-6UMYLtD3glymr6wXvGfx7XXgr4VovCHvBewZbe4Bse8F9wFfIWV-gL_ilg91eMPIL_tqUlbMf8Et_n271W3_3A2TrC854QJbzAjrxgHMe8Bd98J03_kTr3j16KuG7g-8ZzEle8O7RfsInznyDkvoL_qSDzymr90jxHZq84JcunAe8ulBtjjlcssGEyVxlH8laG6cfW3PbtKjZZsx5cqmhRWadvVYrWXf3nURcapKhZS0e2OuoKmnsvK2MyEeazR1ibdWmq_XWey99R2h0Y_-wNqd0L9hF2T5UxwkpvZluzS2KVrEQrSVm87YszfC1zyiWe5vZ-6yLu1uZe44apaOGLdqocx2rqrvyDm2VqNHT7b99YET4uLuPp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fcrihMlwrUTz903ajF9mbtvcTgubeXTNilgNCo2rO5003Svm2NAcvL11XoKRRzuvDNBq31Ugon6ueoE-v119R92qeNK",
"tag": 0
}]
Thanks again for looking at this. Any ideas?
Hi! You might want to check if your song is not protected with some sort of DRM.
S
Hi Chad,
Did you ever get to the bottom of this? I'm having the same problem.
Regards,
Matt.
I didn't. I'll report back if/when I do though.
On Tue, Sep 6, 2011 at 5:05 PM, mattsims < [email protected]>wrote:
Hi Chad,
Did you ever get to the bottom of this? I'm having the same problem.
Regards,
Matt.
Reply to this email directly or view it on GitHub:
https://github.com/echonest/echoprint-codegen/issues/25#issuecomment-2022955
I had the same issue, I just re-installed ffmpeg and the problem disappeared.
hi i'm sorry to re-open an old issue but i'm stuck here
just like the thread starter im trying to run
$handle = popen('/Applications/MAMP/htdocs/projectx/codegen/echoprint-codegen "/Applications/MAMP/htdocs/projectx/codegen/2.mp3" 10 30', 'r') echo "'$handle'; " . gettype($handle) . "\n"; $read = fread($handle, 2096); echo $read; pclose($handle);
But no matter what i am perpetually stuck with
"error":"could not decode", "tag":0, "metadata":{"filename":"/Applications/MAMP/htdocs/projectx/codegen/2.mp3"}}
Now, my filename has no single quotes so i believe i would need to make no use of the Posix ticket up there.
I reinstalled ffmpeg as someone above suggested. Nothing.
From the trace i can see this:
[0] => sh: line 1: 57341 Trace/BPT trap: 5 /usr/local/bin/ffmpeg -i "/Applications/MAMP/htdocs/projectx/codegen/2.mp3" -ac 1 -ar 11025 -f s16le -t 30 -ss 10 - 2> /dev/null
I saw somewhere else that it meant that ffmpeg could not be found. Recompiled codegen with the absolute ffmpeg path of my installation. Nothing.
On another note. While ffmpeg was reinstalling i ran the php script that uses codegen. And got the same result.
Meanwhile from the shell runs fine.
Am i missing something extrmely obvious here? ( i really wouldn't mind if that was the case :)
Best reagrds and thank you in advance
To whomever might need help with this, I managed to solve it after i found out that ffmpeg was indeed the problem. Got the hint from this : http://stackoverflow.com/questions/10107671/ffmpeg-mamp-dyld-library-not-loaded-error/12099991#12099991
$cmd = 'ffmpeg -i "karma.mp3"'; exec($cmd." 2>&1", $out, $ret); if ($ret){ echo "There was a problem!\n"; print_r($out); }else{ echo "Everything went better than expected!\n\n"; print_r($out); }
For me it was complaining that it could not find the libfreetype dylib. It was because i'm running it on MAMP and the answer is to comment out the DYLD_LIBRARY_PATH on /Applications/MAMP/Library/bin/envvars
I also had this problem but was not using MAMP. It turned out the Apache user, in my case _www, did not have /usr/local/bin in it's PATH. You can test this with an echo shell_exec("env"). You can add the path depending on your OS or I simply created a symlink to ffmpeg from one of it's included paths.