[android-developers] Video with MediaRecorder

2009-08-17 Thread Jason Proctor

yeah you probably want to capture to /sdcard/

/videotest.3gp most definitely is not writable to a regular android app!

other than that your code is pretty much the same as mine.



Hi Jason, perhaps you could help me with my code. I was trying to
capture video for two weeks now without success :(

This is my complete code


public class VideoCapture extends Activity
   implements SurfaceHolder.Callback {

   private static final String TAG = JTrek Video Capture;
   private SurfaceView surfaceView;
 private SurfaceHolder surfaceHolder;
 private MediaRecorder recorder;
 private String videoFile = videotest.3gp;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 surfaceView = (SurfaceView)findViewById(R.id.surface);

 surfaceHolder = surfaceView.getHolder();
 surfaceHolder.addCallback(this);
 surfaceHolder.setType
(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

 setRequestedOrientation
(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

 prepareVideoCapture();
 }

 public void prepareVideoCapture() {
   /* Create a MediaRecorder */
   recorder = new MediaRecorder();
   Log.i(TAG, Media recorder created);

   try {
   OutputStream stream = openFileOutput(videoFile,
MODE_WORLD_WRITEABLE);
   stream.write(0xA);
   stream.close();
   } catch(IOException ioException) {
   Log.e(TAG, VIDEO: An error creating the output file.);
   }

   File file = getFileStreamPath(videoFile);
   Log.i(TAG, File exists? :  + file.exists());

   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
   recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
   recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);

   recorder.setOutputFile(this.videoFile);
   Log.i(TAG, Media recorder parameters set);

   recorder.setPreviewDisplay(surfaceHolder.getSurface());
   Log.i(TAG, Preview Display set to surface holder!);
 }

   //

 //SURFACE CALLBACK 
 IMPLEMENTATION
 //

 public void surfaceCreated(SurfaceHolder holder) {
 Log.e(TAG, surfaceCreated);

 try {
 recorder.prepare();
   } catch (IllegalStateException e) {
 Log.e(TAG, e.toString());
   } catch (IOException e) {
 Log.e(TAG, THE ERROR IS HERE!:  + e.toString());
   }

   Log.i(TAG, Media recorder prepared for video capture!);

 try {
   recorder.start();
   } catch (IllegalStateException e) {
   Log.e(TAG, e.toString());
   }
   Log.i(TAG, Video capture started!!);
 }

 public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
 Log.e(TAG, surfaceChanged);
 }

 public void surfaceDestroyed(SurfaceHolder holder) {
 Log.e(TAG, surfaceDestroyed);
 }
 //


 protected void onStop() {
   // Stops the media recorder object
   recorder.stop();
   recorder.release();

 Log.e(TAG, onStop);
 super.onStop();
 }
}

And this is the LogCat I received when debugging:
=

08-17 10:51:22.400: INFO/Video Capture(709): Media recorder created
08-17 10:51:22.450: INFO/Video Capture(709): File exists? : true
08-17 10:51:22.571: INFO/Video Capture(709): Media recorder parameters
set
08-17 10:51:22.581: INFO/Video Capture(709): Preview Display set to
surface holder!
08-17 10:51:23.132: ERROR/Video Capture(709): surfaceCreated
08-17 10:51:23.181: ERROR/Video Capture(709): THE ERROR IS HERE!:
java.io.FileNotFoundException: /videotest.3gp
08-17 10:51:23.191: INFO/Video Capture(709): Media recorder prepared
for video capture!
08-17 10:51:23.191: ERROR/MediaRecorder(709): start called in an
invalid state: 4
08-17 10:51:23.200: ERROR/Video Capture(709):
java.lang.IllegalStateException
08-17 10:51:23.210: INFO/Video Capture(709): Video capture started!!
08-17 10:51:23.210: ERROR/Video Capture(709): surfaceChanged

I am also wondering if it is mandatory to capture video in external
memory instead of internal memory?
Thanks in advance. I appreciate any help you can give me!..


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to 

[android-developers] Video with MediaRecorder

2009-08-12 Thread Jason Proctor

i mean the code inside my application which calls MediaRecorder to 
record video.

btw, since 1.5 i have not found any problems with MediaRecorder. the 
order of the configuration set() methods must be right, but if you 
read the documentation and look at the error log, the order becomes 
clear.



  Hi Jason.
  What do you mean with my own MediaRecorder code?


On Jul 17, 11:50 am, Jason Proctor jason.android.li...@gmail.com
wrote:
  if you're using the camera on the emulator, then you have to disable
  auto orientation changes to get it to work. at least, i picked this
  info off the network and it worked for me.

  i'm doing manual capture with my own MediaRecorder code, and remote
  capture with the vide capture intent, successfully on emulator and
  real phone (in this case, ADP and Ion).



  does it mean there is a bug in this intent
  android.provider.MediaStore.ACTION_VIDEO_CAPTURE

  is anybody have luck?

  On Mon, Jul 13, 2009 at 9:11 PM, hanged_man
  mailto:majd...@gmail.commajd...@gmail.com wrote:

  Muhammad, i tried the issue locally and it seems to be something wrong
  with the camcorder itself (in the emulator), my previously suggested
  workaround
  
 (http://groups.google.com/group/android-developers/http://groups.google.com/group/android-developers/

  browse_thread/thread/60005bb7fff2e14f/eec39e24877d8b42?

  hl=enlnk=gstq=black+screen+camera+hanged_man#eec39e24877d8b42) works
  only with the Camera app, i've tested it by not running it via the
  intents but by running it directly from the home screen, however
  trying to run the camcorder app results in a black screen and no idea
  why.
  And another stupid thing, try running the camcorder first (ofcourse
  you will get a black screen) then try running the camera and
  surprisingly you will get another black screen, i remember that i've
  read somewhere that the camera-related apps hold a lock on certain
  resource related to the camera which explains why this is happening.
  Now this is stupid, i was counting on the fact that the camcorder is
  working and trying to implement my own is going to be painfully
  annoying :(

  --
  jason.software.particle



-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-07-17 Thread Jason Proctor

if you're using the camera on the emulator, then you have to disable 
auto orientation changes to get it to work. at least, i picked this 
info off the network and it worked for me.

i'm doing manual capture with my own MediaRecorder code, and remote 
capture with the vide capture intent, successfully on emulator and 
real phone (in this case, ADP and Ion).



does it mean there is a bug in this intent 
android.provider.MediaStore.ACTION_VIDEO_CAPTURE

is anybody have luck?



On Mon, Jul 13, 2009 at 9:11 PM, hanged_man 
mailto:majd...@gmail.commajd...@gmail.com wrote:


Muhammad, i tried the issue locally and it seems to be something wrong
with the camcorder itself (in the emulator), my previously suggested
workaround 
(http://groups.google.com/group/android-developers/http://groups.google.com/group/android-developers/

browse_thread/thread/60005bb7fff2e14f/eec39e24877d8b42?

hl=enlnk=gstq=black+screen+camera+hanged_man#eec39e24877d8b42) works
only with the Camera app, i've tested it by not running it via the
intents but by running it directly from the home screen, however
trying to run the camcorder app results in a black screen and no idea
why.
And another stupid thing, try running the camcorder first (ofcourse
you will get a black screen) then try running the camera and
surprisingly you will get another black screen, i remember that i've
read somewhere that the camera-related apps hold a lock on certain
resource related to the camera which explains why this is happening.
Now this is stupid, i was counting on the fact that the camcorder is
working and trying to implement my own is going to be painfully
annoying :(



-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-22 Thread Jason Proctor

can you log the exception and post it? thanks.


I am trying to capture video with the same code above but it crash at
- recorder.prepare();
cant track what is the problem, does anybody come across similar
problem ; any hint?

On May 7, 11:50 pm, Jason Proctor ja...@particularplace.com wrote:
  btw, since streaming movies via HTTP requires the moov atom to be
  ahead of the mdat atom in the file, it would therefore be handy if
  MediaRecorder wrote the file like that :-)

  will this be fixed do you think? wondering whether i should just
  write that piece of code anyway.

  --
  jason.software.particle


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-07 Thread Jason Proctor

i set orientation=landscape for my capture activity, which seems to 
do the right thing most of the time.

every now and then however, the phone ignores it and restarts my 
activity if the user rotates the phone. which they have to do, 
because the camera only works in landscape.

not sure why this would be an intermittent type thing.


Hi,

Thanks, I got it to work.

I have one problem though. When I rotate the phone, using automatic
Orientation the onDestroy() method of my activity is called, which
effectively also stops capturing. When the activity is recreated, a
new capture starts. This means I will now have two files for the same
capture since the user didnt choose to stop the capture. (And I need
to merge these files).

Does anyone know of a way to keep the capture running when rotating
the phone?

Thanks,
Anders

On May 6, 8:11 pm, Jason Proctor ja...@particularplace.com wrote:
  just a tiny fyi here is that i did manage to get video recording
  working fine in my app.

  there is however a problem if the surface view fills its parent and
  the parent is the entire screen. if that happens, then the camera's
  view of things gets resized but nobody tells the codec, and hence the
  movie is messed up. it's encoded for one size but the movie metainfo
  says something else.

  making the size something smaller than the screen made it work, but
  it *is* a bug IMHO.

  --
  jason.software.particle


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-07 Thread Jason Proctor

i don't change it, it gets changed by the Author Driver presumably 
to avoid colliding with the status bar or somesuch.

here's some log output which might illustrate what's going on --

05-07 11:13:51.516: WARN/AuthorDriver(35): Intended width(480) 
exceeds the max allowed width(352). Max width is used instead. 05-07 
11:13:51.516: WARN/AuthorDriver(35): Intended height(295) exceeds the 
max allowed height(288). Max height is used instead.
however, a bit later on it seems that nobody has told the camera this --

05-07 11:13:51.686: VERBOSE/QualcommCameraHardware(35): requested 
size 480 x 320 05-07 11:13:51.686: 
VERBOSE/QualcommCameraHardware(35): actual size 480 x 320
so the codec is encoding for 480x320, but the surface is only 
delivering 352x288. hence the corruption.

hth
j



This is a limitation of the hardware, the preview size and encoded
size must be the same.

I'm not sure how you were able to change the preview size though. I'd
like to know the code sequence you used, because it's not supposed to
be possible.

On May 6, 11:11 am, Jason Proctor ja...@particularplace.com wrote:
  just a tiny fyi here is that i did manage to get video recording
  working fine in my app.

  there is however a problem if the surface view fills its parent and
  the parent is the entire screen. if that happens, then the camera's
  view of things gets resized but nobody tells the codec, and hence the
  movie is messed up. it's encoded for one size but the movie metainfo
  says something else.

  making the size something smaller than the screen made it work, but
  it *is* a bug IMHO.

  --
  jason.software.particle


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-07 Thread Jason Proctor

yes. the movie file is correctly formed, but the picture is messed 
up. i've not tried correcting the metadata in the file, but that 
*should* fix it.

either way, AuthorDriver or whoever should be telling 
QualcommCameraHardware what's going on, IMHO.



Wait, when you say corruption, you really mean that there's a mismatch
between the metadata and the actual frame size, is that correct?

On May 7, 11:17 am, Jason Proctor ja...@particularplace.com wrote:
  i don't change it, it gets changed by the Author Driver presumably
  to avoid colliding with the status bar or somesuch.

  here's some log output which might illustrate what's going on --

  05-07 11:13:51.516: WARN/AuthorDriver(35): Intended width(480)
  exceeds the max allowed width(352). Max width is used instead. 05-07
  11:13:51.516: WARN/AuthorDriver(35): Intended height(295) exceeds the
  max allowed height(288). Max height is used instead.
  however, a bit later on it seems that nobody has told the camera this --

  05-07 11:13:51.686: VERBOSE/QualcommCameraHardware(35): requested
  size 480 x 320 05-07 11:13:51.686:
  VERBOSE/QualcommCameraHardware(35): actual size 480 x 320
  so the codec is encoding for 480x320, but the surface is only
  delivering 352x288. hence the corruption.

  hth
  j



  This is a limitation of the hardware, the preview size and encoded
  size must be the same.

  I'm not sure how you were able to change the preview size though. I'd
  like to know the code sequence you used, because it's not supposed to
  be possible.

  On May 6, 11:11 am, Jason Proctor ja...@particularplace.com wrote:
just a tiny fyi here is that i did manage to get video recording
working fine in my app.

there is however a problem if the surface view fills its parent and
the parent is the entire screen. if that happens, then the camera's
view of things gets resized but nobody tells the codec, and hence the
movie is messed up. it's encoded for one size but the movie metainfo
says something else.

making the size something smaller than the screen made it work, but
it *is* a bug IMHO.

--
jason.software.particle

  --
  jason.software.particle


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-07 Thread Jason Proctor

you're welcome. video recording has been a long difficult road from 
the massively problematic recording of still camera previews to the 
comparitively easy ride we have now :-)

ideally i'd be able to change the orientation of the camera, but 
apparently that's a hardware issue and can't be fixed on the G1/ADP 
at least.


Hi,

Jason, thank you. That really helped a lot. I no longer see onDestroy
being called all the time.

Before setting the orientation to LANDSCAPE, the preview display was
wrong. The display was rotated 90 degrees and the picture a bit
distorted  After setting the orientation everything looks the way I
would I expect it to be; When in portrait, the preview is in portrait
as well as the captured video, and when in landscape both preview and
capture is in landscape. In my opinion, this setting should be the
default setting.

For future reference, here is a snippet of my code.
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setOutputFile(filePath);

CameraView.thisCameraView.setRequestedOrientation
(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

recorder.setPreviewDisplay(sv);
recorder.prepare();
recorder.start();

CameraView is my activity displaying the preview, that includes my
SurfaceView class (sv is the surface of the holder) and camera object.

Thanks,
Anders


On May 7, 8:56 pm, Jason Proctor ja...@particularplace.com wrote:
  yes. the movie file is correctly formed, but the picture is messed
  up. i've not tried correcting the metadata in the file, but that
  *should* fix it.

  either way, AuthorDriver or whoever should be telling
  QualcommCameraHardware what's going on, IMHO.



  Wait, when you say corruption, you really mean that there's a mismatch
  between the metadata and the actual frame size, is that correct?

  On May 7, 11:17 am, Jason Proctor ja...@particularplace.com wrote:
i don't change it, it gets changed by the Author Driver presumably
to avoid colliding with the status bar or somesuch.

here's some log output which might illustrate what's going on --

05-07 11:13:51.516: WARN/AuthorDriver(35): Intended width(480)
exceeds the max allowed width(352). Max width is used instead. 05-07
11:13:51.516: WARN/AuthorDriver(35): Intended height(295) exceeds the
max allowed height(288). Max height is used instead.
however, a bit later on it seems that nobody has told the camera this --

05-07 11:13:51.686: VERBOSE/QualcommCameraHardware(35): requested
size 480 x 320 05-07 11:13:51.686:
VERBOSE/QualcommCameraHardware(35): actual size 480 x 320
so the codec is encoding for 480x320, but the surface is only
delivering 352x288. hence the corruption.

hth
j

This is a limitation of the hardware, the preview size and encoded
size must be the same.

I'm not sure how you were able to change the preview size though. I'd
like to know the code sequence you used, because it's not supposed to
be possible.

On May 6, 11:11 am, Jason Proctor ja...@particularplace.com wrote:
  just a tiny fyi here is that i did manage to get video recording
  working fine in my app.

  there is however a problem if the surface view fills its parent and
  the parent is the entire screen. if that happens, then the camera's
  view of things gets resized but nobody tells the codec, 
and hence the
  movie is messed up. it's encoded for one size but the movie metainfo
  says something else.

  making the size something smaller than the screen made it work, but
  it *is* a bug IMHO.

   --
  jason.software.particle

--
jason.software.particle

  --
  jason.software.particle


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-07 Thread Jason Proctor

btw, since streaming movies via HTTP requires the moov atom to be 
ahead of the mdat atom in the file, it would therefore be handy if 
MediaRecorder wrote the file like that :-)

will this be fixed do you think? wondering whether i should just 
write that piece of code anyway.


-- 
jason.software.particle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Video with MediaRecorder

2009-05-06 Thread Anders Nilsson Plymoth
Hi,

Does anyone know how to use the MediaRecorder to API to capture video?

I am writing an application where I want to be able to capture video. I am
trying to use the MediaRecorder API in 1.5, which is supposed to support
video capture. However, there are no examples in the documentation on how to
use this API for video (only for audio, and that works perfect). Basically
what I do is the following:

final MediaRecorder recorder = new MediaRecorder();
final String filePath;



recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setOutputFile(filePath);
recorder.prepare();
recorder.start();

This gives me the following error:
E/CameraInput(   37): No surface is available for display
E/MediaRecorder( 7609): prepare failed: -2147483648

OK, so I have to have a surface to preview the video? Could be useful I
guess, but not something I really need.

Could I use the VideoView widget for this, or is that only for playback?

Or am I supposed to use a SurfaceView to preview the video? I saw someone
use that to capture images, but they used android.hardware.Camera to open
the camera and capture a frame, and did not use MediaRecorder.

Does anyone have any idea on how to capture video, or even better have some
example code?

Thanks,
Anders

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---