Hi All, hi Luca
I sent my problematic source code
I am using vlc and SDP file
int main(int argc, char **argv)
{
const char *input_filename =
"/home/georgi/Downloads/video/IMG_0019.MOV";
const char *filename = "rtp://10.101.3.60:9078";
AVOutputFormat *fmt;
AVFormatContext *input_context = NULL;
AVFormatContext *output_context = NULL;
av_register_all();
avformat_network_init();
int ret;
ret = avformat_open_input(&input_context, input_filename, NULL, NULL);
if (ret)
{
return 1;
}
avformat_find_stream_info(input_context, NULL);
fmt = av_guess_format("rtp", filename, NULL);
if (!fmt)
{
fprintf(stderr, "Could not find suitable output format\n");
return 1;
}
output_context = avformat_alloc_context();
if (!output_context)
{
fprintf(stderr, "Memory error\n");
return 1;
}
output_context->oformat = fmt;
snprintf(output_context->filename, sizeof(output_context->filename),
"%s", filename);
int video_idx;
for (video_idx = 0; video_idx < input_context->nb_streams; video_idx++)
{
if (AVMEDIA_TYPE_VIDEO ==
input_context->streams[video_idx]->codec->codec_type)
{
break;
}
}
AVStream *input_video_stream = input_context->streams[video_idx];
AVStream *output_video_stream = avformat_new_stream(output_context,
input_video_stream->codec->codec);
//ret = avcodec_copy_context(output_video_stream->codec,
input_video_stream->codec);
AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_H264);
assert(NULL != codec);
output_video_stream->codec = avcodec_alloc_context3(codec);
output_video_stream->codec->codec_id = AV_CODEC_ID_H264;
output_video_stream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
output_video_stream->codec->bit_rate = 400000;
output_video_stream->codec->width = input_video_stream->codec->width;
output_video_stream->codec->height = input_video_stream->codec->height;
output_video_stream->time_base.num = 1;
output_video_stream->time_base.den = 30;
output_video_stream->codec->max_b_frames = 2;
output_video_stream->codec->gop_size = 12;
output_video_stream->codec->pix_fmt = PIX_FMT_YUV420P;
if (ret < 0)
{
fprintf(stderr, "Failed to copy context from input to output stream
codec context\n");
}
output_video_stream->codec->codec_tag = 0;
if (output_context->oformat->flags & AVFMT_GLOBALHEADER)
output_video_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
if (!(output_context->oformat->flags & AVFMT_NOFILE))
{
ret = avio_open(&output_context->pb, filename, AVIO_FLAG_WRITE);
if (ret < 0)
{
fprintf(stderr, "Could not open output file '%s'", filename);
}
}
ret = avformat_write_header(output_context, NULL);
if (ret < 0)
{
fprintf(stderr, "Error occurred when opening output file\n");
}
int i = 0;
AVPacket pkt;
while (1)
{
i++;
ret = av_read_frame(input_context, &pkt);
if (ret < 0)
break;
if (pkt.stream_index != video_idx)
continue;
AVStream *in_stream = input_context->streams[pkt.stream_index];
AVStream *out_stream = output_context->streams[pkt.stream_index];
//copy packet
pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base,
out_stream->time_base, AV_ROUND_NEAR_INF);
pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base,
out_stream->time_base, AV_ROUND_NEAR_INF);
pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base,
out_stream->time_base);
pkt.pos = -1;
ret = av_interleaved_write_frame(output_context, &pkt);
if (ret < 0)
{
fprintf(stderr, "Error muxing packet\n");
break;
}
av_free_packet(&pkt);
usleep(100000);
}
av_write_trailer(output_context);
avformat_close_input(&input_context);
if (output_context && !(output_context->flags & AVFMT_NOFILE))
avio_close(output_context->pb);
avformat_free_context(output_context);
return 0;
}
My SDP file content's
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 10.101.3.60
t=0 0
a=tool:libavformat 56.25.101
m=video 9078 RTP/AVP 96
b=AS:5486
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;
sprop-parameter-sets=Z2QAKKy0A8ARPy4CIAAAfSAAHUwB4wZU,aO48sA==;
profile-level-id=640028
2015-03-13 18:10 GMT+02:00 Georgi Rosenov Stefanov <[email protected]
>:
> Hi All,
>
> I succeeded to stream good packages using ffmpeg. But I want to use libav
> code.
> Is there any know issue with RTP streaming ?
>
_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api