如何使用jpeg框架制作.avi,.mp4文件? [英] How to make .avi, .mp4 file with jpeg frames?

查看:74
本文介绍了如何使用jpeg框架制作.avi,.mp4文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IP摄像机,并且从摄像机获得了Jpeg帧和音频数据(PCM).

I'm working with IP camera, and I have got Jpeg frames and audio data (PCM) from camera.

现在,我想根据以上数据创建.avi或.mp4格式的视频文件(音频和视频).

Now, I want to create video file (both audio and video) under .avi or .mp4 format from above data.

我进行了搜索,我知道ffmpeg库可以做到.但是我不知道如何使用ffmpeg来做到这一点.

I searched and I knew that ffmpeg library can do it. But I don't know how to using ffmpeg to do this.

您能建议我一些示例代码或ffmpeg的功能吗?

Can you suggest me some sample code or the function of ffmpeg to do it?

推荐答案

如果您的目标是编写一个c ++应用程序来为您执行此操作,请忽略此答案,我将其留在此处以供将来参考.如果没有,请按照以下步骤在bash中进行操作:

If your objective is to write a c++ app to do this for you please disregard this answer, I'll just leave it here for future reference. If not, here's how you can do it in bash:

首先,请确保您的图片格式正确,并且ffmpeg易于处理.您可以将图像复制到其他目录:

First, make sure your images are in a nice format, easy to handle by ffmpeg. You can copy the images to a different directory:

mkdir tmp
x=1; for i in *jpg; do counter=$(printf %03d $x); cp "$i" tmp/img"$counter".jpg; x=$(($x+1)); done

将音频数据复制到tmp目录并编码视频.假设您的相机每十秒钟拍摄一张照片:

Copy your audio data to the tmp directory and encode the video. Let's say your camera took a picture every ten seconds:

cd tmp
ffmpeg -i audio.wav -f image2 -i img%03d.jpg -vcodec msmpeg4v2 -r 0.1 -intra out.avi

其中 -r 0.1 表示0.1的帧频,即每10秒一帧.

Where -r 0.1 indicates a framerate of 0.1 which is one frame every 10 seconds.

这里可能的问题是:

  • 您的音频/视频可能会略有不同步,除非您事先仔细计算所需的帧速率.您应该能够使用ffmpeg和一些 grep 魔术来获得音频(或视频)的长度.即便如此,对于较长的剪辑,同步可能仍然是一个问题.
  • 如果图像多于999张,则%03d 格式将不够用,请确保将 3 更改为所需的索引长度
  • 视频将从更长的流中继承其长度,您可以使用 -t 开关对其进行限制:

  • Your audio/video might go slightly out of sync unless you calculate your desired framerate carefully in advance. You should be able to get the length of the audio (or video) using ffmpeg and some grep magic. Even so the sync might be an issue with longer clips.
  • if you have more than 999 images the %03d format will not be enough, make sure to change the 3 to the desired length of the index
  • The video will inherit its length from the longer of the streams, you can restrict it using the -t switch:

-t持续时间-将转码/捕获的视频序列限制为以秒为单位指定的持续时间.还支持"hh:mm:ss [.xxx]"语法.

这篇关于如何使用jpeg框架制作.avi,.mp4文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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