FFMPEG code (Not command) to stream audio to a Multicast address - ffmpeg

I need to stream a audio to a Multicast address. And I konw the command could be:
ffmpeg -i input -f mpegts
udp://hostname:port?pkt_size=188&buffer_size=65535
But i don't konw how to do this via code? Can you help me, thanks.

This is not different from any other video conversion with ffmpeg - open input stream, open output stream, and loop around av_read_packet, av_decode_video, av_encode_video, av_write_packet_interleaved.
The easiest way would be to reap apart the ffmpeg utility source code, which is in ffmpeg.c in the ffmpeg source directory.

Related

ffmpeg C program to stream ts file through network without changing AV codecs

I am trying to get a sample C source file as example which uses ffmpeg library APIs to stream a ts file as is without changing codec using rtp multicast
./ffmpeg -re -i test_av.ts -acodec copy -vcodec copy -f rtp_mpegts rtp://237.255.5.3:5008
edit:
I am looking for sample C program(s) which could do something close the command I mentioned. I can modify & make required changes if it is somewhat close to what I am trying to achieve. I tried modifying the muxing.c in the doc, however didn't get how to copy codecs & stream through network using rtp multicast.

FFMPEG: rtsp stream to a udp stream

I am looking for advice on using ffmpeg to convert RTSP stream to udp stream. What would be the simplest general command to do so? This is what I have right now:
ffmpeg -i rtsp://192.168.1.247/play1.sdp -f mpegts -vcodec mpeg4 -acodec mp2 udp://127.0.0.1:1234
The error I'm getting:
UDP timeout, retrying TCP
method PAUSE failed: 405 PAUSE
rtsp://192....: operation not permitted
Finishing stream 0:0 without any data written to it.
I'm running ubuntu 14.04. Thank you!
Looks like the ffmpeg command you are using good enough. I suspect your RTSP input stream is not valid. Have you verified it? You can do so using below command or in vlc also:
ffplay -i rtsp://192.168.1.247:port/filename
One change in the command could be instead of play1.sdp, you can directly give the stream filename i.e, a playable stream than sdp file. Hope it helps.

Redirect FFMPEG's output to multiple named pipes on Windows

I am trying to stream video and audio data into two separate named pipes on Windows.
ffmpeg.exe -f dshow -i video="My camera name":audio="My microphone name" -map 0:1 -ac 1 -f f32le \\.\pipe\audioStream -map 0:0 -f mjpeg \\.\pipe\videoStream
The problem is that FFMPEG does not seem to understand that the outputs \\.\pipe\audioStream and \\.\pipe\videoStream are pipes and treats them like files.
If the pipes are already created when the FFMPEG starts, it wants to overwrite them and fails.
Otherwise, it complains that the path does not exist and fails.
As far as I understand, specifying the pipe: protocol should do the trick, but I can't figure out how to use it properly, even with a single pipe. I have tried:
pipe:pipeName
pipe:pipe\pipeName
pipe:\\.\pipe\pipeName
pipe://pipeName
pipe://pipe\pipeName
pipe://\\.\pipe\pipeName
I always end up with the same result: the output is written to the console and not to the pipe. If the pipe already exists when the FFMPEG starts, nothing connects to the pipe.
Is it possible to use FFMPEG with named pipes on Windows? If yes, what is the proper way to do this?
From my experience piping to multiple outputs with FFmpeg has never worked. Establishing a pipe involves data transfers of blocking type. The feeder FFmpeg expects the feeded program to "eat" a chuck of data before sending other chucks. In case of two feeds FFmpeg doesn't know which feeded programs has the priority and when in doubt FFmpeg does nothing, hence FFmpeg hangs forever waiting that something on the other side of the two pipes happens.

FFMPEG : Redirecting MP4 muxed data to socket

I am using FFMPEG library to mux H.264 and AAC frames to MP4 file. I can do that both using command line and C program.
Now, instead of writing the muxed MP4 data in to file I want to write these muxed data directly on to socket or pipe. Command line options for that will be appreciated. My actual goal is to write a C program though.
I tried using protocols tcp and udp but they are not working with Mp4 format. They are working with the matroska format.
Following is working.
ffmpeg -i Cartoon.mjpeg -f matroska -r 25 -vcodec copy tcp://10.99.19.224:8888
Following is not and gives error as below.
ffmpeg -i Cartoon.mjpeg -f mp4 -r 25 -vcodec copy tcp://10.99.19.224:8888
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted
Any help or advice? Thank you in advance.
Just got one way to output the muxed MP4 output directly on the socket using fragments. I know there are limitations of using fragments but this can be useful.
https://www.ffmpeg.org/ffmpeg-formats.html#Example-1
So following command line is working for me now. I am able to play the MP4 file received from the 8888 port. ffprobe also confirms that its really an MP4 file.
ffmpeg -i Stingray.264 -f mp4 -movflags isml+frag_keyframe -vcodec copy tcp://10.99.19.224:8888
Now I will have to write the C program to do this pragmatically.
If you look at all the ffmpeg output, there is a line:
[mp4 # 0033d660] muxer does not support non seekable output
The mp4 container needs to go back at the beggining of the file to write additional information. A thing that your network socket can not do. So it is not possible to use mp4 container here.

Convert streaming MPEG-4 raw data to H.264

I've got a Sony network camera (SNC-RZ25N) that I am trying desperately to get data from in some meaningful format. The documentation says it sends MPEG-4 raw data, but is not more specific than than. I can capture a segment of the stream using curl ( http://techhead.biz/media/tsv.m4v ) and it will play using VLC and ffplay (though it plays too fast in ffplay).
After a day and a half of tinkering, I just discovered that I cannot use ffmpeg to convert this stream directly. For one, the only way ffmpeg accepts piped data as input (that I'm aware of) is in the 'yuv4mpegpipe' format.
I tried piping to ffmpeg using 'm4v' as the specified format, but it seems to want to read the entire stream before it begins processing.
Anyone know how I can do this? Using commandline tools? Open source libraries in ANY programming language? Simpler solutions are preferred, but any working solution would be great.
It appears mplayer can play your m4v file over HTTP, and at least with your sample file this works:
mkfifo /tmp/fifo
mplayer -benchmark -vo yuv4mpeg:file=/tmp/fifo http://techhead.biz/media/tsv.m4v
ffmpeg -f yuv4mpegpipe -i /tmp/fifo -vcodec libx264 -vpre libx264-hq /tmp/foo.mp4
(-benchmark tells mplayer to ignore frame duration, might or might not be needed)
Alternatively, with just mencoder:
mencoder -o /tmp/foo.avi -of avi -ovc x264 -x264encopts bitrate=250 http://techhead.biz/media/tsv.m4v
Finally, if you don't actually need H.264, you could just put the existing MPEG-ES data in whatever container format you need; MP4Box might be able to do this, and ffmpeg and mencoder can if they support the output format.

Resources