[Q] encode to mp3 on an android device? - Android Software/Hacking General [Developers Only]

Im completely new at android and app writing. But I would like to write an app to make my life easer. I would like to recorde audio then encode it to mp3, is it possible? How would I go about starting?
Thanks
Steve
Sent from my DROIDX using XDA App

What you request is actually fairly advanced for a first program. I know nothing of your coding skills, so please don't take this a slight on you. The default media encoder on Android does not support direct encoding to mp3. So, you would need to either find a pure java mp3 encoder and port that to android, figure out the painful ndk C libraries through JNI to java and compile a C library like LAME, or *shiver* code your own mp3 encoder. All doable, none are trivial.
-frank

Related

rtmpdump 2.0 for Android

Just for grins I've compiled the latest rtmpdump source using the Android 1.5 SDK. I guess it's not much use yet since we still don't have good playback of FLV files, but maybe someone here will find a good use for it.
The source code is from http://rtmpdump.mplayerhq.hu/ This is from the 2.0 C code, not the 1.x C++ code, so it's smaller and faster...
I just tried the latest yxflash. I got nothing at all from an H264 video downloaded from Hulu, and I got audio only for a VP6 video. (I tried a Buck Rogers episode since the video is only 384x288. Current shows on Hulu in wide format are 512x288 which wouldn't display on the 480x320 screen anyway.)
So, do the 2.0 ROMs have more video codecs supported? I know that 1.x can playback H.264 baseline profile videos, but Hulu is using H.264 main profile, so it's no surprise that it didn't play on my 1.5 ROM.
rtmpdump-2.1.zip
This is a fresh build of rtmpdump 2.1. Read the README for details. It contains 4 programs:
rtmpdump - the client
rtmpsrv - a stub server, used mainly for displaying what other clients are doing
rtmpsuck - a transparent proxy, used to intercept a client stream and save it to disk while relaying to the client
streams - an HTTP gateway, serves RTMP streams via HTTP
So it seems there's not much interest here. It would probably help if someone were to port some more codecs into the OpenCore source tree. I've started looking into building ffmpeg on Android, but just compiling the C code probably isn't going to be very useful either. Without GPU acceleration I suspect a lot of these codecs will perform too poorly to be watchable. Is anybody in here working on these codecs?
http://gitorious.org/~olvaffe/ffmpeg/ffmpeg-android
http://gitorious.org/~olvaffe/libswscale/libswscale-android
Looks like work has stopped on it though. I'm not a C programmer therefore can't really help, otherwise this would interest me.
Thanks for the tip. Yeah, seems a bit out of date, too bad. I wonder if any of their work got merged upstream already...
Hmm. This Archos 5 media player is now running Android 1.5
http://www.theinquirer.net/inquirer/review/1568085/archos-internet-tablet
it seems to have a full complement of video codecs. I wonder where their code is. Of course, they're running on an 800MHz Cortex A8 so they've got a lot more horsepower to work with. Feels like it's time to retire the G1 and get something else. Maybe a GSM version of the Motorola Droid.
I've taken a different tack now. Since Android has a built in RTSP client already, I'm using ffmpeg on a remote machine to transcode the FLV to an MP4 that Android can play. This is fed to a DarwinStreamingServer and I just use Meridian to play it.
Now that ffmpeg supports rtmpdump's library, ffmpeg can do all the work in one shot. I've attached the perl script I use to grab a H,u,l,u stream and republish it on the server. ffmpeg grabs the stream using rtmp and re-encodes it and pushes it to DSS. Once the encoding begins you can use Meridian to open the rtsp URL.
T-Mobile's 3G network seems to handle a 400-500kbit/sec stream here in Los Angeles, but it's not consistent. Sometimes it hits a glitch and doesn't recover, sometimes the audio continues but the video stream gets lost and doesn't come back. So probably it's safer to use a smaller bit rate.
Note that H,u,l,u uses 3 different CDNs - Akamai, Level3, and Limeworks. Currently this script doesn't support Limeworks. Basically what it does is grab the lowest bitrate H264 stream from H,u,l,u (usually a 400kbps 512x288 stream) and re-encode it to 480x270. To use it, just run "h,u,l,u,p,u,b <h,u,l,u URL>". You'll need a recent SVN version of ffmpeg built with --enable-librtmp to be able to use it. And of course you'll also need DarwinStreamingServer. I haven't been able to make ffserver work yet.
If you're connected on a decent network with wifi you should have no trouble playing the full 400-500kbit rates. On 3G you might want to stick to 200 or so.
I haven't figured out where to go next with this. Right now I'm thinking about modifying this script so it can be run as a CGI. Then you just use the web browser to navigate the h,u,l,u web site in one window; when you get to a program you want you copy its link and paste it into a form on another window that invokes this script and returns an rtsp link as the result. Then click on the rtsp link and the media player will open it.
Ah hah, after a lot of poking and prodding I managed to fix ffmpeg's ffserver, so now it can be used to stream live media over RTSP to Android phones too.
The required patches are here
https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2010-May/088706.html
So no more need for Darwin Streaming Server to get this job done.
Note - as far as I can tell, streaming from files is still broken, and I haven't looked into it. All I've tested is to see that ffmpeg can stream an RTMPE session to ffserver, which can then stream it out over RTSP.
An even better solution, running ffserver on the phone, so that the stream can be transferred using TCP instead of UDP. It may freeze during play due to network issues, but it will resume again instead of just losing packets.
See this message for the necessary config files...
https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2010-May/089049.html
Any chance of giving a walkthrough or a short guide on how to get this thing working?
I've outlined a number of different things here, what in particular do you want a walkthru on?
Also, I've given links to email postings with example configs. Have you read those already?
highlandsun said:
I've outlined a number of different things here, what in particular do you want a walkthru on?
Also, I've given links to email postings with example configs. Have you read those already?
Click to expand...
Click to collapse
I was just trying to set it up on my evo and drawing a blank.
Grab the config files I posted here
https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2010-May/089049.html
There are two - one for your server, and one to run on your phone. The way it works is you have the ffserver running on a server box with fast-enough CPU and network connectivity. You can send it any stream using any codecs that ffmpeg supports, and ffmpeg will transcode it to a dumbed-down H.264 that can play smoothly over a relatively slow network. This transcode can run at realtime or faster, it all depends on your server and what the input to ffmpeg is. This ffserver will make the data available over HTTP in FLV format.
Install the second ffserver.conf file on your phone, along with the ffserver binary I posted in this thread. You of course need to tailor the file to replace "my.server:8080" with the address and port that you're using for the ffserver on your server box. This ffserver on the phone is configured to grab the FLV over HTTP from your main server, and then re-stream over RTSP/RTP/UDP. You can play the video from your main server by opening rtsp://127.0.0.1/test.mp4 - the Meridian player makes this easy since it has an Open URL menu for this. The SeeJo player also lets you play URLs.
I don't think I can explain it any more simply than this. If you don't understand how to run ffmpeg, there's plenty of other docs on that.
If you specifically want to stream h,u,l,u videos, you'll need to grab the perl script I posted above and edit the ffmpeg command at the end of the script. The script I attached here was set up to publish a stream to the Darwin Streaming Server over rtsp. A simpler command is used to stream to ffserver.
When publishing to DSS, you have to provide all of the audio/video codec settings on the ffmpeg command line, and the stream gets pushed to rtsp://wherever/the/DSS/server/is/listening.
When publishing to ffserver, all of the audio/video codec settings are in the ffserver.conf file, so you only need to tell ffmpeg where to find its input, and send its output to http://wherever/the/ffserver/is/listening.
highlandsun said:
Grab the config files I posted here
https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2010-May/089049.html
There are two - one for your server, and one to run on your phone. The way it works is you have the ffserver running on a server box with fast-enough CPU and network connectivity. You can send it any stream using any codecs that ffmpeg supports, and ffmpeg will transcode it to a dumbed-down H.264 that can play smoothly over a relatively slow network. This transcode can run at realtime or faster, it all depends on your server and what the input to ffmpeg is. This ffserver will make the data available over HTTP in FLV format.
Install the second ffserver.conf file on your phone, along with the ffserver binary I posted in this thread. You of course need to tailor the file to replace "my.server:8080" with the address and port that you're using for the ffserver on your server box. This ffserver on the phone is configured to grab the FLV over HTTP from your main server, and then re-stream over RTSP/RTP/UDP. You can play the video from your main server by opening rtsp://127.0.0.1/test.mp4 - the Meridian player makes this easy since it has an Open URL menu for this. The SeeJo player also lets you play URLs.
I don't think I can explain it any more simply than this. If you don't understand how to run ffmpeg, there's plenty of other docs on that.
If you specifically want to stream h,u,l,u videos, you'll need to grab the perl script I posted above and edit the ffmpeg command at the end of the script. The script I attached here was set up to publish a stream to the Darwin Streaming Server over rtsp. A simpler command is used to stream to ffserver.
When publishing to DSS, you have to provide all of the audio/video codec settings on the ffmpeg command line, and the stream gets pushed to rtsp://wherever/the/DSS/server/is/listening.
When publishing to ffserver, all of the audio/video codec settings are in the ffserver.conf file, so you only need to tell ffmpeg where to find its input, and send its output to http://wherever/the/ffserver/is/listening.
Click to expand...
Click to collapse
That's exactly what I was thinking of, thank you very much. I'll give it a shot tonight.
Let us know how it goes. I post stuff here and people download it, but nobody ever gives any feedback...
Thanks!!!
Hi there, this post was extremely helpful and saved me the hassle of trying to compile ffmpeg myself (I'm having huge issues with this).
Are you able to post the ffmpeg compiled binary for Android also? the ffserver one was exactly what I needed!
I didn't compile ffmpeg, I figured there's not much point in running it on a G1, the CPU is too slow to do transcoding in any reasonable amount of time.
What would you want to use it for?
Not transcoding... Just streaming. I need to recieve and play an RTP (not RTSP stream). Unfortunately it's a bug that the current media player can _only_ recieve HTTP or RTSP streams and not straight RTP.
So my ingenious plan is:
RTP stream (pc) -> Phone FFMpeg recieve -> Sends via FFM file to localhost ffserver -> Streams via RTSP to localhost -> local mediaplayer plays RTSP stream.
No transcoding required, just straight restreaming. Unfortunately I'm having difficulties compiling ffmpeg. I think... simply as I'm not particularly skilled in this cross compiling for Android area. Other people say that ffmpeg runs fine however.
This is the only way thus far (unless you use FFMpeg to straight play the stream on Android but this is difficult and has issues I hear).
This solution is necessary as mentioned above the inbuilt mediaplayer cannot play RTP streams (without some modifications to the opencore code which I'm not clever enough to do). Nor can I save the RTP stream to a file and play that as the mediaplayer will only play properly formed files with seek information ??? (go figure).

Can Windows Phone 7 play Ogg Vorbis files?

Simple question really. I'm guessing that it won't be able to, and that you'll need a different app which won't integrate properly into all areas of the OS. I can't find any info on it though.
Cheers
Audio support
Windows Media® Audio Standard3 (WMA) (.wma); Up to 384 Kbps; constant bit rate (CBR) and variable bit rate (VBR) up to 48-kHz sample rate;
WMA Pro two channel up to 768 Kbps; CBR and VBR up to 48-kHz
WMA Lossless: two channel up to 768 kbps and 48-kHz
Advanced Audio Coding (AAC-LC) (.mp4, .m4a, .m4b); .m4a and .m4b files without FairPlay DRM up to 320 Kbps; CBR and VBR up to 48-kHz
MP3 (.mp3); Up to 320 Kbps; CBR and VBR up to 48-kHz
That's copied from the ZuneHD tech specs. I don't see OGG there, so I don't expect it to be compatible. However they might add it on the long run.
I found a great reply to this over at another site, which I'm probably not allowed to mention or link to, so here's the text:
"There is a managed implementation for mono called csvorbis, it includes a sample which outputs a wav file this didn't need many changes to work with XNA's SoundEffect class. I did a whole track at once, this took a few seconds in the emulator so you may need to stream it using DynamicSoundEffect for better results. The mooncodecs folder has a codec for the desktop version based on csvorbis which may be worth a look aswell."
Click to expand...
Click to collapse
Also this:
"With pain. You would have to port the Vorbis source code to safe, managed C# to decode the Vorbis file. I can think of less painful things, such as the removal of both feet."
Click to expand...
Click to collapse
I'm sure I read that Microsoft will be allowing native code soon, after a request from Nokia, so fingers crossed that they'll implement something. It seems unlikely, so maybe this will fall to XDA developers.
There isn't a current solution yet is there? Maybe via a custom ROM?
Why bother with OGG since .wma and .aac are far superior? .wav is the best but the files are too large.
prohibido_por_la_ley said:
Why bother with OGG since .wma and .aac are far superior? .wav is the best but the files are too large.
Click to expand...
Click to collapse
Please stay on topic, the OP didn't ask which one was better.
Moved to Q&A.

[Q]Unsupported File Types (mainly .flac)

I was wondering, is there any type of hack or midification where we would be able to add codecs to the phone in order to play .flac files? I have a lot of my music in that format, and would love to play it. I believe that the first hurdle would be to get the zune player to recognize it, so is there any way to do that as well?
Just a thought. Thanks.
Getting Zune to recognize it is not hard; it's a registry edit under HKEY_CLASSES_ROOT (HKCR) much like it is on Windows. You can look at how WMA and MP3 are handled.
Adding the codec itself... interesting idea. On desktop Windows, codecs are DLLs (they may have other extensions, but that's what they are internally) that take a compressed stream in one function and return an uncompressed stream. It's relatively easy to add more codec support into the OS; create new DLLs to do the decoding, and register them.
The creation of the codecs is possible. I don't know if managed code would work, so you'd probably need to use the native WinCE dev tools. If there's already a FLAC decoder for older versions of WinMo on AR, it may work unmodified. Registering it, though... no idea how to do that. There may be an API for it, though.
GoodDayToDie said:
Getting Zune to recognize it is not hard; it's a registry edit under HKEY_CLASSES_ROOT (HKCR) much like it is on Windows. You can look at how WMA and MP3 are handled.
Adding the codec itself... interesting idea. On desktop Windows, codecs are DLLs (they may have other extensions, but that's what they are internally) that take a compressed stream in one function and return an uncompressed stream. It's relatively easy to add more codec support into the OS; create new DLLs to do the decoding, and register them.
The creation of the codecs is possible. I don't know if managed code would work, so you'd probably need to use the native WinCE dev tools. If there's already a FLAC decoder for older versions of WinMo on AR, it may work unmodified. Registering it, though... no idea how to do that. There may be an API for it, though.
Click to expand...
Click to collapse
Do it!! that would be the coolest thing if we could enable Flac support :X
So it would be great.

Hack suggestion: Winamp+flac plugin

I think this may potentially be an easy thing to do.
First of all, Winamp for desktop has native FLAC support. How hard would it be to adapt a FLAC plugin file to manually stick into a Winamp for Android program folder on your phone and make it recognize and play FLAC files from your phone's music folder? There are a lot of plugins availble for the desktop version of Winamp, this would be like adapting that concept to the Android version of Winamp...
...Or am I just that naive about such things? Simple in theory... but I don't have any such skills to do this myself.
Winamp is my favorite music player for desktop and Android, and I'm probably not the only one. I think a lo of people would appreciate such a plugin!
So... would this be realistic? (Do devs ever come to the Android Software and Hacking General thread and read suggestions?)

[Q] Adding FLAC codec to rooted phone

Hi,
Is it possible to add the FLAC codec to my GingerBurst HTC Desire? I know some player apps can play it but CyangenMod has the codec built in and I'm thinking maybe it's possible to add it?
I would ask in the GingerBurst ROM thread in the developer forum but not enough posts to be allowed.. (Meh)
Thanks.
Add more codec to Native library
Hi all,
I was wondering on similar lines.
Will we be able to enable native support for more codec, by copying the codec library files to the /system/lib directory?
Are there any other configurations that need to be made in order to tell the device what the library file (added) is about?
I want to be able to use FLAC files as a ringtone. That, I guess, will be possible only when there is native support for FLAC.
I own a XPERIA X10 mini (Rooted)
Thanks in advance.
r/\\J35h

Categories

Resources