[Libav-user] Converting ts to DASH using libavformat

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Converting ts to DASH using libavformat

Simon Brown
I'm trying to convert an incoming transport stream to DASH without re-encoding.

I've done this using two separate ffmpeg commands and it works, but as each instance of FFMpeg spends time locking onto the stream, finding the first I-frame, etc the resulting latency is unacceptable.  I thought I could streamline this somewhat by writing it using the libav libraries that come with FFmpeg.

I've taken the demux_decode.c example and receive the stream.  I don't decode it, I just get a packet from the stream using:

av_read_frame(fmt_ctx, &pkt)

Once read, I try and write it to the stream using:

   ret = av_interleaved_write_frame(oc, &pkt);

having setup oc as an output context for muxer "dash".

    avformat_alloc_output_context2(&oc, NULL, "dash", filename);

However, I seem to have missed some vital steps, because the dash muxer responds with:
Output #0, dash, to 'vid.mpd':
    Stream #0:0: Unknown: none

The muxing.c example is all about taking some generated frames and encoding them before sending them out and that sets up a codec context which is added to the dash muxer, but I don't want a codec context, because I don't want to encode an already encoded stream.

Any help would be greatly appreciated.

Regards,
Simon

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Converting ts to DASH using libavformat

James


On Tue, 25 Feb 2020 at 17:13, Simon Brown <[hidden email]> wrote:
I'm trying to convert an incoming transport stream to DASH without re-encoding.

I've done this using two separate ffmpeg commands and it works, but as each instance of FFMpeg spends time locking onto the stream, finding the first I-frame, etc the resulting latency is unacceptable.  I thought I could streamline this somewhat by writing it using the libav libraries that come with FFmpeg.

I've taken the demux_decode.c example and receive the stream.  I don't decode it, I just get a packet from the stream using:

av_read_frame(fmt_ctx, &pkt)

Once read, I try and write it to the stream using:

   ret = av_interleaved_write_frame(oc, &pkt);

having setup oc as an output context for muxer "dash".

    avformat_alloc_output_context2(&oc, NULL, "dash", filename);

However, I seem to have missed some vital steps, because the dash muxer responds with:
Output #0, dash, to 'vid.mpd':
    Stream #0:0: Unknown: none

The muxing.c example is all about taking some generated frames and encoding them before sending them out and that sets up a codec context which is added to the dash muxer, but I don't want a codec context, because I don't want to encode an already encoded stream.

Any help would be greatly appreciated.

Regards,
Simon
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

See the "remuxing.c" example.
Use avcodec_parameters_copy to copy the codecpar from the demuxer's AVStream to the muxer's one.

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Converting ts to DASH using libavformat

Simon Brown

See the "remuxing.c" example.
Use avcodec_parameters_copy to copy the codecpar from the demuxer's AVStream to the muxer's one.

Thanks James - that's exactly what I needed.  Now I just need to pass all the parameters I need into the dash muxer and I'll be sorted.

Cheers,
Simon 

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Converting ts to DASH using libavformat

Simon Brown


On Wed, 26 Feb 2020 at 11:28, Simon Brown <[hidden email]> wrote:

See the "remuxing.c" example.
Use avcodec_parameters_copy to copy the codecpar from the demuxer's AVStream to the muxer's one.

Thanks James - that's exactly what I needed.  Now I just need to pass all the parameters I need into the dash muxer and I'll be sorted.

Cheers,
Simon 

Ok, next problem - I have parsed all the command line parameters and assigned them to the output context using:

    ret = avformat_write_header(ofmt_ctx, &opt);

where opt contains the options dictionary.  I know it is accepting this because the returned dictionary is empty.  Also, I know because it is clearing out older .m4s segment files so that my disk doesn't fill up, so it's accepting the window_size parameter.  What it's not doing though, when it runs, is outputting continuously updated manifest.mpd data - which if I run ffmpeg with the same command line options I do get.  So ultimately my manifest.mpd file has a single segment in it, and my dash player never plays anything.

Looking through dashenc.c it would appear that the manifest should be updated whenever write_packet is called, and I'm assuming this is called because otherwise I wouldn't get the .m4s files being output.  But something must be failing here.  Is there anyway I can see what options the dash mux is using and why it wouldn't be outputting manifest updates?

To write the frames out I am using the same line as in remuxing.c, namely:

        ret = av_interleaved_write_frame(ofmt_ctx, &pkt);

should I just use av_write_frame?

Regards,
Simon 

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Converting ts to DASH using libavformat

Simon Brown

Ok, next problem - I have parsed all the command line parameters and assigned them to the output context using:

    ret = avformat_write_header(ofmt_ctx, &opt);

where opt contains the options dictionary.  I know it is accepting this because the returned dictionary is empty.  Also, I know because it is clearing out older .m4s segment files so that my disk doesn't fill up, so it's accepting the window_size parameter.  What it's not doing though, when it runs, is outputting continuously updated manifest.mpd data - which if I run ffmpeg with the same command line options I do get.  So ultimately my manifest.mpd file has a single segment in it, and my dash player never plays anything.

Looking through dashenc.c it would appear that the manifest should be updated whenever write_packet is called, and I'm assuming this is called because otherwise I wouldn't get the .m4s files being output.  But something must be failing here.  Is there anyway I can see what options the dash mux is using and why it wouldn't be outputting manifest updates?

To write the frames out I am using the same line as in remuxing.c, namely:

        ret = av_interleaved_write_frame(ofmt_ctx, &pkt);

should I just use av_write_frame?

Regards,
Simon 
 
 I've tried av_write_frame and the results are better, in that the manifest is updated each segment, but it still only has 1 segment in it, whereas if I use ffmpeg it has multiple segments, so still nothing plays in the browser.

I don't see what can be going wrong here - it MUST have the same options because otherwise it would be forever adding new .m4s files without deleting the old ones.

Cheers,
Simon

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".