C++ LibVLC broadcast audio - c++

Before creating the post I was looking but I can't find a solution to my problem.
I am trying to broadcast my microphone's default output live.
If you paste in the cmd replacing the ip, it will start transmitting sound from your microphone.
"C:\Program Files\VideoLAN\VLC\vlc.exe" --qt-start-minimized dshow:// :dshow-vdev=none :dshow-adev= :sout=#transcode{vcodec=none,acodec=mp3,ab=128}:standard{access=http,mux=mp3,dst=192.168.1.253:8080}
So I decided to move that command from cmd to c ++
std::cout<<"BEGIN BROADCAST"<<std::endl;
libvlc_instance_t *vlc;
const char *url = "dshow://";
const char *sout = "#transcode{vcodec=none,acodec=mp3,ab=128}:http{mux=mp3,dst=192.168.1.253:8080}";
const char *media_name = "Radio";
vlc = libvlc_new(0, NULL);
std::cout<< libvlc_vlm_add_broadcast(vlc, media_name, url, sout, 0, NULL, true, false);
std::cout<<"END BROADCAST"<<std::endl;
According to the official documentation, it returns an int if the transmission was successful -> int libvlc_vlm_add_broadcast
https://videolan.videolan.me/vlc-3.0/group__libvlc__vlm.html#gaa8d58569f07229edabe9fdaab41b1c3d
It returns 0 to me.
But when I open another VLC to access: http://192.168.1.253:8080 it won't connect ...
Is there someone who can help me? I really appreciate it, greetings.
One of the posts that comes closest is this:
Use libvlc to stream mp3 to network

Related

Using ClipboardSetData function to set the contents of the clipboard of the remote machine

I've been tasked with sending text clipboard data to a WfreeRDP connected remote machine's clipboard from a web application and am having trouble knowing where to look.
WFreeRDP has a TestClipboardFormats.c which kind of looks like what I need and features a SetClipboardData and GetClipboardData which I've managed to get working (according to the Debug console output at least)
BOOL bSuccess;
UINT32 SrcSize;
UINT32 DstSize;
const char* pSrcData = commandArgs.c_str();
char* pDstData;
textHtmlStringFormatId = ClipboardRegisterFormat(clipboard, "CF_TEXT");
utf8StringFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
SrcSize = (UINT32)(strlen(pSrcData) + 1);
bSuccess = ClipboardSetData(clipboard, textHtmlStringFormatId, pSrcData, SrcSize);
fprintf(stderr, "ClipboardSetData: %d\n", bSuccess);
DstSize = 0;
pDstData = (char*)ClipboardGetData(clipboard, textHtmlStringFormatId, &DstSize);
fprintf(stderr, "ClipboardGetData: %s\n", pDstData);
free(pDstData);
I was kind of hoping the remote machine's clipboard would be populated with the data I'd sent as it can be retrieved with GetClipboardData successfully, but right clicking on the remote machine yields no results.
Am I using the right method? Or maybe using it incorrectly?

Is there a way to get call back in linux if file/directory size increases above configured level

am looking for some thing like this programatically in c/c++ using linux system call,
char * filename="/tmp/testDirectory";
fd = open(filename, O_CREAT | O_RDWR);
setmaxfilesize(fd,"4mb"); //<== looking for some API to do this.
registerforCallback(mycallback); //<== looking for some API to do this
void mycallback(void * arg)
{
/* Delete old files inside directory to have space for new files*/
}
Yes, but not directly on the file size as I know.
Take a look at:
https://lwn.net/Articles/604686/
This will give you a good startpoint how to interact with file notifications. After a file change your handler can be notified. In the handler you can check for size and do your job.
Excerpt:
There is dnotify which basically works with the syscall fcntl(fd, F_NOTIFY, mask);
dnotify seams to be outdated ( my linux distro has no support for dnotify anymore )
inotify comes with an own API. See man inotify.
Watching for file change can be done with int inotify_add_watch(int fd, const char *pathname, uint32_t mask); where mask can be IN_MODIFY to see all modifications on the file. If your handler is called from here, request the file size and do your actions.

How to use ffmpeg faststart flag programmatically?

I try to convert videos for playback on Android using H264, AAC codecs and mp4 container. Video plays normaly with non-system players. But system player shows error "Can't play this video".
I found out that the problem is in moov atom, which is writed in the end of the file.
When I use "-movflags +faststart" ffmeg flag to convert video, it plays normal, but when I try to do that programmatically, it gives no result. I use following code:
av_dict_set( &dict, "movflags", "faststart", 0 );
ret = avformat_write_header( ofmt_ctx, &dict );
This code works fine:
av_dict_set( &dict, "movflags", "faststart", 0 );
ret = avformat_write_header( ofmt_ctx, &dict );
But problem is not solved. I still can't play converted videos on Android devices.
I assume that this answer is very late, but still, for anyone who might still be facing the same issue: this might be caused by the AV_CODEC_FLAG_GLOBAL_HEADER not being set in the audio/video AVCodecContext. A lot of guides show that it needs to be set in the AVFormatContext, but it needs to be set in the AVCodecContext before opening it using avcodec_open2.
if (format_context->oformat->flags & AVFMT_GLOBALHEADER) {
video_codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
avcodec_open2(video_codec_context, video_codec, nullptr);
Maybe the video is not compatible with your android phone? Try to convert with h264 baseline profile.
TL;DR
Set url field of AVFormatContext before avformat_write_header.
Why
I hit same issue today, and I found there is a log when calling av_write_trailer:
Unable to re-open output file for the second pass (faststart)
In the movenc.c implementation, we can see it needs s->url to re-open the file:
avio_flush(s->pb);
ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for "
"the second pass (faststart)\n", s->url);
goto end;
}

c++ ffmpeg api get video stream from https link

I'm trying to read https video link using the function av_format_open_input() but the function return a negative value.
Here is my code:
av_register_all();
avcodec_register_all();
avformat_network_init();
const char * url = "https://r1---sn ...";
AVFormatContext * pFormatCtx = avformat_alloc_context();
int ret = avformat_open_input(&pFormatCtx, url, NULL, NULL);
This code worked with a local file as url but as soon as I give a https url it doesnt work anymore.
thanks
[edit]
I found only this: ffserver.c
But it uses a .ffm file as input. Any exemple or help on how to implement HttpContext (if HttpContext is needed here) would be great.
[update]
I ended using libvlc which seems to be much easier but the way to do it using ffmpeg could still be interesting. See my other post if interested: Get frame from video with libvlc smem and convert it to opencv Mat. (c++)

FFmpeg: How to control console output while reading from RTSP?

So I created simple Consol app: FFmpeg RTSP Video stream reader (using only general FFmpeg C API) But while ffmpeg reads from RTSP it shows lots of info. I did not asked for if... At least not all of it... So how can I filter what ffmpeg is outputing? I mean in all he talls user-developer there is only one important line something like: missing picture in acsess unit so how to put some filter mechanism for ffmpeg not to output all it wants and for me developer to catch the moment when message I want appeares? (In my project I write in C++ under visual studio using Boost libs)
Use av_log_set_callback, to set your function as callback:
static void avlog_cb(void *, int level, const char * szFmt, va_list varg) {
//do nothing...
}
av_log_set_callback(avlog_cb);
or, you may also use
av_log_set_level(AV_LOG_ERROR);
to print error messages only.