VLC: saving a stream to a file - vlc

This code works with VLC 2.2.8 but it does not with VLC 3.0.9.2
if (it->second.handle && it->second.fDump) {
// Video/audio + file dump -> duplicate stream
transcode = "#duplicate{ dst=file{ dst=" + string(it->second.fDump) + " }, dst=display }";
}
else if (it->second.handle == NULL) {
// No video + file dump -> single stream
transcode = "#standard{ access=file, dst='" + string(it->second.fDump) + "' }";
}
I am focusing on the second branch and I wish to receive suggestions, thanks.
UPDATE:
It does not work means that it does not throw any error nor warning but it does not create the file. It seems, it ignores the option.
UPDATE 2:
I suspect that the saving option is ignored because I see this line in the application log which is related to the GPU but I have no way to see the video output:
avcodec: Using OpenGL/VAAPI backend for VDPAU for hardware decoding
It is not required decoding the stream but simply saving.
UPDATE 3:
I do not use the graphic interface but the command line and this works:
vlc rtsp://172.18.2.60:554/Streaming/Channels/1 --rtsp-user=$user --rtsp-pwd=$passwd \
--sout="#file{dst=test.mp4}" --vout=dummy -Idummy --ignore-config --quiet \
--rtsp-frame-buffer-size=500000 --network-caching=4000
However, trying to send the same trough VLC library API, it does not save the file. Then the issue should be in this piece of code which works with VLC 2.2.8:
it->second.p_lib = libvlc_new((int)argsCount, p_args);
if (!it->second.p_lib) {
HVLog("Cannot initialize VLC engine");
return -1;
}
// Set up logging
libvlc_log_set(it->second.p_lib, s_vlc_logcb, nullptr);
libvlc_media_t *p_url = libvlc_media_new_location(it->second.p_lib, url.c_str());
it->second.p_player = libvlc_media_player_new_from_media(p_url);
libvlc_media_release(p_url);
if (it->second.handle)
libvlc_media_player_set_hwnd(it->second.p_player, it->second.handle);
if (libvlc_media_player_play(it->second.p_player) < 0) {
HVLog("HVPlayOpen(%p, %d): cannot play stream %s", p_cam, channel, url.c_str());
return -1;
}
return 0;
For testing, I used this code instead and it works, obviously.
char vlcstr[1024];
snprintf(vlcstr, 1024, "vlc %s --rtsp-user=%s --rtsp-pwd=%s --sout=#file{dst=%s} --vout=dummy -Idummy "
"--ignore-config --quiet --rtsp-frame-buffer-size=500000 --network-caching=4000 &",
ss.str().c_str(), p_camera->getUser().c_str(), p_camera->getPassword().c_str(), it->second.fDump);
HVLog("HVPlayOpen(%p, %d): %s", p_cam, channel, vlcstr);
system(vlcstr);
return 0;
However, I wish to use the library API not the system().
UPDATE 4:
This is the log https://pastebin.com/9zgMQiNL

SOLVED
The issue is addressed using the libvlc_media_add_option() function as show here:
https://forum.videolan.org/viewtopic.php?t=69933

Related

e-MMC returns FR_OK at very first bring-up but mk_dir return FR_NO_FILESYSTEM

I am using stm32H753xx and Cube FatFs library.
After our e-MMC has been soldered to our board, I want to bring-up.
My startup codes is here:
res = f_mount(&fat_fs, "0:", 0);
if (res != FR_OK) {
res = f_mkfs("", FM_ANY, 0, work, sizeof(work));
if (res != FR_OK) {
while(1) {
LOGGER_REPORT(FORMAT_REQUEST_FAILED);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
res = f_mount(&fat_fs, "0:", 0);
if (res != FR_OK) {
while(1) {
LOGGER_REPORT(FORMATTED_BUT_NOT_MOUNTED);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
}
I generally expect an error at mounting phase if bringing-up of a memory device is very first time and this implies why I made my software branch to f_mkfs functions if f_mount fails. But f_mount is returning FR_OK and software is skipping here.
Afterwards, I am doing some api calls to detect latest directory in the root and to create new one by giving a name in way that would be latest+1. ( latest is like ./70/ new one ./71/ anyway)
There are some api calls here f_opendir, f_readdir, f_closedir respectively and all of them returns succesfully but,
whenever I want to create new dir by calling fs_mkdir, it returns FR_NO_FILESYTEM.
If I call f_mkfs after f_mount above, a FAT is creating and software works but I can not call f_mkfs ile that and could not figure it out where I have to put this code to make it run only once at very initial bring-up of e-MMC.

Java 8 issues printing PS to network printer

Got a weird question for you. Recently upleveled my old project from java 7(jdk1.7.0_10) to java 8(1.8.0.91.x86_64). In java 7 it printed the post script file with no issues and now it is printing the postscript file as plain text instead of converting the file. This is on a redhat linux environment. Simply I am trying to print a string containing a post script file of a file itself.
Here is my original code
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintService pService = PrintServiceLookup.lookupDefaultPrintService();
// In a field environment, send to the printer
if (System.getenv("USER_DEFINED_RELTOP") == null || pfr.exists()) {
if (pService.getName().isEmpty()) {
LOGGER.error("No printer selected");
} else {
LOGGER.info("Printing to " + pService.getName());
DocPrintJob pj = pService.createPrintJob();
try {
InputStream is = new ByteArrayInputStream(data.getBytes("UTF8"));
Doc doc = new SimpleDoc(is, flavor, null);
PrintJobWatcher pjw = new PrintJobWatcher(pj);
pj.print(doc, null);
pjw.waitForDone();
is.close();
} catch (PrintException | IOException e) {
LOGGER.error(e);
} // try block
} // no printer selected
// Otherwise, send to a file
} else {
That worked fine in java 7, I updated it to the oracle spec found here for java 8.
https://docs.oracle.com/javase/8/docs/api/javax/print/PrintService.html#createPrintJob--
https://docs.oracle.com/javase/8/docs/technotes/guides/jps/spec/printing.fm6.html
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
attrs.add(MediaSizeName.ISO_A4);
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(psFlavor,
attrs);
File pfr = new File(PFR_INDICATOR);
// In a field environment, send to the printer
if (System.getenv("USER_DEFINED_RELTOP") == null || pfr.exists()) {
//Check we have a printer capable of post script
if (pservices.length > 0) {
LOGGER.info("Printing to " + pservices[0].getName());
DocPrintJob pj = pservices[0].createPrintJob();
try {
InputStream fis = new ByteArrayInputStream(data.getBytes("UTF8"));
//byte[] ba =data.getBytes("UTF8");
Doc doc = new SimpleDoc(fis, psFlavor, null);
LOGGER.info("Doc Flavor " + doc.getDocFlavor());
PrintJobWatcher pjw = new PrintJobWatcher(pj);
LOGGER.info("PrintJob Attributes : " + pj.getAttributes());
pj.print(doc, attrs);
pjw.waitForDone();
fis.close();
} catch (IOException e) {
LOGGER.error(e);
NotificationDialog.show(NotificationDialog.NOTICE_TYPE.ERROR, PRINT_ERROR);
} catch (PrintException e) {
LOGGER.error(e);
}
} else { // no printer selected
This gives me an error java.awt.print.PrinterIOException: java.io.IOException: /usr/bin/lpr: where it looks to not find lpr.
If I keep it the way it was originally (not write to file) it prints the postscript as plain text even if adding the check to check if the printer is post script capable. If I use the new way of printing file I get a lpr not found error. If I print the PS document using the command lpr it converts it as expected and prints fine. If I use lpr -l that doesn't format it prints it document as plain text as well.
Any suggestion/help would be great. I am lost on what to do. I really don't want to convert it to an image and print that.
At a guess I'd say that your printer is an HP or at least PCL + PS printer, not a pure PostScript-only printer.
In that case you generally need to prepend the PostScript with a language selection PJL string. If you don't do this then it usually defaults to PCL and if you don't send any PCL commands (which all begin with 0x1B) then everything is treated as plain ASCII text. That would explain why both your application and lpr -l end up writing text, but lpr itself doesn't (presumably it adds the PJL).
You could try prepending the PostScript file with something like:
%-12345X#PJL JOB
#PJL ENTER LANGUAGE=POSTSCRIPT
NB the first byte there, before the % should be a 0x1b ESC character, but I can't readily paste binary....
Try sending the file with lpr -l if that works then you could try your old printing method.

tweetinvi Chunked Uploads for large uploads

I am trying to file upload with tweetinvi.File upload work for image but same code does not work for video(large video more than 20 mb)
I asked here but now answear
TweetInvi Large Video Upload Failing With Null Reference
so I look for another solution.There is tweetinvi chunked uploads
I coded this but it does not work,it does not give error but it does not work
if (file.ContentType.Contains("video"))//video
{
var video1 = System.IO.File.ReadAllBytes(path);
var chunk = Upload.CreateChunkedUploader(); //Create an instance of the ChunkedUploader class (I believe this is the only way to get this object)
using (FileStream fs = System.IO.File.OpenRead(path))
{
chunk.Init("video/mp4", (int)fs.Length); //Important! When initialized correctly, your "chunk" object will now have a type long "MediaId"
byte[] buffer = new byte[video1.Length]; //Your chunk MUST be 5MB or less or else the Append function will fail silently.
int bytesRead = 0;
while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
byte[] copy = new byte[bytesRead];
Buffer.BlockCopy(buffer, 0, copy, 0, bytesRead);
TimeSpan s = new TimeSpan();
chunk.Append(copy, chunk.NextSegmentIndex.ToString()); //The library says the NextSegment Parameter is optional, however I wasn't able to get it to work if I left it out.
}
}
var video = chunk.Complete(); //This tells the API that we are done uploading.
listMedia.Add(video);
}
I wanted to say that after working on your bug I was able to identify the problem you were encountering.
The issue is that you were not specifying the media_category of the upload.
In addition to this you need to wait for the media to be processed by Twitter.
In Tweetinvi 2.1, the process should be made easier. Please use the following code :
var binary = File.ReadAllBytes(#"video_path");
var media = Upload.UploadVideo(binary);
// The upload is completed but it does not mean it succeeded!
if (!media.HasBeenUploaded)
{
// Something went wrong during the upload.
// Please retry or check the video type/settings.
return;
}
// Just wait for Twitter to have processed the upload (RECOMMENDED)
Upload.WaitForMediaProcessingToGetAllMetadata(media);
// Now the media is ready to be used in a Tweet
var tweet = Tweet.PublishTweet("hello", new PublishTweetOptionalParameters
{
Medias = { media }
});
You can read more about the upload in the updated documentation : https://github.com/linvi/tweetinvi/wiki/Upload#upload-status-video
Finally please note that further improvements of upload are planned for version 2.2 and 2.3.
Have a great day and thank you for reporting this problem,
Cheers
Linvi

Getting error when uploading video using Tweetinvi

I am trying to upload files larger than 5MB but less than 15MB. In this case its 10MB... sample video from sample-videos.com
I am using Tweetinvi, and it works great with files less than 5MB, but fails on chunked uploads. I've tried the easy and the hard way.
Easy way:
var video = File.ReadAllBytes(#"D:\Projects\SampleVideo_1280x720_10mb.mp4");
var media = Upload.UploadVideo(video); // Error here... Invalid Content
var tweet = user.PublishTweet(message, new PublishTweetOptionalParameters
{
Medias = { media }
});
I've pulled in the Tweetinvi solution from Git (currently 0.9.13.0 repository here) and see that the above is getting an error "Invalid Content" when calling Upload.UploadVideo(...). It appears to fail on the command FINALIZE.
Tried the hard way:
using (var fileStream = File.OpenRead(#"D:\Projects\SampleVideo_1280x720_10mb.mp4"))
{
var initSucceeded = uploader.Init("video/mp4", (int)fileStream.Length);
byte[] buffer = new byte[4900000]; //Your chunk MUST be 5MB or less or else the Append function will fail silently.
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
byte[] copy = new byte[bytesRead];
Buffer.BlockCopy(buffer, 0, copy, 0, bytesRead);
var appendResult = uploader.Append(new ChunkUploadAppendParameters(copy, "video/mp4", null) { SegmentIndex = uploader.NextSegmentIndex });
}
var video = uploader.Complete(); // Fails here... Returned error: Segments do not add up to provided total file size
var tweet = user.PublishTweet(message, new PublishTweetOptionalParameters()
{
//Medias = { video }
MediaIds = { video.MediaId.Value }
});
}
The above fails on upload.Complete() with the Twitter API returning "Segments do not add up to provided total file size"
What am I missing?
TIA
I think the problem you have is with the video file. The video seems to be using a 6 channels audio and Twitter Public Upload API only allow developers to upload video with mono or stereo audio.
Source : https://dev.twitter.com/rest/media/uploading-media
I am no expert in video properties so feel free to prove me wrong if I am.
The above fails on upload.Complete() with the Twitter API returning "Segments do not add up to provided total file size"
This error means that you are not actually sending all the byte that you promised Twitter. During the INIT, you tell Twitter the size of your media, if what it receives in the combined APPEND is not equals to the value you specified in the INIT, the error you described is thrown.
PS : I have tried using a 2 channels 14.8 MB mp4 and it works properly. var media = Upload.UploadVideo(binary);

Arabic input fields in unity

Is there is a way to change the language of input fields in unity to Arabic?. I tried ArabicSupport and it displayed Arabic correctly but using it with input fields didn't work because
GameObject.Find("input_field")
.GetComponent<InputField>().text = Fix3dTextCS.fix(
GameObject.Find("input_field").GetComponent<InputField>().text
);
caused an error so, if I printed the input text elsewhere, it will appear correctly but how can I do it with the same input field?
input field is a little bit tricky to let it work with Arabic Support
please try this opensource asset it has an prefab for Arabic Input Field and some other UIs.
OpenSource for ArabicSupport Solution Link
OpenSource for unity asset UI Arabic Support: Link
Have you tried adding arabic font in that input.
If so, post the error message it may help to find the bug
Using Font won't help because it will only change the theme of your current Input usage but not how you use to input in the Device.
You will need to use Input.Location <- Input is static so you can access it anywhere. The only problem is, I am not sure what is the exact variable for arabic is. My best guess is Input.Location = "Arabic" or "arabic".
If you want to automatically detect their location, the GPS which will unity3d turn on by calling Input.Location.Start, and turn off by Input.Location.Stop()
Here is a sample code for you.
using UnityEngine;
using System.Collections;
public class TestLocationService : MonoBehaviour
{
IEnumerator Start()
{
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser) yield break;
// Start service before querying location
Input.location.Start();
// Wait until service initializes
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return new WaitForSeconds(1);
maxWait--;
}
// Service didn't initialize in 20 seconds
if (maxWait < 1)
{
print("Timed out");
yield break;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed)
{
print("Unable to determine device location");
yield break;
}
else
{
// Access granted and location value could be retrieved
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
}
// Stop service if there is no need to query location updates continuously
Input.location.Stop();
}
}

Resources