模拟 FFMPEG“-sameq”所需的设置使用 libavcodec 时的标志
目前正在尝试使用libavcodec将MP4(MPEG4和H264)和MPG(MPEG2)视频文件转码为.MP4、.MPG和.AVI文件。 之前已使用 FFMpeg.exe 完成此操作,并使用“-sameq”标志来保留与输入文件相同/相似质量的输出文件。
现在使用 av_open_input_file、av_read_frame 和 avcodec_decode_video2 打开、读取和解码输入文件,然后分配 AVCodecContext 并使用 avcodec_encode_video 对数据进行编码。然而,输出文件的视频质量很差。
这些是我正在使用的 AVCodecContext 设置?:-
codecContextOutput->width = SAME AS INPUT FILE;
codecContextOutput->height = SAME AS INPUT FILE;
codecContextOutput->pix_fmt = SAME AS INPUT FILE;
/* frames per second */
AVRational ar;
ar.num = 1;
ar.den = 25;
codecContextOutput->time_base = ar;
codecContextOutput->gop_size = 10; /* emit one intra frame every ten frames */
codecContextOutput->max_b_frames=1;
codecContextOutput->bit_rate = 480000;
有谁知道模拟“-sameq”设置所需的附加设置,或者 AVCodecContext 中需要哪些附加设置来提高输出质量?
Currently attempting to use libavcodec to transcode MP4 (MPEG4 and H264) and MPG (MPEG2) video files into .MP4, .MPG and .AVI files.
Have done this previously using FFMpeg.exe with use of the '-sameq' flag to retain the same/similar quality output file to that of the input file.
Now using av_open_input_file, av_read_frame and avcodec_decode_video2 to open, read and decode the input file, then assigning a AVCodecContext and encoding the data using avcodec_encode_video. However the output file video quality is pretty poor.
These are the AVCodecContext settings I'm using?:-
codecContextOutput->width = SAME AS INPUT FILE;
codecContextOutput->height = SAME AS INPUT FILE;
codecContextOutput->pix_fmt = SAME AS INPUT FILE;
/* frames per second */
AVRational ar;
ar.num = 1;
ar.den = 25;
codecContextOutput->time_base = ar;
codecContextOutput->gop_size = 10; /* emit one intra frame every ten frames */
codecContextOutput->max_b_frames=1;
codecContextOutput->bit_rate = 480000;
Does anybody know the additional settings needed to emulate the '-sameq' setting or what additional settings are needed in the AVCodecContext to improve the output quality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过进一步测试和使用 Libavformat 库中的一些不同调用,我发现只要将输出上下文的 bit_rate 设置为与输入上下文相同,就可以保持相同的质量。
当从 MPEG2 等高带宽格式转码为 H264 流时,这不太方便,因为输出带宽可能比所需的要大得多,但它是一个解决方案,这样我就不会损失转码文件的质量。
Following further testing and use of some different calls in the Libavformat library, I've found that as long as I set the bit_rate of the output context to the same as the input context then the same quality can be maintained.
This isn't so handy when transcoding from a high bandwidth format like MPEG2, down to an H264 stream since the output bandwidth is probably much greater than it needs to be but it's a solution so that I don't lose quality from the transcoded file.