Srt: ffmpeg srt to dash

Created on 3 May 2018  路  27Comments  路  Source: Haivision/srt

Hello,

I would know if it's possible to transcode a stream which I receive through srt to MPEG-dash ?

My input command is :

ffmpeg -re -i 'udp://127.0.0.1:8080' -f mpegts 'srt://127.0.0.1:1234'

I tried something like this :

ffmpeg -i srt://127.0.0.1:1234 -re -r 23.976 -s 480x204 -aspect 2.35 -acodec libfaac -ac 2 -ar 44100 -ab 128k -vcodec libx264 -vprofile baseline -preset fast -vb 500k -f mpegts -threads 0 -async 2 OUTPUT_FILE.ts

Thx

Question

Most helpful comment

Hi,
I know the issue. I have debuged it.

Caller:
ffmpeg -re -i big_buck_bunny_720p_stereo.avi -f mpegts "srt://server.com:1234"

you MUST setup packet size.

I have patched ffmpeg to accept new options such as:

ffmpeg -xerror -y -i 'rtmp://127.0.0.1/app/zenlink_m1' -c:v copy -c:a copy -f mpegts -muxrate 7M 'srt://127.0.0.1:17241?pkt_size=1316&buffer_size=1048576&mode=caller&oheadbw=50&inputbw=875000&tsbpddelay=2000000'

check the patch:
https://gist.github.com/nxtreaming/defaf90d4a08fdda0a7b30440ddfbbaa

`

All 27 comments

This has nothing to do with SRT. It's only the matter of that the party, which receives the TS stream over SRT, can convert the MPEG TS stream into MPEG-Dash - same situation when you received the MPEG TS stream over UDP.

It麓s possible to convert your SRT to dash. Your command line do a transcoding, you also can do transmuxing from srt to mpegdash which does not require transcoding (saves CPU power). For transmuxing, see ffmpeg copy flags (parameter -c:v copy) and make sure that your video codec and audio codec is compatible to your mpegdash player.

Your output call is not generating mpeg-dash segments, you are saving a single mpegts file. Mpegdash requires segmenting in a manifest file (with byteranges) or in single file segments, but both method requires the manifest file.

Segmenting with ffmpeg is possible with the segment muxer (see ffmpeg: https://www.ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment)

Hope that helps.

Thank you for your help i will take a look at it.

I tried earlier this morning to implement an hls solution like the example in the documentation. But something strange appened i'm not able to use srt directly at input of my ffmpeg command but when I use an intermediate stream it works ...

SItuation 1 : Not working 馃憥

Listener :
ffmpeg -i srt://:1234 -c:v h264 -flags +cgop -g 30 -hls_fragment_filename 'pi/stream%08d.ts' pi/stream.m3u8

Caller:
ffmpeg -re -i big_buck_bunny_720p_stereo.avi -f mpegts "srt://server.com:1234"

ffmpeg version N-90927-g0f0d468fbc Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
configuration: --enable-libsrt --enable-libx264 --enable-libx265 --enable-gpl
libavutil 56. 18.100 / 56. 18.100
libavcodec 58. 19.100 / 58. 19.100
libavformat 58. 13.100 / 58. 13.100
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 21.100 / 7. 21.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, avi, from 'big_buck_bunny_720p_stereo.avi':
Metadata:
encoder : MEncoder 2:1.0~rc2-0ubuntu13
Duration: 00:09:56.46, start: 0.000000, bitrate: 3815 kb/s
Stream #0:0: Video: msmpeg4v2 (MP42 / 0x3234504D), yuv420p, 1280x720, 3556 kb/s, 24 fps, 24 tbr, 24 tbn, 24 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 245 kb/s
[srt @ 0x7fcd8a50de00] Connection setup failure: connection time out.
srt://server.com:1234: Unknown error occurred >

Solution 2 : Working 馃憤

Listener :
stransmit srt://:1234 udp://127.0.0.1:8080

Caller:
ffmpeg -re -i big_buck_bunny_720p_stereo.avi -f mpegts "srt://server.com:1234"

Conveter:
ffmpeg -i udp://:8080 -c:v h264 -flags +cgop -g 30 -hls_fragment_filename 'pi/stream%08d.ts' pi/stream.m3u8

Any idea ?

Huh, interesting... I don't even know how the implementation looks like, is it possible to increase the log level? This "Connection setup failure..." definitely comes from SRT, but it would be nice to see what happened before.

In verbose mode i get this log :

Caller & Listener :

Successfully opened the file.
Parsing a group of options: output url srt://server:1234.
Applying option f (force format) with argument mpegts.
Successfully parsed a group of options.
Opening an output file: srt://server:1234.
[srt @ 0x7fb9dad06580] No default whitelist set
[srt @ 0x7fb9dad06580] Connection setup failure: connection time out.
srt://server:1234: Unknown error occurred

Tell me if you need something more detailed.

Oh, that "whitelist" thing definitely doesn't come from SRT library.

SRT has possible very detailed debug level logging, I just don't know if the log level settings have been correctly synchronized with these in ffmpeg.

Hi,
I know the issue. I have debuged it.

Caller:
ffmpeg -re -i big_buck_bunny_720p_stereo.avi -f mpegts "srt://server.com:1234"

you MUST setup packet size.

I have patched ffmpeg to accept new options such as:

ffmpeg -xerror -y -i 'rtmp://127.0.0.1/app/zenlink_m1' -c:v copy -c:a copy -f mpegts -muxrate 7M 'srt://127.0.0.1:17241?pkt_size=1316&buffer_size=1048576&mode=caller&oheadbw=50&inputbw=875000&tsbpddelay=2000000'

check the patch:
https://gist.github.com/nxtreaming/defaf90d4a08fdda0a7b30440ddfbbaa

`

Why isn't pkt_size set default to 1316?

I already add this line into libsrt.c :
h->max_packet_size = 1316

source : https://qiita.com/tetsu_koba/items/92c398abd96c651f4035 & https://qiita.com/tetsu_koba/items/b8e1868a726c6201d3ab

because libavformat/libsrt.c does not implement very correctly.

ffmpeg mpegts has default 1316 as packet size, but the protocal (avio buffer) layer should be adjusted as well, otherwisze it will use 32K as buffer size,

My change is a little bit more barbarian but at the end we've got the same thing no ? @nxtreaming

Or maybe I misunderstand something in your modification.

@nxtreaming with your patch i have 2 new log :

[AVIOContext @ 0x7f8cddd06bc0] Statistics: 790496 bytes read, 5 seeks
09:37:49.162919!!FATAL!!: SRT.c: CChannel reported ERROR DURING TRANSMISSION - IPE. INTERRUPTING worker anyway.>

After using Wireshark , we saw that the caller send 12 handshake request, all request are recieved by the Listener but no respond from it

The debug logs on the listener could be the only way to tell why it's not sending any response.

@nawer56

my test is fine

the caller:
ffmpeg -xerror -y -i 'rtmp://127.0.0.1/app/just4test' -c:v copy -c:a copy -f mpegts -muxrate 7M 'srt://my.server.com:18241?pkt_size=1316&buffer_size=1048576&mode=caller&oheadbw=50&inputbw=875000&tsbpddelay=2000000'

the server (my.server.com)
ffmpeg -i "srt://:18241?mode=listener" -codec copy -bsf:a aac_adtstoasc -f flv rtmp://127.0.0.1/relay/abc

maybe your original stream is not fine.

If you need my patched FFmpeg, I can share you.

OK we are going in the right direction. I'm now able to get an exchange beetween my server and caller.
Unfortunatly I've got an ffmpeg error --'. But it's just about ffmpeg config now.

I tried with all your option then I remove one by one to know which are my sticking point.

At the end it's works with this configuration :

Caller:
ffmpeg -v "trace" -re -i big_buck_bunny_720p_stereo.avi -f mpegts "srt://server.com:1234"
Listener:
ffmpeg -v "debug" -i "srt://:1234?mode=listener" -c:v h264 -flags +cgop -g 30 -hls_segment_filename 'pi/stream-%08d.ts' pi/stream.m3au8

And not with :

Caller:
ffmpeg -v "trace" -re -i big_buck_bunny_720p_stereo.avi -f mpegts "srt://server.com:1234"

Listener:
listner HLS : ffmpeg -v "debug" -i "srt://:1234" -c:v h264 -flags +cgop -g 30 -hls_segment_filename 'pi/stream-%08d.ts' pi/stream.m3au8

But conforming to the documentation they are no difference beetween both command...

srt://:1234 - the port is specified (1234), but host is empty. This assumes listener mode.

srt://:1234 - the port is specified (1234), but host is empty. This assumes listener mode.

it's the default action of srtransmit app, not FFmpeg's

You SHOULD add "mode=listener" in FFmpeg receiver.

@nxtreaming congrats for figuring out this issue with srt implementation in ffmpeg. I have been banging my head over this exact issue of pkt_size=1316 and how to set it up in srt .
You should submit this patch to ffmpeg-devel mail-list

A ticket had been opened on ffmpeg trac: i added a ref to this thread and a link to the patch by nxstreaming which is better than the hack by koba IMO.

@pkviet my patch is not the best one.
I think the best one is to reuse the "mss" option in libsrt.c, but my patch is compatible with ffmpeg's UDP syntax.

@nxtreaming oh; i had tried mss option with 1316 and failed to have it work; but it does work, dunno what I did.
Yeah, so your patch is not needed but a patch for the doc would still be a good idea with a clear explanation that mss=1316 should be used.

Please update the patch to fix the typo in libsrt.c
https://gist.github.com/nxtreaming/a931bfbb6092939666e270542ec6afb7

@nxtreaming you need to submit the patch in ffmpeg-devel mail-list or email to the maintainer of libsrt in ffmpeg (see maintainers file)

hi guys,
followed the conversation here, and i may be missing something , but even after fixing the MMS-->MSS typo in libsrt.c and rebuilding ffmpeg, i still get
on Sender:
./ffmpeg-4.1dev -v "trace" -y -i 'udp://@239.44.100.250:5001?reuse=true&timeout=500&fifo_size=573440&buffer_size=128000&overrun_nonfatal=true&localport=30503' -c:v copy -c:a copy -f mpegts -muxrate 7M 'srt://10.23.205.221:8000?pkt_size=1316&buffer_size=1048576&mode=caller&oheadbw=50&inputbw=875000&tsbpddelay=2000000'
......
[

srt @ 0x4bedec0] Operation not supported: Incorrect use of Message API (sendmsg/recvmsg)..
av_interleaved_write_frame(): Unknown error occurred
No more output streams to write to, finishing.
Error writing trailer of srt://10.23.205.221:8000?pkt_size=1316&buffer_size=1048576&mode=caller&oheadbw=50&inputbw=875000&tsbpddelay=2000000: Unknown error occurred

on Receiver
./ffmpeg-4.1dev -v "trace" -i "srt://:8000?mode=listener" -codec copy -f mpegts udp://239.44.100.101:5000?pkt_size=1316
....

Opening an input file: srt://:8000?mode=listener.
[NULL @ 0x47d3b00] Opening 'srt://:8000?mode=listener' for reading
[srt @ 0x47d4400] No default whitelist set
[srt @ 0x47d4400] Operation not supported: Invalid socket ID: No such file or directory.
[AVIOContext @ 0x47f8640] Statistics: 0 bytes read, 0 seeks
srt://:8000?mode=listener: Unknown error occurred

Hi @nxtreaming 锛孖 see you methion that"If you need my patched FFmpeg, I can share you."Can you share me one thanks!
Because I am trying to generate SRT stream from file and decoder it by ffmpeg,but failed.
My command:

Caller
ffmpeg -re -i D:/test.flv -c:v copy -c:a
copy -f mpegts -muxrate 7M srt://127.0.0.1:2345?pkt_size=1316&mode=caller
Listener:
ffmpeg  -i srt://:2345?mode=listener  -c:v copy -c:a copy -f flv tcp://127.0.0.1:6789

And the result
image

@Amyyum my patch has been published.

Looks like we can close this. Do not hesitate to reopen if required.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moonbc picture moonbc  路  4Comments

boxerab picture boxerab  路  5Comments

alexpokotilo picture alexpokotilo  路  9Comments

prabh13singh picture prabh13singh  路  9Comments

gou4shi1 picture gou4shi1  路  5Comments