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?
Related
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;
}
I want to use the can_msgs/Frame.msg for decoding can messages using db.decode_message(Frame.id, Frame.data) but it is giving error
I want to try and write a new Frame.msg format but will it help?
def callback(Frame):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", Frame.data)
Temp = db.decode_message(Frame.id, Frame.data)
temp.data = Temp
pub.publish(temp)
I want to print the message in the dbc format that the cantools package helps decoding.
Error:
File "safa.py", line 42, in callback
temp = db.decode_message(Frame.id, Frame.data)
File "build/bdist.linux-x86_64/egg/cantools/database/can/database.py", line 379, in decode_message
message = self._name_to_message[frame_id_or_name]
KeyError: 10
Looking at the cantools documentation for db.decode_message, the KeyError is a bad description/error msg for the following.
db is a database (class cantools.database.can.Database), which stores all the weird encodings we may choose to use with cantools. To decode a message, it must already have an encoding stored within it, using one of the db.add_* methods with the class.
Edit:
The definition of the can_msgs/Frame is
std_msgs/Header header
uint32 id
bool is_rtr
bool is_extended
bool is_error
uint8 dlc
uint8[8] data
The data term requires an array/list of 8 uint8 values, not a string. Any CANbus data encoding must finish in this form.
Additionally, ROS provides an interface to the CANbus already: socketcan_bridge can be called in a launch file with your node at the same time.
Before you can decode messages you should setup the database e.g by loading a dbc file:
try:
dbc_file_object = open(dbc_file, 'r')
except IOError as e:
rospy.loginfo('Unable to open file {}'.format(e))
sys.exit(-1)
self.db = cantools.db.load(dbc_file_object)
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
I'm trying to use PortAudio and libsndfile to play .wav files in exclusive mode on my Windows 7 machine, but I'm getting
error number -9984 "Incompatible host API specific stream info" .
I've filled out the PaWasapiStreamInfo struct as follows:
struct PaWasapiStreamInfo wasapiInfo ;
wasapiInfo.size = sizeof(PaWasapiStreamInfo);
wasapiInfo.hostApiType = paWASAPI;
wasapiInfo.version = 1;
wasapiInfo.flags = paWinWasapiExclusive;
wasapiInfo.channelMask = NULL;
wasapiInfo.hostProcessorOutput = NULL;
wasapiInfo.hostProcessorInput = NULL;
wasapiInfo.threadPriority = eThreadPriorityProAudio;
Then assigning the hostApiSpecificStreamInfo parameter and opening the stream via Pa_OpenStream as follows:
/* stereo or mono */
out_param.channelCount = sfinfo.channels;
out_param.sampleFormat = paInt16;
out_param.suggestedLatency = _GetDeviceInfo(out_param.device)->defaultLowOutputLatency;
out_param.hostApiSpecificStreamInfo = (&wasapiInfo);
err = Pa_OpenStream(&stream, NULL, &out_param, sfinfo.samplerate,
paFramesPerBufferUnspecified, paClipOff,
output_cb, file);
Have I missed a step?
Thanks,
Tyler
The technique you used to run the stream in exclusive mode worked for me. It may be the case that you're not opening a stream on a WASAPI device. Depending on your system configuration you may have DirectSound and WMME devices as well. The following code will verify whether the device referenced by index deviceIndexis a WASAPI device or not:
bool isWasapi = Pa_GetHostApiInfo(Pa_GetDeviceInfo(deviceIndex)->hostApi)->type == paWASAPI;
You also need to specify the same index in the out_param struct:
out_param.device = deviceIndex;
You did couple things I did not. In your example you tried to set the thread priority, but PortAudio documentation states that the following line:
wasapiInfo.threadPriority = eThreadPriorityProAudio;
will have no effect because you didn't not set the paWinWasapiThreadPriority bit in wasapiInfo.flags. By the same rule it is unnecessary to explicitly set the other varaibles to null. To fix this set wasapiInfo.flags as follows:
wasapiInfo.flags = (paWinWasapiExclusive|paWinWasapiThreadPriority)
This should enable exclusive mode and cause the threadPriority variable to take effect.
I have a requirement to read email body and attachments from blackberry application. I am able to read plain text messages, email messages but unable to read the attachments. I am getting null pointer exception when trying to read the attachment stream. I am able to get the content type, size and attachment name but not the content. Below is the sample code I have been playing with. Please help me as I am unable to proceed further
public void uploadAttachment(SupportedAttachmentPart attachment)
{
String strMimeType = attachment.getContentType();
String strAttachmentFileName=attachment.getFilename();
String strAttachmentSize=attachment.getSize()
InputStream emailAttachmentStream = attachment.getInputStream();
int ch = emailAttachmentStream.read();
while(ch!=-1)
{
reqVector.addElement((byte) (ch));
ch = emailAttachmentStream.read();
}
}
In BlackBerry, for performance resons, there was a file size limitation regarding attachments, so only a portion of the message was downloaded. The attachments were not actually delivered to the device unless the user opened them.
Now, in JDE 5.0, they introduced a new class, AttachmentDownloadManager, that allows the programmer to force a retrieval from code.
It could be something like this (not tested):
Message m = ... //The mail message instance.
AttachmentDownloadManager atm = new AttachmentDownloadManager();
BodyPart[] bparr = atm.getAttachmentBodyParts(m);
atm.download(bparr, <some folder path>, null);