以编程方式转码MPEG-2视频 [英] Programmatically transcode MPEG-2 videos

查看:213
本文介绍了以编程方式转码MPEG-2视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够以编程方式将mpeg-2文件转码为.mp4,.mp3,.wmv,.rm(可选)和.flv(可选),并希望生成缩略图。我发现了Java媒体框架,但它坦率地看起来很肮脏。这将运行一个Linux服务器,所以我可以使用Commons Exec来卸载ffmpeg - ffmpeg是否做了我需要做的一切? FFmpeg似乎相当令人生畏,这就是为什么我无法找到这些信息,但它绝对似乎是一个千篇一律的交易。任何建议?

I need to be able to programmatically transcode mpeg-2 files to .mp4, .mp3, .wmv, .rm (optional), and .flv (optional), and hopefully generate a thumbnail as well. I found the Java Media Framework, but it frankly looks pretty crappy. This will be running a Linux server, so I could shell out to ffmpeg using Commons Exec - does ffmpeg do everything I need to do? FFmpeg seems pretty daunting, which is why I'm having trouble finding this information, but it definitely seems to be a jack-of-all-trades. Any suggestions?

推荐答案

Ffmpeg是最好最简单的。要输出/转换视频:

Ffmpeg is the best and easiest. To output/convert video:

ffmpeg -i {input}.ext -r {target_frame_rate} -ar {target_audio_rate} -b {target_bitrate} -s {width}x{height} {target}.ext

而您的屏幕截图:

ffmpeg -i {input}.ext -r 1 -ss 00:00:04:005 -t 00:00:01 -an -s {width}x{height} {target_name}%d.jpg

15 fps是flv的标准,音频采样率应为flv的44100。使用的选项: -r 指定1 fps的帧速率(一帧用作屏幕截图), -ss 寻求你想要的位置 hh:mm:ss:fff -t 是持续时间(匹配一秒)您的一帧), -an 告诉ffmpeg忽略音频,而 -s 是屏幕截图的大小。 %d 是必需的,因为它将以您使用的屏幕截图数量递增。以上所述,%d 将始终为数字1(一帧,一个截图)。祝你好运。

15 fps is standard for flv and audio sample rate should be 44100 for flv. Options to use: -r specifies a frame rate of 1 fps (one frame used as the screenshot), -ss seeks to the position you want hh:mm:ss:fff, -t is the duration (one second to match your one fps), -an tells ffmpeg to ignore audio, and -s is the size of the screenshot. The %d is necessary as it will be the digit incremented on how many screenshots you use. With the above, %d will always be the number 1 (one frame, one screenshot). Good luck.

这篇关于以编程方式转码MPEG-2视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆