【发布时间】:2015-01-04 05:11:24
【问题描述】:
文件中特定帧的 PTS 是否可能与流式传输时同一文件中同一帧的 PTS 不同?
当我使用 av_read_frame 读取帧时,我将视频流存储在 AVStream 中。使用 avcodec_decode_video2 解码帧后,我使用 av_frame_get_best_effort_timestamp 将该帧的时间戳存储在 int64_t 中。现在,如果程序从文件中获取输入,我会得到与将输入(来自同一文件)流式传输到程序时不同的时间戳。
要更改输入类型,我只需将 argv 参数从“/path/to/file.mp4”更改为“udp://localhost:1234”,然后在命令行中使用 ffmpeg 流式传输文件:“ ffmpeg -re -i /path/to/file.mp4 -f mpegts udp://localhost:1234"。会不会是因为“-f mpegts”参数改变了媒体的某些特性?
以下是我的代码(简化)。通过阅读 ffmpeg 邮件列表档案,我意识到我正在寻找的 time_base 在 AVStream 而不是 AVCodecContext 中。而不是使用 av_frame_get_best_effort_timestamp 我也尝试使用 packet.pts 但结果没有改变。 我需要时间戳来了解正在接收的流视频中的帧号。 我非常感谢任何形式的帮助。
//..
//argv[1]="/file.mp4";
argv[1]="udp://localhost:7777";
// define AVFormatContext, AVFrame, etc.
// register av, avcodec, avformat_network_init(), etc.
avformat_open_input(&pFormatCtx, argv, NULL, NULL);
avformat_find_stream_info(pFormatCtx, NULL);
// find the video stream...
// pointer to the codec context...
// open codec...
pFrame=av_frame_alloc();
while(av_read_frame(pFormatCtx, &packet)>=0) {
AVStream *strem = pFormatCtx->streams[videoStream];
if(packet.stream_index==videoStream) {
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if(frameFinished) {
int64_t perts = av_frame_get_best_effort_timestamp(pFrame);
if (isMyFrame(pFrame)){
cout << perts*av_q2d(strem->time_base) << "\n";
}
}
}
//free allocated space
}
//..
【问题讨论】:
标签: c++ stream ffmpeg libavcodec libavformat