[Libav-user] Remux RTSP stream ?
yoann
yoann at woozoom.net
Thu Dec 29 04:32:33 EET 2016
At 2016-12-27 14:06:14, "yoann" <yoann at woozoom.net> wrote:
Hi everyone,
I am trying to remux a mp4 RTSP stream (provided by an ffserver) into a mp4 file, but I am struggling to get the file set correctly. I do not want to re-encode the stream for performances reasons.
Using the remuxing.c example, I met different issues :
- if I use the example directly, the PTS and DTS of the firsts frames are mixed up and av_write_interleaved_frames gives me a "Application provided invalid, non monotonically increasing dts to muxer in stream 0: 4752 >= 4752" error.
- if I skip a random amount of frames (I would also like to be able to start remuxing from anywhere in the stream and not only from the start), it produces a file which is eventually readable but analyzing it with ffprobe -show_frames, it throws me a "Missing key frame while reordering index according to edit list", which is understandable, I need my first frame to be an keyframe I think.
- If I try to use AV_PKT_FLAG_KEY to ensure my first frame is a keyframe, it does not changes anything, and printing the pkt.flags field give me that almost one frame on 2 i a keyframe, which is false, it is around 1 on 10 for my RTSP stream. Am I not using this flag correctly ?
I should have precised that it is a h264 stream. And from what I understood from this thread : https://ffmpeg.org/pipermail/libav-user/2013-December/005997.html, AV_PKT_FLAG_KEY is directly read from the h264 stream and not set by libavformat and is not the relevant information, the index entry is.
So if I want to start the remuxing into a file from any random point, what would be the easiest way to ensure I am starting with a keyframe ?
I can try to decode the first few frames and than check AVframe->key_frame but the performances will be poor. Is using av_seek_frame here useful is some manner ?
Here is my modified code for remuxing.c :
// same that remuxing.c before, here is around line 130
i = 0;
int have_first_keyframe = 0;
while (1) {
AVStream *in_stream, *out_stream;
ret = av_read_frame(ifmt_ctx, &pkt);
if (ret < 0)
break;
i++;
if(i <= 54){ // random number to start further in the stream
av_packet_unref(&pkt);
continue;
}
fprintf(stderr, "pkt.flags : %d \n", pkt.flags);
if(!have_first_keyframe){
if((pkt.flags & AV_PKT_FLAG_KEY) == 0){
// not a keyframe
av_packet_unref(&pkt);
continue;
} else {
have_first_keyframe = 1;
}
}
// same that remuxing.c after except I use i = 700 to break the loop and stop remuxing
Here is what the output looks like :
pkt.flags : 0
No keyframe
pkt.flags : 1
First keyframe
pkt.flags : 1
pkt.flags : 0
pkt.flags : 1
pkt.flags : 1
pkt.flags : 0
pkt.flags : 1
pkt.flags : 0
pkt.flags : 1
pkt.flags : 1
pkt.flags : 1
pkt.flags : 0
pkt.flags : 1
pkt.flags : 1
pkt.flags : 0
pkt.flags : 1
pkt.flags : 1
pkt.flags : 0
pkt.flags : 1
Someone has any advice to record an RTSP stream ?
Yoann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20161229/9c82aeb3/attachment.html>
More information about the Libav-user
mailing list