相关疑难解决方法(0)

了解视频帧中的PTS和DTS

从avi转换为mp4(x264)时,我遇到了fps问题.最终问题出现在PTS和DTS值中,因此第12-15行在av_interleaved_write_frame函数之前添加:

1.  AVFormatContext* outContainer = NULL;
2.  avformat_alloc_output_context2(&outContainer, NULL, "mp4", "c:\\test.mp4";
3.  AVCodec *encoder = avcodec_find_encoder(AV_CODEC_ID_H264);
4.  AVStream *outStream = avformat_new_stream(outContainer, encoder);
5.  // outStream->codec initiation
6.  // ...
7.  avformat_write_header(outContainer, NULL);

8.  // reading and decoding packet
9.  // ...
10. avcodec_encode_video2(outStream->codec, &encodedPacket, decodedFrame, &got_frame)
11. 
12. if (encodedPacket.pts != AV_NOPTS_VALUE)
13.     encodedPacket.pts =  av_rescale_q(encodedPacket.pts, outStream->codec->time_base, outStream->time_base);
14. if (encodedPacket.dts != AV_NOPTS_VALUE)
15.     encodedPacket.dts = av_rescale_q(encodedPacket.dts, outStream->codec->time_base, outStream->time_base);
16. 
17. av_interleaved_write_frame(outContainer, &encodedPacket)
Run Code Online (Sandbox Code Playgroud)

看完很多帖后我还是不明白:

  1. outStream->codec->time_base= 1/25和outStream->time_base= 1/12800.第一个由我设定,但我无法弄清楚为什么和谁设置12800?我注意到在行(7) …

video ffmpeg pts video-streaming avcodec

23
推荐指数
1
解决办法
4万
查看次数

标签 统计

avcodec ×1

ffmpeg ×1

pts ×1

video ×1

video-streaming ×1