bilibili / bilibili/ijkplayer

读取网络流丢包导致跳帧

Open
#4,591 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
33.2k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Description

if ((ret = avformat_open_input(&ifmt_ctx, video_source, 0, NULL)) < 0) {
av_log(NULL, AV_LOG_ERROR, "[nelson] -- Could not open %s Url \n", video_source);
goto end;
}
av_log(NULL, AV_LOG_ERROR, "[nelson] -- Open %s Url Success \n", video_source);

if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
av_log(NULL, AV_LOG_ERROR, "[nelson] -- Failed to retrieve input stream information \n");
goto end;
}

avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);
if (!ofmt_ctx) {
av_log(NULL, AV_LOG_ERROR, "[nelson] -- Could not create output context \n");
ret = AVERROR_UNKNOWN;
goto end;
}

ofmt = ofmt_ctx->oformat;

av_log(NULL, AV_LOG_ERROR, "[nelson] -- Copy Streams Start \n");

for (int i = 0; i nb_streams; i++) {
// create output stream
AVStream *in_stream = ifmt_ctx->streams[i];
AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
if (!out_stream) {
av_log(ffp, AV_LOG_ERROR, "record - Failed allocating output stream\n");
goto end;
}

// copy params to AVCodecContext
av_log(ffp, AV_LOG_DEBUG, "record - in_stream->codec;\n", in_stream->codec);
if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {
av_log(ffp, AV_LOG_ERROR, "record - Failed to copy context from input to output stream codec context\n");
goto end;
}
out_stream->codec->codec_tag = 0;
}

av_log(NULL, AV_LOG_ERROR, "[nelson] -- Copy Streams Success \n");

av_dump_format(ofmt_ctx, 0, out_filename, 1);

if (!(ofmt->flags & AVFMT_NOFILE)) {
ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR,"[nelson] -- Could not open output file '%s'", out_filename);
goto end;
}
}

ret = avformat_write_header(ofmt_ctx, NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "[nelson] -- Error occurred when opening output file\n");
goto end;
}
int num = 0;
int recordFinished = 0;
while (isRecording(ffp,key)) {
ret = av_read_frame(ifmt_ctx, &pkt);
if (ret < 0)
break;
ret = av_interleaved_write_frame(ofmt_ctx, &pkt);
av_log(NULL, AV_LOG_ERROR,"[nelson] -- Record %s Frame '%d' \n", out_filename, num++);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "[nelson] -- Error muxing packet\n");
break;
}
av_packet_unref(&pkt);
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start from the shown recording loop around av_read_frame and av_interleaved_write_frame, and reproduce the reported packet-loss behavior with a network stream. Trace how read or write errors affect frame handling and identify the relevant recording entry point in the repository. Done means the reported frame skipping is addressed and the recording path remains functional.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.