<div dir="ltr">I believe "avformat_write_header" can be omitted for RTSP Stream and it'll just blow right through it.<div><br></div><div>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.</div><div><br></div><div>Getting an error myself when I call 'av_write_frame', it'll crash and tell me:<br>Exception thrown at 0x00007FF84B59291A (avformat-58.dll) in Ffmpeg_Simple_Server.exe: 0xC0000005: Access violation writing location 0x0000000000000000.<br></div><div><br></div><div>If you manage to get past this, I'd appreciate a look at your working code. Good luck.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 4, 2020 at 11:28 AM Thierry Gayet <<a href="mailto:thierry.gayet@dazzl.tv">thierry.gayet@dazzl.tv</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello guys,<br clear="all"><div><br>We are currently trying to stream a video (h264) and audio (opus) stream through an RTSP connection. </div><div><br></div><div>It worked well until a change of API. Indeed, since then we have been using the version installed by ubuntu 16.04. </div><div><br></div><div>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.<br></div><div><br></div><div>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?<br></div><div><br></div><div>Here is the code used:<br></div><div><br></div><div> AVCodecContext * avctx;<br> char filename[500];<br> char stream_title[256];<br> AVCodec *audio_input_codec;<br> AVCodec *audio_output_codec;<br> AVCodecContext *audio_input_codec_context;<br> AVCodecContext *audio_output_codec_context;<br> AVStream *audio_stream;<br> AVOutputFormat *video_output_codec;<br> AVCodecContext *video_output_codec_context;<br> AVStream *video_stream;<br> AVFormatContext *rtsp_format_context;<br><br> av_register_all();<br> avformat_network_init();<br><br> audio_input_codec = NULL;<br> audio_output_codec = NULL;<br> audio_input_codec_context = NULL;<br> audio_output_codec_context = NULL;<br> audio_stream = NULL;<br><br> video_output_codec = NULL;<br> video_output_codec_context = NULL;<br> video_stream = NULL;<br> rtsp_format_context = NULL;<br><br> /* Open RTSP muxer */<br> snprintf(filename, sizeof(filename), "rtsp://<a href="http://127.0.0.1:5544/live/session_12135464647967643468" target="_blank">127.0.0.1:5544/live/session_12135464647967643468</a>");<br> printf("Publishing RTSP stream on %s\n", filename);<br><br> err = avformat_alloc_output_context2(&rtsp_format_context, NULL, "rtsp", filename);<br><br> video_output_codec = avcodec_find_encoder(AV_CODEC_ID_H264);<br> if (!video_output_codec) {<br> printf("Could not initialize H264 codec\n");<br> return (-1);<br> }<br><br> video_stream = avformat_new_stream(rtsp_format_context, video_output_codec);<br> if (!channel->video_stream) {<br> printf("Could not create video stream\n");<br> return(-1);<br> }<br><br> avctx = avcodec_alloc_context3(video_output_codec);<br> err = avcodec_parameters_to_context(avctx, video_stream->codecpar);<br> if(err < 0){<br> printf("Could not initialize video_output_codec_context parameters %d\n" , err);<br> avcodec_free_context(&avctx);<br> return(-1);<br> }<br> video_output_codec_context = avctx;<br> video_output_codec_context->codec_type = AVMEDIA_TYPE_VIDEO;<br> video_output_codec_context->codec_id = AV_CODEC_ID_H264;<br> video_output_codec_context->thread_count = 1;<br><br> /*<br> * Those video codec parameters must be set up even if our video codec is<br> * a fake one (i.e. no encoding is involved, we forward video packets with<br> * no changes). This is basically used to generate a correct<br> * sprop-parameter-sets in the SDP file, which is also useless since H264<br> * parameters are transmitted inband in H264 SPS PPS packets (that's the case<br> * at least for webRTC).<br> */<br> video_output_codec_context->width = 960;<br> video_output_codec_context->height = 720;<br> video_output_codec_context->time_base = (AVRational) {1, 15};<br> video_output_codec_context->bit_rate = 600000;<br> video_output_codec_context->pix_fmt = AV_PIX_FMT_YUV420P;<br><br> /*<br> * H264 profile-id setup<br> * For some reason it doesn't work just by setting up<br> * FF_PROFILE_H264_CONSTRAINED_BASELINE. An obscure av_opt_set function must be<br> * called ...<br> */<br> av_opt_set(video_output_codec_context->priv_data, "profile", "baseline", AV_OPT_SEARCH_CHILDREN);<br><br> video_output_codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;<br> video_stream->time_base = (AVRational) {1, 15};<br><br> err = avcodec_open2(channel->video_output_codec_context, channel->video_output_codec, NULL); <br><br><br> /* OPUS Decoder init */<br> audio_input_codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);<br> if (!audio_input_codec){<br> printf("Could not initialize OPUS codec\n");<br> return (-1);<br> }<br><br> audio_input_codec_context = avcodec_alloc_context3(audio_input_codec);<br> if (!audio_input_codec_context) {<br> printf("Could not initialize OPUS codec context\n");<br> return (-1);<br> }<br><br> err = avcodec_open2(audio_input_codec_context, audio_input_codec, NULL);<br><br> err = avformat_write_header(&rtsp_format_context, NULL);<br></div><div><br></div><div>Here are some traces while initializing :</div><div><br></div><div>[libx264 @ 0x557123450480] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512</div><div><br>[libx264 @ 0x557123450480] profile Constrained Baseline, level 3.1</div><div><br>[libx264 @ 0x557123450480] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - <a href="http://www.videolan.org/x264.html" target="_blank">http://www.videolan.org/x264.html</a> - 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<br>Adding metadata for ffmpeg expected for evostream : dazzl_12135464647967643468</div><div><br>[rtsp @ 0x55712344bfe0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.</div><div><br>[rtsp @ 0x55712344bfe0] dimensions not set<br></div><div><br></div><div>At the end it stuck with the avformat_write_header because of the initialisation maybe in relation with the two RTSP traces</div><div><br></div><div>Thanks in advance of your reply !</div>-- <br><div dir="ltr"><div dir="ltr"><br><div>Regards</div><div><br></div><div>Thierry GAYET</div><div><br></div><div>(Courrouze)</div><div>Village by CA<br>3 avenue Germaine Tillon<br>Saint Jacques de la Lande.<br></div></div></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Matthew Czarnek<div>(814) 421-6770</div></div></div>