cv::VideoCapture read live video stream but can't discriminate fake urls - opencv

I tried to read live video stream with OpenCV as following,
cv::VideoCapture capture(video_url);
It can read from live video stream and works well. However, when a fake video_url was sent to it, such as an url of a txt file, for example,
video_url = "http://127.0.0.10:8090/result.txt"
it can also decode data from this fake url. But I want it to return error information when the video_url is fake.
How can I make it to be able to discriminate whether an url is truly of a live video stream, or a txt web file?

python
You can use URLValidator() for discriminating fake urls.
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
validate = URLValidator()
is_valid = False
url = "https://www.youtube.com/watch?v=vNSxargsAWk"
try:
validate(url)
is_valid = True
except ValidationError as exception:
print("url is not valid")
c++
Check the URL using regular expression.
#include <regex>
using namespace std;
int main()
{
regex url_validator("/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)/");
if(regex_match(input, url_validator))
cout<<"Input is an integer"<<endl;
else
cout<<"Invalid input : Not an integer"<<endl;
}

Related

vlc onlistnener needed to know the end of the video

Im using VLC to play video but I need to know when the video ends. so basically I need a onlistener. Can someone give me a simple code for onlistener for VLC. Here is the code I'm using to play VLC :
int vlcRequestCode = 42; Uri uri = Uri.parse("/storage/emulated/0/Download/hero.mp4");
vlcIntent.setComponent(new ComponentName("org.videolan.vlc", "org.videolan.vlc.gui.video.VideoPlayerActivity"));
vlcIntent.setDataAndTypeAndNormalize(uri, "video/*");
vlcIntent.putExtra("title", " Concert Collection");
vlcIntent.putExtra("from_start", true);
vlcIntent.putExtra("position", 90000l);
vlcIntent.putExtra("position", 90000l);
startActivityForResult(vlcIntent, vlcRequestCode);

Export SSRS report directly without rendering it on ReportViewer

I have a set of RDL reports hosted on the report server instance. Some of the report renders more than 100,000 records on the ReportViewer. So that it takes quite long time to render it on the Viewer. So, we decided to go with Export the content directly from the server based on the user input parameters for the report as well as export file format.
Main thing here, I do not want the user to wait until the export file available for download. Rather, User can submit the action and can proceed to do other works. In the background, the program has to export the file to some physical location. When the download will be available, the user will be informed with some notification about the exported file.
I found the way in this Link. I need to know what are the ways to achieve the above mentioned functionality as well as how to pass the input parameters for the report. Pl suggest me.
Note: I was using XML as datasource for the rdl reports.
EDIT
I found something useful and did the coding like the below,
string path = ServerURL +"?" + _reportFolder + "ReportName&rs:Command=Render&rs:Format=PDF";
WebRequest req = WebRequest.Create(path);
string reportParametersQT = String.Empty;
req.Credentials = CredentialCache.DefaultNetworkCredentials;
WebResponse response = req.GetResponse();
Stream stream = response.GetResponseStream();
//screen.Response.Clear();
string enCodeFileName = HttpUtility.UrlEncode("fileName.pdf", System.Text.Encoding.UTF8);
// The word attachment in Addheader is used to directly show the save dialog box in browser
Response.AddHeader("content-disposition", "attachment; filename=" + enCodeFileName);
Response.BufferOutput = false; // to prevent buffering
Response.ContentType = response.ContentType;
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
Response.OutputStream.Write(buffer, 0, bytesRead);
}
Response.End();
I am able to download the exported file. But need to save the file in physical location instead of downloading. I dont know how to do that.
Both of these are very easy to do. You essentially just pass the parameters in the URL that you're calling, for example for a parameter called "LearnerList" you add &LearnerList=12345 to the URL. For exporting, add an additional paramter for Format=PDF (or whatever you want the file as) to get the report to export as a PDF instead of generating in Report Viewer.
Here's an example URL:
https://reporting.MySite.net/ReportServer/Pages/ReportViewer.aspx?/Users+Folders/User/My+Reports/Learner+Details&rs:Format=PDF&LearnerList=202307
Read these two pages, and you should be golden:
https://msdn.microsoft.com/en-us/library/ms155391.aspx
https://msdn.microsoft.com/en-us/library/ms154040.aspx

How to parse VP8 bitstream with libav

I've just started to learn about VP8, so give me some slack if this is a dumb question.
H.264 Example
In the past I've worked mostly with H.264. Whenever I needed to parse H.264 bit streams, I would leverage libav to help me and use something like this
av_register_all();
_ioContext = avio_alloc_context(
encodedData,
H264_READER_BUF_SIZE,
0,
0,
&readFunction,
NULL,
NULL);
if (_ioContext == NULL)
throw std::exception("Unable to create AV IO Context");
AVInputFormat *h264Format = av_find_input_format("h264");
if (h264Format == NULL) {
throw std::exception("Unable to find H264 Format");
}
_context = avformat_alloc_context();
_context->pb = _ioContext;
ret = avformat_open_input(&_context,
"",
h264Format,
NULL);
if (ret != 0) {
throw std::exception(
"Failed to open input file :" +
std::string(_avErrToString(ret)));
}
VP8
The above method has worked great for parsing the H.264 bit streams and providing me with H.264 frames to feed to my own decoding infrastructure.
I'm trying to duplicate the same effort with VP8. I tried using this code as a basis and instead of looking for the "h264" format, I've tried "vp8" and "webm". "vp8" doesn't seem valid, but "webm" is able to load a format. However when I get to avformat_open_input I get this error:
[matroska,webm # 0x101812400] Unknown entry 0xF0
[matroska,webm # 0x101812400] EBML header using unsupported features
(EBML version 0, doctype (null), doc version 0)
Failed to open input file :Not yet implemented in FFmpeg, patches welcome
Am I out of look? Or am I just approaching this incorrectly?
I am using this C# wrapper for FFMPEG\LibAV (particularly this example file), it has the same syntax as the C++ one, and it works fine.
The error message says that it hasn't been implemented yet, so I suggest updating your libav library.
Piece of code that is working (it include the AVInputFormat modification by me, which is not present in the linked example file):
FFmpegInvoke.av_register_all();
FFmpegInvoke.avcodec_register_all();
FFmpegInvoke.avformat_network_init();
string url = #"C:\file.webm";
AVFormatContext* pFormatContext = FFmpegInvoke.avformat_alloc_context();
AVInputFormat* pFormatExt = FFmpegInvoke.av_find_input_format("webm");
if (FFmpegInvoke.avformat_open_input(&pFormatContext, url, pFormatExt, null) != 0)
throw new Exception("Could not open file"); //no exception is thrown
//more code to decode frames, and frames are decoded successfully
If that does not work, then maybe you are opening the file incorrectly (the second argument of avformat_open_input is empty).
Maybe try specifying a file path?

Dart:io stdin raw character codes

I've created a Dart console app and need to process keycodes like Arrow keys and function keys from stdin? The samples I've seen are typically String based :
Stream readLine() => stdin.transform(UTF8.decoder).transform(new LineSplitter());
readLine().listen(processLine);
I modified the above sample hoping to get the raw ints like this:
Stream readInts() => stdin;
readInts().listen(processInts);
void processInts(List<int> kbinput) {
for (int i=0;i<kbinput.length;i++){
print ("kbinput:${kbinput[i]}");
}
}
It seems stdin provides only printable characters and not all ascii keycodes. If it is not possible from stdin, can I create & load a stream within my native extension with the keycodes? How can my console app get to the ascii keycodes of any keypress? Thanks for your help!
One way would be
import 'dart:io' as io;
import 'dart:convert' show UTF8;
void main() {
io.stdin.echoMode = false;
var input;
while(input != 32) { // leave program with [Space][Enter]
input = io.stdin.readByteSync();
if(input != 10) print(input); // ignore [Enter]
}
io.stdin.echoMode = true;
}
but it only returns a value after Enter is pressed.
For one key press it returns from one up to three bytes.
It seems it's not easy to get a keystroke from console without pressing Enter
see Capture characters from standard input without waiting for enter to be pressed for more details.
You could create a native extension that implements the suggested solution in the linked question.

pdf.js to display output of file created with tcpdf

I really hope you will be able to help me out on this one.
I am new to pdf.js so for the moment, I am playing around with the pre-built version to see if I can integrate this into my web app.
My problem:
I am using tcpdf to generate a pdf file which I would like to visualize using pdf.js without having to save it to a file on the server.
I have a php file (generate_document.php) that I use to generate the pdf. The file ends with the following:
$pdf->Output('test.pdf', 'I');
according to the tcpdf documentation, the second parameter can be used to generate the following formats:
I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
D: send to the browser and force a file download with the name given by name.
F: save to a local server file with the name given by name.
S: return the document as a string (name is ignored).
FI: equivalent to F + I option
FD: equivalent to F + D option
E: return the document as base64 mime multi-part email attachment (RFC 2045)
Then, I would like to view the pdf using pdf.js without creating a file on the server (= not using 'F' as a second parameter and passing the file name to pdf.js).
So, I thought I could simply create an iframe and call the pdf.js viewer pointing to the php file:
<iframe width="100%" height="100%" src="/pdf.js_folder/web/viewer.html?file=get_document.php"></iframe>
However, this is not working at all....do you have any idea what I am overlooking? Or is this option not available in pdf.js?
I have done some research and I have seen some posts here on converting a base64 stream to a typed array but I do not see how this would be a solution to this problem.
Many thanks for your help!!!
EDIT
#async, thanks for your anwer.
I got it figured out in the meantime, so I thought I'd share my solution with you guys.
1) In my get_document.php, I changed the output statement to convert it directly to base64 using
$pdf_output = base64_encode($pdf->Output('test_file.pdf', 'S'));
2) In viewer.js, I use an XHR to call the get_document.php and put the return in a variable (pdf_from_XHR)
3) Next, I convert what came in from the XHR request using the solution that was already mentioned in a few other posts (e.g. Pdf.js and viewer.js. Pass a stream or blob to the viewer)
pdf_converted = convertDataURIToBinary(pdf_from_XHR)
function convertDataURIToBinary(dataURI) {
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for (i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i);
}
return array;
}
et voilĂ  ;-)
Now i can inject what is coming from that function into the getDocument statement:
PDFJS.getDocument(pdf_converted).then(function (pdf) {
pdfDocument = pdf;
var url = URL.createObjectURL(blob);
PDFView.load(pdfDocument, 1.5)
})

Resources