我试图从一组帧使用FFMPEG使用libx264编解码器编码。mp4视频。

这是我正在运行的命令:

/usr/local/bin/ffmpeg -r 24 -i frame_%05d.jpg -vcodec libx264 -y -an video.mp4

我有时会得到以下错误:

[libx264 @ 0xa3b85a0] height not divisible by 2 (520x369)

在搜索了一下之后,似乎这个问题与缩放算法有关,可以通过添加-vf参数来修复。

然而,在我的例子中,我不想做任何缩放。理想情况下,我希望保持尺寸与框架完全相同。任何建议吗?是否存在h264强制的某种纵横比?

ffmpeg -r 1/5 -start_number 2 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

这一行工作得很好,但我想从另一个文件夹中的图像创建一个视频文件。 我文件夹中的图像名称是:

img001.jpg
img002.jpg
img003.jpg
...

我如何从不同的文件夹输入图像文件?例如:C: \ mypics

我尝试了这个命令,但ffmpeg只生成了第一个图像(img001.jpg)的视频。

ffmpeg -r 1/5 -start_number 0 -i C:\myimages\img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

如何通过命令行或批处理脚本与ffmpeg转换整个目录/文件夹?

我一直试图弄清楚如何旋转视频与FFmpeg。我正在处理以竖屏模式拍摄的iPhone视频。我知道如何使用MediaInfo(优秀的库,顺便说一下)确定当前的旋转程度,但我现在卡住了FFmpeg。

从我所读到的,你需要使用的是一个vfilter选项。根据我看到的,它应该是这样的:

ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4

然而,我不能让它工作。首先,-vfilters已经不存在了,现在只有-vf。其次,我得到这个错误:

No such filter: 'rotate'
Error opening filters!

据我所知,我有一个全选项的FFmpeg构建。运行ffmpeg -filters显示:

Filters:
anull            Pass the source unchanged to the output.
aspect           Set the frame aspect ratio.
crop             Crop the input video to x:y:width:height.
fifo             Buffer input images and send them when they are requested.
format           Convert the input video to one of the specified pixel formats.
hflip            Horizontally flip the input video.
noformat         Force libavfilter not to use any of the specified pixel formats
 for the input to the next filter.
null             Pass the source unchanged to the output.
pad              Pad input image to width:height[:x:y[:color]] (default x and y:
 0, default color: black).
pixdesctest      Test pixel format definitions.
pixelaspect      Set the pixel aspect ratio.
scale            Scale the input video to width:height size and/or convert the i
mage format.
slicify          Pass the images of input video on to next video filter as multi
ple slices.
unsharp          Sharpen or blur the input video.
vflip            Flip the input video vertically.
buffer           Buffer video frames, and make them accessible to the filterchai
n.
color            Provide an uniformly colored input, syntax is: [color[:size[:ra
te]]]
nullsrc          Null video source, never return images.
nullsink         Do absolutely nothing with the input video.

拥有vflip和hflip的选项很棒,但它们不能让我去我需要去的地方。我需要至少能够将视频旋转90度。270度也是个不错的选择。旋转选项去哪儿了?

我尝试了以下命令从视频中提取音频:

ffmpeg -i Sample.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 Sample.mp3

但我得到了如下的输出

libavutil     50.15. 1 / 50.15. 1
libavcodec    52.72. 2 / 52.72. 2
libavformat   52.64. 2 / 52.64. 2
libavdevice   52. 2. 0 / 52. 2. 0
libavfilter    1.19. 0 /  1.19. 0
libswscale     0.11. 0 /  0.11. 0
libpostproc   51. 2. 0 / 51. 2. 0
SamplE.avi: Invalid data found when processing input

有人能帮忙吗?

我正在尝试使用ffmpeg连接两个mp4文件。我需要这是一个自动过程,因此我选择了ffmpeg。我将这两个文件转换为.ts文件,然后将它们连接起来,然后尝试对连接的.ts文件进行编码。文件是h264和aac编码的,我希望保持质量相同或尽可能接近原始。

ffmpeg -i part1.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part1.ts
ffmpeg -i part2.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part2.ts
cat part1.ts part2.ts > parts.ts
ffmpeg -y -i parts.ts -acodec copy -ar 44100 -ab 96k -coder ac -vbsf h264_mp4toannexb parts.mp4

不幸的是,我在编码过程中从ffmpeg返回以下错误消息:

[h264 @ 0x1012600]sps_id out of range
[h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
[h264 @ 0x1012600]sps_id out of range
[h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
[NULL @ 0x101d600]error, non monotone timestamps 13779431 >= 13779431kbits/s    
av_interleaved_write_frame(): Error while opening file

这种情况大约发生在编码的一半,这让我认为不能将两个.ts文件合并在一起并使其正常工作。

我尝试使用以下命令使用视频的开始和结束时间来剪切视频

ffmpeg -ss 00:00:03 -t 00:00:08 -i movie.mp4 -acodec copy -vcodec copy -async 1 cut.mp4

通过使用上面的命令,我想把视频从00:00:03剪辑到00:00:08。但它并没有在这两个时间之间剪切视频,而是剪切了前11秒的视频。有人能帮我解决这个问题吗?

编辑1:

我尝试使用mark4o建议的以下命令进行切割

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

但是显示了以下错误。

编码器“aac”是实验性的,但实验性编解码器未启用

因此,我在命令中添加了-strict -2,即,

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 -strict -2 cut.mp4

现在它工作得很好。