How to enable the FFMPEG logging? - ffmpeg

I want to debug the ffmpeg. I add the following code to print logs:
av_log(s, AV_LOG_PANIC, fmt, ...)
or
printf("msg....")
But it can't work. There isn't any debug information.
Then I enable the debug build option:
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-debug"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-debug=0"
It can't work.
I'm sure that the place where I added the trace will be executed.
I just want to print some simple informations, how to do it ?

I found a solution:
void my_log_callback(void *ptr, int level, const char *fmt, va_list vargs)
{
vprintf(fmt, vargs);
}
Set the log level and register the log callback:
av_log_set_level(AV_LOG_ERROR);
av_log_set_callback(my_log_callback);

this works fine:
int main(int argc, char *argv[])
{
av_log_set_level(AV_LOG_DEBUG);
...
}

Related

global try and catch block in qt

I am using Qt 4.8. Is there any way to have a global try and catch block for whole project. Example, if my application has two .cpp files. Is it possible way to catch exception across both .cpp files?
First of all, be warned that Qt doesn't play nice with exceptions. It was designed back in those days when exceptions were rather obscure feature of C++ so the use of exceptions was not generally considered a good practice for a whole bunch of implementation-related reasons.
Also be warned that as of Qt 5.7 the exception safety is not feature complete as the official doc currently tells:
Preliminary warning: Exception safety is not feature complete! Common cases should work, but classes might still leak or even crash.
If you use signal-slot connections within your classes, it's best to handle exceptions inside the slots which may throw them. As of Qt 5.7 not doing so is considered undefined behaviour.
If you just want to do some cleanup and/or error logging on any occasionally uncaught exception, you can either wrap the entire main() contents into try/catch block as the previous answer suggests or alternatively you can wrap the Qt's main event loop into such a block:
QApplication app(argc, argv);
...
try {
app.exec();
}
catch (const std::exception &) {
// clean up here, e.g. save the session
// and close all config files.
return 0; // exit the application
}
You can put in brackets the entire contents of your main() function as follows::
int main(int argc, char *argv[])
{
int ret = 0;
try
{
QApplication a(argc, argv);
QWidget w;
w.show();
ret = a.exec();
}
catch(...)
{
/* ... */
}
return ret;
}
See also: std::set_terminate()

Efficiently write log file on Windows

I want to write log files. My application could be run on Linux and Windows. I've pretty much figured out how to do it for the former, thanks to this example:
void SyslogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Q_UNUSED(context)
QByteArray localMsg = msg.toLocal8Bit();
switch (type)
{
case QtDebugMsg:
#ifdef __linux__
syslog(LOG_DEBUG, "Message (debug): %s", localMsg.constData());
#elif _WIN32
// WRITE INTO FILE
#else
#endif
break;
// etc.
}
}
int main()
{
// Install our message handler.
qInstallMessageHandler(SyslogMessageHandler);
// Send some messages, which should go to syslog.
qDebug("Debug log message from Qt test program");
}
source (2nd example)
However, I am wondering what would be the fastest way for Windows? Is using QFile or QTextStream an efficient way for writing this kind of information?
I was thinking about storing everything in a simple QString and then put everything in a file when the app closes or crashes (in the latter case, is that possible?).

boost asio and libcurl mutiple handler

im learning libcurl and boost:asio from this nice post http://www.lijoantony.com/?p=76
though i do have one question about the source code at:
sample code
the main function looks like:
int main(int argc, char **argv)
{
GlobalInfo g;
CURLMcode rc;
(void)argc;
(void)argv;
memset(&g, 0, sizeof(GlobalInfo));
g.multi = curl_multi_init();
curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
new_conn((char *)"http://us.download.nvidia.com/XFree86/Linux-x86_64/331.79/NVIDIA-Linux-x86_64-331.79.run", &g); /* add a URL */
/* enter io_service run loop */
io_service.run();
curl_multi_cleanup(g.multi);
fprintf(MSG_OUT, "\ndone.\n");
return 0;
}
i see there is no place calling the curl function curl_multi_perform()
how does the tasks get started at the very begining?
I see there is no place calling the curl function curl_multi_perform()
This is because this sample code uses an alternative API called curl_multi_socket_action:
curl_multi_socket_action is then used instead of curl_multi_perform.
(see the MULTI_SOCKET section of the official documentation for more details)
how does the tasks get started at the very begining?
The magic occurs thanks to the CURLMOPT_TIMERFUNCTION option, curl_multi_add_handle function and corresponding timer logic.
If you refer to the static void new_conn(char *url, GlobalInfo *g ) function you can see that:
static void new_conn(char *url, GlobalInfo *g )
{
/* ... */
rc = curl_multi_add_handle(g->multi, conn->easy);
mcode_or_die("new_conn: curl_multi_add_handle", rc);
/* note that the add_handle() will set a time-out to trigger very soon so
that the necessary socket_action() call will be called by this app */
}
So in practice everything starts by calling new_conn(...) which in turn will trigger multi_timer_cb which then calls timer_cb.
And timer_cb performs the curl_multi_socket_action.

Event handler when user manually shutsdown system

I need a event handler when ever shutdown message is send to system.
Can anyone help?
When ever we try to shutdown a system, and if any dialog box is open shutdown process terminates. I don't want this to happen in my application. i.e if any dialog box is open from my application and I try to shutdown my system then it should not block shutdown process. Is this implementation possible?
Thanks,
Rahul
Yes, look at NSWorkspaceWillPowerOffNotification
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html
try overriding QApplication::commitData it should be called whenever user shuts down the system and your application is still running.
This function deals with session
management. It is invoked when the
QSessionManager wants the application
to commit all its data.
Usually this means saving all open
files, after getting permission from
the user. Furthermore you may want to
provide a means by which the user can
cancel the shutdown.
below is an example (never tried it with macs; though works fine on my ubuntu):
main.cpp:
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QSessionManager>
class MyApplication : public QApplication
{
public:
MyApplication(int &argc, char **argv);
virtual void commitData(QSessionManager& sm);
};
MyApplication::MyApplication(int &argc, char **argv):
QApplication(argc, argv)
{
//???
}
void MyApplication::commitData(QSessionManager& sm)
{
// do smth here....
QApplication::commitData(sm);
}
int main(int argc, char *argv[])
{
MyApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
hope this helps, regards

"seekg identifier not found"

I have a program called main:
#include<iostream>
#include<fstream>
using namespace std;
#include"other.h"
int main()
{
//do stuff
}
and then other.h:
char* load_data(int begin_point,int num_characters)
{
seekg(begin_point);
char* return_val=new char[num_characters+1];
mapdata.getline(return_val,num_characters);
return return_val;
}
and I get the error:
'seekg': identifier not found
why do I get this error and how do I fix it?
seekg is a method from the fstream (declared in istream) class.
You haven't instantiated any.
Take this as an example
ifstream is;
is.open ("test.txt", ios::binary );
// get length of file:
is.seekg (0, ios::end);
source: http://www.cplusplus.com/reference/iostream/istream/seekg/
So, you should
char* load_data(int begin_point,int num_characters)
{
ifstream is;
is("yourfile.txt") //file is now open for reading.
seekg(begin_point);
char* return_val=new char[num_characters+1];
mapdata.getline(return_val,num_characters);
return return_val;
}
Take into account what ParoXon commented in your question.
You should create a file other.cpp containing function's load_data implementation.
File other.h should contain function's load_data declaration. In that file (other.h) you should include all files neccesary for functions declared there to work. And dont forget to protect yourself against multiple includes !
File other.h
#ifndef __OTHER_H__
#define __OTHER_H__
#include <iostream>
#include <fstream>
char* load_data(int,int);//no implementation
#endif
File other.cpp
#include "other.h" //assumes other.h and other.cpp in same directory
char* load_data(int begin,int amount){
//load_data implementation
}

Resources