[Libav-user] RTSP with ffmpeg 4.1
Matthew Czarnek
mczarnek at edge360.com
Wed Feb 12 00:00:59 EET 2020
I believe "avformat_write_header" can be omitted for RTSP Stream and it'll
just blow right through it.
Working on a similar problem.. outputting to RTSP stream , crazy thing is I
had it working, then had git issues and the whole thing broke and now can't
remember what I'm doing wrong.
Getting an error myself when I call 'av_write_frame', it'll crash and tell
me:
Exception thrown at 0x00007FF84B59291A (avformat-58.dll) in
Ffmpeg_Simple_Server.exe: 0xC0000005: Access violation writing location
0x0000000000000000.
If you manage to get past this, I'd appreciate a look at your working code.
Good luck.
On Tue, Feb 4, 2020 at 11:28 AM Thierry Gayet <thierry.gayet at dazzl.tv>
wrote:
> Hello guys,
>
> We are currently trying to stream a video (h264) and audio (opus) stream
> through an RTSP connection.
>
> It worked well until a change of API. Indeed, since then we have been
> using the version installed by ubuntu 16.04.
>
> On the way to ubuntu 18.04, it didn't work anymore. We have tried to adapt
> the APIs to the more recent one, but we still have a problem.
>
> Among the people subscribed to this mailing list or even developers of
> FFmpeg, are there people who have already used an RTSP connection (as a
> client) on the last API? I can't find anything among the examples?
>
> Here is the code used:
>
> AVCodecContext * avctx;
> char filename[500];
> char stream_title[256];
> AVCodec *audio_input_codec;
> AVCodec *audio_output_codec;
> AVCodecContext *audio_input_codec_context;
> AVCodecContext *audio_output_codec_context;
> AVStream *audio_stream;
> AVOutputFormat *video_output_codec;
> AVCodecContext *video_output_codec_context;
> AVStream *video_stream;
> AVFormatContext *rtsp_format_context;
>
> av_register_all();
> avformat_network_init();
>
> audio_input_codec = NULL;
> audio_output_codec = NULL;
> audio_input_codec_context = NULL;
> audio_output_codec_context = NULL;
> audio_stream = NULL;
>
> video_output_codec = NULL;
> video_output_codec_context = NULL;
> video_stream = NULL;
> rtsp_format_context = NULL;
>
> /* Open RTSP muxer */
> snprintf(filename, sizeof(filename), "rtsp://
> 127.0.0.1:5544/live/session_12135464647967643468");
> printf("Publishing RTSP stream on %s\n", filename);
>
> err = avformat_alloc_output_context2(&rtsp_format_context, NULL, "rtsp",
> filename);
>
> video_output_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
> if (!video_output_codec) {
> printf("Could not initialize H264 codec\n");
> return (-1);
> }
>
> video_stream = avformat_new_stream(rtsp_format_context,
> video_output_codec);
> if (!channel->video_stream) {
> printf("Could not create video stream\n");
> return(-1);
> }
>
> avctx = avcodec_alloc_context3(video_output_codec);
> err = avcodec_parameters_to_context(avctx, video_stream->codecpar);
> if(err < 0){
> printf("Could not initialize video_output_codec_context parameters
> %d\n" , err);
> avcodec_free_context(&avctx);
> return(-1);
> }
> video_output_codec_context = avctx;
> video_output_codec_context->codec_type = AVMEDIA_TYPE_VIDEO;
> video_output_codec_context->codec_id = AV_CODEC_ID_H264;
> video_output_codec_context->thread_count = 1;
>
> /*
> * Those video codec parameters must be set up even if our video codec is
> * a fake one (i.e. no encoding is involved, we forward video packets
> with
> * no changes). This is basically used to generate a correct
> * sprop-parameter-sets in the SDP file, which is also useless since H264
> * parameters are transmitted inband in H264 SPS PPS packets (that's the
> case
> * at least for webRTC).
> */
> video_output_codec_context->width = 960;
> video_output_codec_context->height = 720;
> video_output_codec_context->time_base = (AVRational) {1, 15};
> video_output_codec_context->bit_rate = 600000;
> video_output_codec_context->pix_fmt = AV_PIX_FMT_YUV420P;
>
> /*
> * H264 profile-id setup
> * For some reason it doesn't work just by setting up
> * FF_PROFILE_H264_CONSTRAINED_BASELINE. An obscure av_opt_set function
> must be
> * called ...
> */
> av_opt_set(video_output_codec_context->priv_data, "profile", "baseline",
> AV_OPT_SEARCH_CHILDREN);
>
> video_output_codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
> video_stream->time_base = (AVRational) {1, 15};
>
> err = avcodec_open2(channel->video_output_codec_context,
> channel->video_output_codec, NULL);
>
>
> /* OPUS Decoder init */
> audio_input_codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);
> if (!audio_input_codec){
> printf("Could not initialize OPUS codec\n");
> return (-1);
> }
>
> audio_input_codec_context = avcodec_alloc_context3(audio_input_codec);
> if (!audio_input_codec_context) {
> printf("Could not initialize OPUS codec context\n");
> return (-1);
> }
>
> err = avcodec_open2(audio_input_codec_context, audio_input_codec, NULL);
>
> err = avformat_write_header(&rtsp_format_context, NULL);
>
> Here are some traces while initializing :
>
> [libx264 @ 0x557123450480] using cpu capabilities: MMX2 SSE2Fast SSSE3
> SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
>
> [libx264 @ 0x557123450480] profile Constrained Baseline, level 3.1
>
> [libx264 @ 0x557123450480] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC
> codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options:
> cabac=0 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1
> psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0
> cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1
> lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
> bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250
> keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1
> bitrate=600 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
> aq=1:1.00
> Adding metadata for ffmpeg expected for evostream :
> dazzl_12135464647967643468
>
> [rtsp @ 0x55712344bfe0] Using AVStream.codec to pass codec parameters to
> muxers is deprecated, use AVStream.codecpar instead.
>
> [rtsp @ 0x55712344bfe0] dimensions not set
>
> At the end it stuck with the avformat_write_header because of the
> initialisation maybe in relation with the two RTSP traces
>
> Thanks in advance of your reply !
> --
>
> Regards
>
> Thierry GAYET
>
> (Courrouze)
> Village by CA
> 3 avenue Germaine Tillon
> Saint Jacques de la Lande.
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
--
Matthew Czarnek
(814) 421-6770
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200211/bb7d05d5/attachment.html>
More information about the Libav-user
mailing list