[Libav-user] Dumping RTSP(H264) stream to container

Leandro Raffo ljraffo at gmail.com
Tue Aug 30 17:12:00 EEST 2016


My bad. I wasn't printing the time_base values correctly. Seems that
skipping the first packet solves (still testing) the issue (I was
getting pts > pts for packet 1 and 2 which the interlaced write did
not like), and I don't know why, and now I'm getting a correct video
with the correct fps with both containers (.avi and mp4) :).

2016-08-30 10:14 GMT-03:00 Leandro Raffo <ljraffo at gmail.com>:
>
> Well seems like the base_time of the input and output streams are 0. How can this be? Anyway to fix it maybe knowing the fps?
> Here is kinda my main loop (Inserted in the main loop from remuxing.c and doing a avformat_network_init())
>
>
>     while (1) {
>         AVStream *in_stream, *out_stream;
>         if (av_read_frame(ifmt_ctx, &pkt) < 0)
>             break;
>         in_stream = ifmt_ctx->streams[pkt.stream_index];
>         out_stream = ofmt_ctx->streams[pkt.stream_index];
>
>         log_packet(ifmt_ctx, &pkt, "in");
>         /* copy packet */
>         pkt.dts = video_dts;
>         pkt.pts = ++video_dts;
>
>         // Rescaling just gives 0 dts and 0 pts
>         //av_rescale_q_rnd(++video_dts,  in_stream->time_base,  out_stream->time_base,
>         //   AV_ROUND_PASS_MINMAX | AV_ROUND_PASS_MINMAX);
>         //ofmt_ctx->duration += pkt.duration;
>
>         pkt.pos = -1;
>
>         log_packet(ofmt_ctx, &pkt, "out");
>
>         if (av_interleaved_write_frame(ofmt_ctx, &pkt) < 0) {
>             fprintf(stderr, "Error muxing packet\n");
>             break;
>         }
>
>         av_packet_unref(&pkt);
>
>         end = clock();
>         if ( (100.f * (double)(end - begin) / CLOCKS_PER_SEC) > 10) {
>             break;
>         }
>
>
>     }
>
>
> 2016-08-29 13:09 GMT-03:00 Leandro Raffo <ljraffo at gmail.com>:
>>
>> Seems its just working with .avi as container and using mp4 just gives me like a half-second video for the same filesize. Also I didn't have a duration when watching the result over a video player, summing to the AVFormatContext->duration for the output stream's got me a duration when playing but I'm getting like 35 secs video for a 60 secs recording (It also looks kinda accelerated and it keeps just working for .avi).
>>
>> 2016-08-29 11:01 GMT-03:00 Leandro Raffo <ljraffo at gmail.com>:
>>>
>>> I finally managed to make it work using the remuxing.c example by doing an
>>>
>>> avformat_network_init()
>>>
>>> And incrementaly adding (from zero) one to pts and dts with pts + 1 = dts.
>>>
>>> I still don't understand why is this the case. "It Just Works" and I dont like it. Can someone please enlighten me on this? Why don't I need to use the in/out stream time_base?
>>> Thanks in advance
>>>
>>> ---------- Forwarded message ----------
>>> From: Leandro Raffo <ljraffo at gmail.com>
>>> Date: 2016-08-24 10:25 GMT-03:00
>>> Subject: Dumping RTSP(H264) stream to container
>>> To: libav-user at ffmpeg.org
>>>
>>>
>>> Hello,
>>>
>>> As the title say I'm trying to remux(I dont know if this is the correct term) a rtsp h264 stream into a container(mp4). I've been fiddling with the remuxing example given in the documentation for ffmpeg 3.1 (https://www.ffmpeg.org/doxygen/3.1/remuxing_8c-example.html) with no avail.
>>> I know I can read the frames because I wrote them to disk (decode -> encoded, not in h264 might i say so.). So I'm having troubles with the writing them raw part (writing the frames without an decode/encode pipeline).
>>> I'm also a bit lost with the dts and pts in this part, how would this work for an encoded stream?.
>>>
>>> These are the errors I'm getting when remuxing from two files
>>>
>>> [mp4 @ 0x1d869e0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
>>> [mp4 @ 0x1d869e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
>>> [mp4 @ 0x1d869e0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
>>> [mp4 @ 0x1d869e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
>>> [mp4 @ 0x1d869e0] track 1: codec frame size is not set
>>> [mp4 @ 0x1d869e0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
>>>
>>> And when remuxing from the rtsp stream
>>>
>>> [avi @ 0x18d1fe0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
>>> [avi @ 0x18d1fe0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
>>> [avi @ 0x18d1fe0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 15 >= 6
>>>
>>>
>>> Thanks in advance.
>>>
>>
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>


More information about the Libav-user mailing list