Skip to content

Commit 757641f

Browse files
committed
关键帧开始保持
1 parent 5d2597f commit 757641f

File tree

1 file changed

+5
-61
lines changed

1 file changed

+5
-61
lines changed

ijkmedia/ijkplayer/ff_ffplay.c

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,17 +3659,17 @@ static int read_thread(void *arg)
36593659
//
36603660
// }
36613661
// }
3662-
if (!ffp->real_record && (pkt->flags & AV_PKT_FLAG_KEY)) { //遇到关键帧打开开关
3662+
if (!ffp->real_record && (pkt->flags & AV_PKT_FLAG_KEY)) { //遇到关键帧打开开关,quicktime比较严格
36633663
MPTRACE("===== now III sample_rate =====\n");
36643664
ffp->real_record = true;
36653665
}
36663666

3667-
// if (ffp->real_record) {
3667+
if (ffp->real_record) {
36683668
if (0 != ffp_record_file(ffp, pkt)) {
36693669
ffp->record_error = 1;
36703670
ffp_stop_record(ffp);
36713671
}
3672-
// }
3672+
}
36733673
}
36743674
}
36753675

@@ -5200,59 +5200,7 @@ int ffp_start_record(FFPlayer *ffp, const char *file_name)
52005200
ffp->record_error = 1;
52015201
return -1;
52025202
}
5203-
/*
5204-
int ffp_record_file(FFPlayer *ffp, AVPacket *packet)
5205-
{
5206-
assert(ffp);
5207-
VideoState *is = ffp->is;
5208-
int ret = 0;
5209-
AVStream *in_stream;
5210-
AVStream *out_stream;
5211-
if (ffp->is_record) {
5212-
if (packet == NULL) {
5213-
ffp->record_error = 1;
5214-
av_log(ffp, AV_LOG_ERROR, "packet == NULL");
5215-
return -1;
5216-
}
52175203

5218-
AVPacket *pkt = (AVPacket *)av_malloc(sizeof(AVPacket)); // 与看直播的 AVPacket分开,不然卡屏
5219-
av_log(ffp, AV_LOG_INFO, "----------- pts:%llx,dts:%llx,duration:%llx",pkt->pts,pkt->dts,pkt->duration);
5220-
av_new_packet(pkt, 0);
5221-
if (0 == av_packet_ref(pkt, packet)) {
5222-
pthread_mutex_lock(&ffp->record_mutex);
5223-
if (!ffp->is_first) { // 录制的第一帧,时间从0开始
5224-
ffp->is_first = 1;
5225-
pkt->pts = 0;
5226-
pkt->dts = 0;
5227-
} else { // 之后的每一帧都要减去,点击开始录制时的值,这样的时间才是正确的
5228-
pkt->pts = abs(pkt->pts - ffp->start_pts);
5229-
pkt->dts = abs(pkt->dts - ffp->start_dts);
5230-
}
5231-
5232-
in_stream = is->ic->streams[pkt->stream_index];
5233-
out_stream = ffp->m_ofmt_ctx->streams[pkt->stream_index];
5234-
5235-
// 转换PTS/DTS
5236-
pkt->pts = av_rescale_q_rnd(pkt->pts, in_stream->time_base, out_stream->time_base, (AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
5237-
pkt->dts= av_rescale_q_rnd(pkt->dts, in_stream->time_base, out_stream->time_base, (AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
5238-
pkt->duration = av_rescale_q(pkt->duration, in_stream->time_base, out_stream->time_base);
5239-
pkt->pos = -1;
5240-
// 写入一个AVPacket到输出文件,如果遇到报错的帧,那么直接跳过ret赋值0,跳过该帧
5241-
if ((ret = av_interleaved_write_frame(ffp->m_ofmt_ctx, pkt))< 0) {
5242-
av_log(ffp, AV_LOG_ERROR, "Error muxing packet %d",ret);
5243-
ret = 0;
5244-
}
5245-
av_packet_unref(pkt);
5246-
pthread_mutex_unlock(&ffp->record_mutex);
5247-
//av_log(ffp, AV_LOG_ERROR, "av_interleaved_write_frame end");
5248-
} else {
5249-
av_log(ffp, AV_LOG_ERROR, "av_packet_ref == NULL");
5250-
}
5251-
}
5252-
return ret;
5253-
}
5254-
//*/
5255-
///*
52565204
int ffp_record_file(FFPlayer *ffp, AVPacket *packet)
52575205
{
52585206
assert(ffp);
@@ -5266,11 +5214,7 @@ int ffp_record_file(FFPlayer *ffp, AVPacket *packet)
52665214
av_log(ffp, AV_LOG_ERROR, "packet == NULL");
52675215
return -1;
52685216
}
5269-
5270-
// AVPacket *pkt = (AVPacket *)av_malloc(sizeof(AVPacket)); // 与看直播的 AVPacket分开,不然卡屏
5271-
// av_log(ffp, AV_LOG_DEBUG, "----------- pts:%llx,dts:%llx,duration:%llx",pkt->pts,pkt->dts,pkt->duration);
5272-
// av_new_packet(pkt, 0);
5273-
5217+
52745218
int size = packet->size;
52755219

52765220
AVPacket pkt;
@@ -5316,7 +5260,7 @@ int ffp_record_file(FFPlayer *ffp, AVPacket *packet)
53165260
}
53175261
return ret;
53185262
}
5319-
//*/
5263+
53205264
int ffp_stop_record(FFPlayer *ffp)
53215265
{
53225266
MPTRACE("====== stop record ======");

0 commit comments

Comments
 (0)