Video upload and streaming Record video Android camera

  • Slides: 12
Download presentation
Video upload and streaming • Record video – Android camera – Looxcie • Upload

Video upload and streaming • Record video – Android camera – Looxcie • Upload video – http put – Thread • Video streaming – Streaming server – Video formatting – Playing a video stream

Record video • Recording with phone’s camera is in another lecture • Looxcie –

Record video • Recording with phone’s camera is in another lecture • Looxcie – records video and holds it in the camera. – Looxcie app pulls the video from camera to phone

ftp package • New app – Video. Streamer – Add user permission: Internet •

ftp package • New app – Video. Streamer – Add user permission: Internet • ftp package – Download apache commons. net package from • http: //commons. apache. org/net/download_net. cgi – Get binary – Decompress – Add package • • • Right on the src directory of the newly made app Select build path -> configure build path Click add external jar. Browse to commons-net-2. 2. jar Select “Order and Export” tab Click commons-net-2. 2. jar

Using ftp • Make new class, FTPHelper • Add member function, upload. File FTPClient

Using ftp • Make new class, FTPHelper • Add member function, upload. File FTPClient ftp. Client = new FTPClient(); ftp. Client. connect( "128. 4. 35. 59" ); ftp. Client. login( "ftpuser", "ftpuser" ); System. out. println("Connected to 128. 4. 35. 59"); System. out. print(ftp. Client. get. Reply. String()); Buffered. Input. Stream buff. In = null; buff. In = new Buffered. Input. Stream(new File. Input. Stream("/mnt/sdcard/my_mov. mp 4")); – result = ftp. Client. store. File("my_vov. mp 4", buff. In); – if (result) { – – – – • Log. e("Debug. Info", "ftp trasnfer returned true"); – } else { – } • Log. e("Debug. Info", "ftp trasnfer returned false");

In Video. Streamer class • At the end of on. Create, add – FTP

In Video. Streamer class • At the end of on. Create, add – FTP ftp = new FTP(); – ftp. upload. File(); • Run • If the file is very large, this will fail because the UI thread cannot take too long • You must use theads

threads • async. Task - easy threads • In Video. Streamer class, add new

threads • async. Task - easy threads • In Video. Streamer class, add new class – private class Upload. File. Task extends Async. Task {} – Let eclipse add unimplemented methods • Move from on. Create to do. In. Background – FTP ftp = new FTP(); – ftp. upload. File(); • In on. Create, add – new Upload. File. Task(). execute(); • Run.

Video Server • Popular video servers – Darwin • • Apple version Open source

Video Server • Popular video servers – Darwin • • Apple version Open source version Supports many formats including quicktime I couldn’t get it working on windows – Wowza • Not open source • Free (for a small number of users/downloaders)

Try it • Take video with phone • Pull file from phone (in /mnt/sdcard/DCIM/Camera/*.

Try it • Take video with phone • Pull file from phone (in /mnt/sdcard/DCIM/Camera/*. 3 gp) • Put file in – C: Program Files (x 86)Wowza Media SystemsWowza Media Server 2. 2. 3content • Open VLC – Select menu: media -> network stream – enter rtsp: //128. 4. 35. 53: 1935/vod/mp 4: Vid 3. mp 4 – Where Vid 3. mp 4 is the name • Does not work

Streaming Video Format • It is not always possible to stream a video captured

Streaming Video Format • It is not always possible to stream a video captured by any video camera • Wowza Media Server and Flash only support H. 264 (AVC 1, MPEG 4 Part 10), AAC (MP 4 A, AAC+, HE-AAC) and MP 3 in an MP 4 file. – http: //www. wowzamedia. com/forums/content. php? 107 -GSpot-Tool-to-inspect-MP 4 -%28 Quick. Timecontainer%29 -video-audio-codecs • The format can be checked – Gspot: http: //www. headbands. com/gspot/ – Shows the format details

transcoding • MS Expression can also make video files that can be streamed. But

transcoding • MS Expression can also make video files that can be streamed. But this requires manual effort, whereas ffmpeg can be run from command line or a script • Ffmpeg can be used to transcode – read a video file compressed in one set of codecs and recompress in another set • Transcoding is very slow – Works better if the source is low bit-rate. On phone video, select low rate • Using ffmpeg is tricky – The following perl code transcode. pl • #!/usr/bin/perl • d: \uploaded. Content\ffmpeg\bin\ffmpeg. exe -i $ARGV[0] -strict experimental -acodec aac -ab 32 k vcodec libx 264 -fpre libx 264 -medium. ffpreset -b 512 k $ARGV[0]. mp 4 – Call via>> perl transode. pl filename. 3 gp – These parameters can be adjusted – Try it: • Take video with camera • Pull from phone, move to directory where ffmpeg is located (might need to copy FFPreset files to this directory) • Run perl code – Wait • Move file to directory • View with vlc

Video streaming on android • Change the Video. Streaming Activity so that it –

Video streaming on android • Change the Video. Streaming Activity so that it – • Add member variables – – – • • Button start. Button = (Button)find. View. By. Id(R. id. Start. Video); start. Button. set. On. Click. Listener(new View. On. Click. Listener() {}); In on. Click, add • play. Video(); Make public void play. Video() { – – – • m. Preview = (Surface. View) find. View. By. Id(R. id. Surface. View); holder = m. Preview. get. Holder(); holder. add. Callback(this); holder. set. Type(Surface. Holder. SURFACE_TYPE_PUSH_BUFFERS); Add button, Start. Video Add callback – – – • private Surface. View m. Preview; private Surface. Holder holder; private Media. Player m. Media. Player; Add surface view to layout. Call it Surface. View At the end of on. Create, – – • • implements Surface. Holder. Callback Run – if (m. Media. Player != null) { m. Media. Player. release(); m. Media. Player = null; } m. Media. Player = new Media. Player(); //m. Media. Player. set. Data. Source("/mnt/sdcard/DCIM/Camera/VID_20110502_143808. 3 gp"); // some file m. Media. Player. set. Data. Source("rtsp: //128. 4. 35. 53: 1935/vod/mp 4: Vid 3. mp 4"); // some stream //m. Media. Player. set. Data. Source("rtsp: //128. 4. 35. 53: 1935/vod/mp 4: sample. mp 4"); m. Media. Player. set. Display(holder); m. Media. Player. prepare(); m. Media. Player. set. Audio. Stream. Type(Audio. Manager. STREAM_MUSIC); m. Media. Player. start(); It takes a long time. But should run

improvements • • Lots of things can be improved with callbacks Put progress bar

improvements • • Lots of things can be improved with callbacks Put progress bar to give the user feedback as video is starting In layout, add Progress. Bar Add member variable – • In on. Create, – – • Progress. Bar progress. Bar; progress. Bar = (Progress. Bar)find. View. By. Id(R. id. Progress. Bar 01); progress. Bar. set. Visibility(View. INVISIBLE); In play. Video – – At the beginning, add progress. Bar. set. Visibility(View. VISIBLE); After m. Media. Player = new Media. Player(); , add • • m. Media. Player. set. On. Prepared. Listener(new On. Prepared. Listener() {}); In on. Prepared, add – – – Change m. Media. Player. prepare(); to – Remove m. Media. Player. start(); • • • progress. Bar. set. Visibility(View. INVISIBLE); m. Media. Player. start(); m. Media. Player. prepare. Async(); Now run, and progress bar shows that something is happening But if an error occurs, the progress bar never stops – Need to add more callbacks • • • set. On. Error. Listener(android. media. Media. Player. On. Error. Listener) to catch errors set. On. Completion. Listener(On. Completion. Listener). , when it finished, to clean up screen or something set. On. Buffering. Update. Listener to track the buffer, this gives a percent