android record video(3gp) to remote server

690 views
Skip to first unread message

zongan liu

unread,
Oct 18, 2009, 11:36:39 PM10/18/09
to Android Developers
After several days of agonizing, ultimately did not solve the problem,
is hereby published issue and hoping to get friends to help.

Requirements: The android to record video and transmitted through the
socket means to save the file on the server (3gp file).

Question: 3gp files saved to the server, mobile player can't open, 3gp
file encoding is not correct.

Note: stored in the phone's local system, 3gp files encoded in the
correct format, mobile phone player to open.

android record code:

String hostname = "192.168.20.106";
int port = 1234;
try
{
socket = new Socket(InetAddress.getByName(hostname), port);
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
mMediaRecorder = new MediaRecorder();

// 设置以流方式输出
mMediaRecorder.setOutputFile(pfd.getFileDescriptor());
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat
(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setVideoSize(176, 144);
mMediaRecorder.setVideoFrameRate(15);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setMaxDuration(10000);


Server receives the data code:
public MultiThreadServer() throws IOException
{
serverSocket = new ServerSocket(port);
// Runtime的availableProcessor()方法返回当前系统的CPU数目.
executorService = Executors.newFixedThreadPool(Runtime.getRuntime
().availableProcessors() * POOL_SIZE);

System.out.println("服务器启动");
}

public void service()
{
while (true)
{
Socket socket = null;
try
{
// 接收客户连接,只要客户进行了连接,就会触发accept();从而建立连接
socket = serverSocket.accept();
//executorService.execute(new Handler(socket));
new Thread(new Handler(socket)).start();

}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Handler class code:

public Handler(Socket socket)
{
this.socket = socket;
d = new File("D:/ds");
if (!d.exists())
{
d.mkdirs();
}

try
{
store = File.createTempFile("sdsd", ".3gp", d);
fos = new FileOutputStream(store);
socketIn = socket.getInputStream();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void run()
{
try
{
System.out.println("New connection accepted " +
socket.getInetAddress() + ":" + socket.getPort());

while ((length = socketIn.read(buffer)) != -1)
{
fos.write(buffer, 0, length);
fos.flush();
System.out.println("正在写入中。。。。" + length);
}

fos.flush();
store = null;
socketIn.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
fos.close();
fos = null;
store = null;
if (socket != null)
socket.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println("-----------------------------完毕");
}



You help me find the cause of it, in this thank you. Given at the high
score! ! !

fala70

unread,
Oct 19, 2009, 3:24:27 PM10/19/09
to Android Developers
Can you explain better your problem ? Can you receive data side
server ?

Jason Proctor

unread,
Oct 19, 2009, 3:30:34 PM10/19/09
to android-d...@googlegroups.com
just a knee-jerk here, but i think the problem
might be that the recorder requires random access
to the resource to write meta information etc.
easy to rewind a file and update it, not so easy
on a socket.....



>Can you explain better your problem ? Can you receive data side
>server ?
>
>On 19 Ott, 05:36, zongan liu <liuzongan1...@gmail.com> wrote:
>> After several days of agonizing, ultimately did not solve the problem,
>> is hereby published issue and hoping to get friends to help.
>>
>> Requirements: The android to record video and transmitted through the
>> socket means to save the file on the server (3gp file).
>>
>> Question: 3gp files saved to the server, mobile player can't open, 3gp
>> file encoding is not correct.
>>
>> Note: stored in the phone's local system, 3gp files encoded in the
>> correct format, mobile phone player to open.
>>
>> android record code:
>>
>> String hostname = "192.168.20.106";
>> int port = 1234;
>> try
>> {
>> socket = new
>>Socket(InetAddress.getByName(hostname), port);
>> }
>> catch (UnknownHostException e)
>> {
>> e.printStackTrace();
>> }
>> catch (IOException e)
>> {
>> e.printStackTrace();
>> }
>> ParcelFileDescriptor pfd =
>>ParcelFileDescriptor.fromSocket(socket);
>> mMediaRecorder = new MediaRecorder();
>>
>> // ŠËíuà»ó¨ïšéÆ ”èo
>> mMediaRecorder.setOutputFile(pfd.getFileDescriptor());
>>
>>mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
>>
>>mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
>>
>>mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
>> mMediaRecorder.setOutputFormat
>> (MediaRecorder.OutputFormat.THREE_GPP);
>> mMediaRecorder.setVideoSize(176, 144);
>> mMediaRecorder.setVideoFrameRate(15);
>>
>>mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
>>
>>mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
>> mMediaRecorder.setMaxDuration(10000);
>>
>> Server receives the data code:
>> public MultiThreadServer() throws IOException
>> {
>> serverSocket = new ServerSocket(port);
>> // RuntimeìIavailableProcessor()ïšñ@ï'âÒìñëOånÕ„ìICPUêîñŽ.
>> executorService =
>>Executors.newFixedThreadPool(Runtime.getRuntime
>> ().availableProcessors() * POOL_SIZE);
>>
>> System.out.println("ïû‘ÒäÌ Ù Ø");
>> }
>>
>> public void service()
>> {
>> while (true)
>> {
>> Socket socket = null;
>> try
>> {
>> //
>>êŽùæãqªß¡¨êŽ,ë¸óvãqªß‡¯çs󼡨êŽ,èAâÔêG…¢accept();ò½éßåöóß¡¨êŽ
>>System.out.println("ê„çðé ì¸íÜÅBÅBÅBÅB" +
>>length);
>> }
>>
>> fos.flush();
>> store = null;
>> socketIn.close();
>> }
>> catch (IOException e)
>> {
>> e.printStackTrace();
>> }
>> finally
>> {
>> try
>> {
>> fos.close();
>> fos = null;
>> store = null;
>> if (socket != null)
>> socket.close();
>> }
>> catch (IOException e)
>> {
>> e.printStackTrace();
>> }
>> }
>> System.out.println("-----------------------------äƱ¦");
>> }
>>
>> You help me find the cause of it, in this thank you. Given at the high
>> score! ! !
>

--
jason.vp.engineering.particle

Roman ( T-Mobile USA)

unread,
Oct 19, 2009, 6:21:12 PM10/19/09
to Android Developers
A file which is recorded as a 3gp file by the Android MediaRecorder is
NOT streamable. You would need to make it streamable before trying to
play it back via the MediaPlayer.

--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.

ivan

unread,
Oct 21, 2009, 3:16:57 AM10/21/09
to Android Developers
Are there plans to implement 3gps, 3gpt or 3gpr streamable formats
from the MediaRecorder?

On Oct 19, 4:21 pm, "Roman ( T-Mobile USA)" <roman.baumgaert...@t-
mobile.com> wrote:
> A file which is recorded as a3gpfile by the Android MediaRecorder is
> NOT streamable. You would need to make it streamable before trying to
> play it back via the MediaPlayer.
>
> --
> Roman Baumgaertner
> Sr. SW Engineer-OSDC
> ·T· · ·Mobile· stick together
> The views, opinions and statements in this email are those of the
> author solely in their individual capacity, and do not necessarily
> represent those of T-Mobile USA, Inc.
>
> On Oct 18, 8:36 pm, zongan liu <liuzongan1...@gmail.com> wrote:
>
>
>
> > After several days of agonizing, ultimately did not solve the problem,
> > is hereby published issue and hoping to get friends to help.
>
> > Requirements: The android to record video and transmitted through the
> > socket means to save the file on the server (3gpfile).
>
> > Question:3gpfiles saved to the server, mobile player can't open,3gp
> > file encoding is not correct.
>
> > Note: stored in the phone's local system,3gpfiles encoded in the
> > score! ! !- Hide quoted text -
>
> - Show quoted text -

Roman ( T-Mobile USA)

unread,
Oct 21, 2009, 2:16:45 PM10/21/09
to Android Developers
I have no idea what will be supported in future. I hope only that the
media framework offers a much better support for real time streaming.

You could try to port some open source code to Android which converts
3gp to a streamable format.

--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.

ivan

unread,
Oct 21, 2009, 8:30:27 PM10/21/09
to Android Developers
You wouldn't happen to know of any off hand...?

On Oct 21, 12:16 pm, "Roman ( T-Mobile USA)" <roman.baumgaert...@t-
mobile.com> wrote:
> I have no idea what will be supported in future. I hope only that the
> media framework offers a much better support for real time streaming.
>
> You could try to port some open source code to Android which converts3gpto a streamable format.
> > > - Show quoted text -- Hide quoted text -

Roman ( T-Mobile USA)

unread,
Oct 21, 2009, 10:58:49 PM10/21/09
to Android Developers
Check the Gpac source forge page

http://gpac.cvs.sourceforge.net/viewvc/gpac/gpac/applications/mp4box/

The app mp4box does the conversion.



Roman ( T-Mobile USA)
View profile
More options Oct 21, 11:16 am
From: "Roman ( T-Mobile USA)" <roman.baumgaert...@t-mobile.com>
Date: Wed, 21 Oct 2009 11:16:45 -0700 (PDT)
Local: Wed, Oct 21 2009 11:16 am
Subject: Re: android record video(3gp) to remote server
Reply | Reply to author | Forward | Print | Individual message | Show
original | Remove | Report this message | Find messages by this author
I have no idea what will be supported in future. I hope only that the
media framework offers a much better support for real time streaming.

You could try to port some open source code to Android which converts
3gp to a streamable format.

--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.

Reply all
Reply to author
Forward
0 new messages