FFmpegInterop stream to youtube - Windows10 IoT - youtube

I need to get data from rtsp link like code below and stream to youtube rtmp like: rtmp://a.rtmp.youtube.com/live2/e1j9-ag98-vg5p-avhc
but I dont know how to do next with MediaStreamSource
My application will be deploy to RapsberryPi3 - Windows10 IoT ARM
Please help me
try
{
string uri = "rtsp://27.74.XXX.XXX:55/ufirststream";
// Read toggle switches states and use them to setup FFmpeg MSS
bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn;
bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn;
// Set FFmpeg specific options. List of options can be found in https://www.ffmpeg.org/ffmpeg-protocols.html
PropertySet options = new PropertySet();
// Below are some sample options that you can set to configure RTSP streaming
options.Add("rtsp_flags", "prefer_tcp");
options.Add("allowed_media_types", "video");
options.Add("stimeout", 100000 * 5);
options.Add("reorder_queue_size", 1);
options.Add("packet-buffering", 0);
options.Add("fflags", "nobuffer");
options.Add("probesize", 32);
// Instantiate FFmpegInteropMSS using the URI
mediaElement.Stop();
FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(uri, forceDecodeAudio, forceDecodeVideo, options);
if (FFmpegMSS != null)
{
MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();
if (mss != null)
{
// Pass MediaStreamSource to Media Element
mediaElement.SetMediaStreamSource(mss);
// Close control panel after opening media
Splitter.IsPaneOpen = false;
}
else
{
DisplayErrorMessage("Cannot open media");
}
}
else
{
DisplayErrorMessage("Cannot open media");
}
}
catch (Exception ex)
{
DisplayErrorMessage(ex.Message);
}

Related

Media Projection and Image Reader duo not working on Netflix/Youtube on Android TV

Media Projection and Image Reader duo not working on Netflix/Youtube on Android TV.
I am trying to get image from android TV with Media Projection and Image Reader.
On the log side, a warning catches my eye; probably because Image Reader uses OpenGL:
W/libEGL: EGLNativeWindowType 0xd7995a68 disconnect failed
Although it works correctly in the simulator, Image Reader does not work properly in programs such as Youtube, Netflix and so on licensed Android TV. (No problem in simulator)
I tried, works fine on CNBC-e and Android TV User Interface.
I'm starting to think it's due to HDCP. Any guesses about it? Or do you think these programs have Media Projection protection?
Images captured on Netflix and Youtube are always the same. It's like time has stopped.
The heart of my codes is as follows.
private class ImageAvailableListener implements ImageReader.OnImageAvailableListener {
#Override
public void onImageAvailable(ImageReader reader) {
FileOutputStream fos = null;
Bitmap bitmap = null;
try (Image image = mImageReader.acquireLatestImage()) {
if (image != null) {
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = (ByteBuffer) planes[0].getBuffer().rewind();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * mWidth;
// create bitmap
bitmap = Bitmap.createBitmap(mWidth + rowPadding / pixelStride, mHeight, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
// write bitmap to a file
fos = new FileOutputStream(mStoreDir + "/myscreen_" + IMAGES_PRODUCED + ".png");
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
IMAGES_PRODUCED++;
Log.e(TAG, "captured image: " + IMAGES_PRODUCED);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
if (bitmap != null) {
bitmap.recycle();
}
}
}
}
#SuppressLint("WrongConstant")
private void createVirtualDisplay() {
// get width and height
mWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
mHeight = Resources.getSystem().getDisplayMetrics().heightPixels;
// start capture reader
mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
mVirtualDisplay = mMediaProjection.createVirtualDisplay(SCREENCAP_NAME, mWidth, mHeight,
mDensity, getVirtualDisplayFlags(), mImageReader.getSurface(), null, mHandler);
mImageReader.setOnImageAvailableListener(new ImageAvailableListener(), mHandler);
}

How to get webcam video feed in a firefox addon?

I am currently developing an addon where the requirement is to capture the webcam video. I did some testing and noticed that navigator.mediaDevices.getUserMedia() is available within panel and hence have written the following content script for the panel to get webcam video feed from addon.
var mediastream;
var mediarecorder;
// Get the instance of mediaDevices object to use.
navigator.mediaDevices = navigator.mediaDevices || ((navigator.mozGetUserMedia || navigator.webkitGetUserMedia) ? {
getUserMedia: function(c) {
return new Promise(function(y, n) {
(navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
} : null);
function startVideoCapture(width, height, framerate) {
// Check if the browser supports video recording
if (!navigator.mediaDevices) {
return;
}
// Lets initialize the video settings for use for our video recording session
var constraints = { audio: false, video: { width: 640, height: 320, framerate: 25 } };
// Make request to start video capture
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
// Lets initialize the timestamp for this video
var date = new Date();
var milliseconds = "000" + date.getMilliseconds();
var timestamp = date.toLocaleFormat("%Y-%m-%d %H:%M:%S.") + milliseconds.substr(-3);
// Lets make the stream globally available so that we will be able to control it later.
mediastream = stream;
// Lets display the available stream in the video element available inside the panel.
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(stream);
video.onloadedmetadata = function(e) {
video.play();
};
// We are not here to just show the video to screen. Lets get a media recorder to store the video into memory
mediarecorder = new MediaRecorder(stream);
// Lets decide what to do with the recorded video once we are done with the recording
mediarecorder.ondataavailable = function(evt) {
// recorded video will be available as a blob in evt.data object.
// The only way to use it properly is through FileReader Object
var reader = new FileReader();
// Lets decide what we are going to do with the data that we will read from blob
reader.onloadend = function() {
// create a video object containing the timestamp and the binary video string
var videoObject = new Object();
videoObject.timestamp = timestamp;
videoObject.video = reader.result;
// send the video to the main script for safe keeping
self.port.emit("videoAvailable", videoObject);
}
// instruct the FileReader to start reading the blob
reader.readAsBinaryString(evt.data);
}
// Lets start the video capture
mediarecorder.start();
})
.catch(function(err) {
self.port.emit("VideoError", err);
});
}
function stopVideoCapure(){
if (mediarecorder !== undefined && mediarecorder !== null) {
mediarecorder.stop();
}
if (mediastream !== undefined && mediastream !== null) {
mediastream.stop();
}
}
function updateVideoSettings(settings){
stopVideoCapture();
startVideoCapture(settings.width, settings.height, settings.framerate);
}
self.port.on("VideoPreferenceUpdated", updateVideoSettings);
// Start video capture
startVideoCapture(self.options.width, self.options.height, self.options.framerate);
Now the problem here is the code is perfectly working when from a webpage i.e. if I save the open the panel.html file directly in the browser with proper adjustment of self.options and self.port lines. But when I am using the code in the contentscript for panel in my addon, I am getting the following error
JavaScript error: resource:///modules/webrtcUI.jsm, line 186: TypeError: stringBundle is undefined
Now that is an error from the inbuilt jsm module in firefox. Is there a way I can get past that error or any other way to get webcam video feed in my addon?
Thanks

an exception is occurred while play an audio in blackberry

try {
Player p = javax.microedition.media.Manager.createPlayer("abc.mp3");
p.realize();
VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
volume.setLevel(30);
p.prefetch();
p.start();
} catch(MediaException me) {
Dialog.alert(me.toString());
} catch(IOException ioe) {
Dialog.alert(ioe.toString());
}
I used above code to play an audio in blackberry. But it gives an exception error as mentioned in below.
javax.microedition.media.MediaException
If you look at the BlackBerry API docs, you see that for the version of createPlayer() that you use:
MediaException - Thrown if a Player cannot be created for the given locator.
It also says:
locator - A locator string in URI syntax that describes the media content.
Your locator ("abc.mp3") doesn't look like it's in URI syntax. You could try changing that, to something like "file:///SDCard/some-folder/abc.mp3".
Or, if the mp3 file is an app resource, I usually use this code:
try {
java.io.InputStream is = getClass().getResourceAsStream("/sounds/abc.mp3");
javax.microedition.media.Player p =
javax.microedition.media.Manager.createPlayer(is, "audio/mpeg");
p.realize();
// get volume control for player and set volume to max
VolumeControl vc = (VolumeControl) p.getControl("VolumeControl");
if (vc != null) {
vc.setLevel(100);
}
// the player can start with the smallest latency
p.prefetch();
// non-blocking start
p.start();
} catch (javax.microedition.media.MediaException me) {
// do something?
} catch (java.io.IOException ioe) {
// do something?
} catch (java.lang.NullPointerException npe) {
// this happened on Tours without mp3 bugfix
}

XNA XBOX highscore port

I'm trying to port my pc XNA game to the xbox and have tried to implement xna easystorage alongside my existing pc file management for highscores. Basically trying to combine http://xnaessentials.com/tutorials/highscores.aspx/tutorials/highscores.aspx with http://easystorage.codeplex.com/
I'm running into one specific error regarding the LoadHighScores() as error with 'return (data);' - Use of unassigned local variable 'data'.
I presume this is due to async design of easystorage/xbox!? but not sure how to resolve - below are code samples:
ORIGINAL PC CODE: (works on PC)
public static HighScoreData LoadHighScores(string filename)
{
HighScoreData data; // Get the path of the save game
string fullpath = "Content/highscores.lst";
// Open the file
FileStream stream = File.Open(fullpath, FileMode.Open,FileAccess.Read);
try
{ // Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{ // Close the file
stream.Close();
}
return (data);
}
XBOX PORT: (with error)
public static HighScoreData LoadHighScores(string container, string filename)
{
HighScoreData data;
if (Global.SaveDevice.FileExists(container, filename))
{
Global.SaveDevice.Load(container, filename, stream =>
{
File.Open(Global.fileName_options, FileMode.Open,//FileMode.OpenOrCreate,
FileAccess.Read);
try
{
// Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{
// Close the file
stream.Close();
}
});
}
return (data);
}
Any ideas?
Assign data before return. ;)
data = (if_struct) ? new your_struct() : null;
if (Global.SaveDevice.FileExists(container, filename))
{
......
}
return (data);
}

Open pdf, doc, ppt or xls on a BlackBerry

How do I open pdf, doc, ppt or xls programmatically on a BlackBerry?
The best approach is to purchase a 3rd-party viewer and launch that to view the document:
String path = "file://SDCard/info.doc";
String contentType = MIMETypeAssociations.getMIMEType(path);
Invocation invocation = new Invocation(path, contentType, null, false, ContentHandler.ACTION_OPEN);
Registry registry = Registry.getRegistry(MyApp.class.getName());
try {
ContentHandler[] handlers = registry.findHandler(invocation);
if (handlers != null && handlers.length > 0) {
invocation.setID(handlers[0].getID());
registry.invoke(invocation);
} else {
Dialog.alert("Error");
}
} catch (Exception e) {
Dialog.alert("Error");
}

Resources