仅当以 30 FPS 拍摄视频时,FFmpeg 视频输出才会被放大?
FFmpeg video output is being zoomed in ONLY when video is taken in 30 FPS?
我已经使用 FFmpeg 大约一个月了,它很棒。
我正在 IOS 上以 60FPS 或 30FPS 拍摄视频。我正在将视频大小调整为 1:1(或 4:3)。
我正在用拍摄我的视频https://github.com/mrousavy/react-native-vision-camera
默认的 60FPS 一切正常。但是,出于某种原因,当以 30FPS 拍摄视频时,在执行 FFmpeg 后视频会放大,我无法弄清楚为什么...
这是我的 FFmpeg 命令在我的函数中的样子(React JS 钩子):
const onMediaCaptured = useCallback(
(media: PhotoFile | VideoFile, type: 'photo' | 'video') => {
setIsProcessingMedia(!isProcessingMedia);
var path =
type === 'photo'
? RNFS.DocumentDirectoryPath + '/after.png'
: RNFS.DocumentDirectoryPath + '/after.mp4';
const portraitCrop =
type === 'video' ? 'crop=1080:1350' : 'crop=1350:1080';
const ffMPEGcmd = isSquareRatio
? `-y -i ${
media.path
} -aspect 1:1 -vf "crop=1080:1080:exact=1, scale=1080:1080, ${
type === 'photo' ? 'transpose=1' : null
}" -qscale 0 -b:v 10M ${path}`
: `-y -i ${media.path} -vf "${portraitCrop}, ${
type === 'photo' ? 'transpose=1' : null
}" -b:v 10M -qscale 0 ${path}`;
FFmpegKit.execute(ffMPEGcmd).then(async session => {
const returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
// SUCCESS
FFprobeKit.getMediaInformation(path)
.then(async (session: MediaInformationSessionCamera) => {
const information: MediaInformation =
await session.getMediaInformation();
const output = await session.getOutput();
const outputJSON = JSON.parse(output);
const newOne = outputJSON;
const videoHeight = newOne.streams[0].height;
const videoWidth = newOne.streams[0].width;
setIsProcessingMedia(false);
Actions.push('cameraMediaCaptured', {
isSquareRatio: isSquareRatio,
type: type,
ratio: isSquareRatio ? 1080 / 1080 : 1350 / 1080,
color: props.color,
category: props.category,
needsCrop: true,
videoHeight: videoHeight,
videoWidth: videoWidth,
aspectRatio: videoHeight / videoWidth,
});
})
.catch(error => console.error(error));
} else if (ReturnCode.isCancel(returnCode)) {
// CANCEL
} else {
// ERROR
alert('error');
}
});
},
[isSquareRatio, props.category, props.color, isProcessingMedia],
);
我很感激能得到任何反馈!
干杯。
它是否以 30 和 60 fps 的相同分辨率捕获视频?如果不是,并且 30 fps 可以为您提供更高分辨率的视频,crop
过滤器可以有效地为您提供缩放的视频。请改用输入大小表达式:类似 crop=ih:ih
也请阅读 the documentation. There are a lot of examples there as well. If you wish to use more complex expression so you don't need to do portrait/landscape detection in javascript, check out the FFmpeg expression syntax。
我已经使用 FFmpeg 大约一个月了,它很棒。
我正在 IOS 上以 60FPS 或 30FPS 拍摄视频。我正在将视频大小调整为 1:1(或 4:3)。
我正在用拍摄我的视频https://github.com/mrousavy/react-native-vision-camera
默认的 60FPS 一切正常。但是,出于某种原因,当以 30FPS 拍摄视频时,在执行 FFmpeg 后视频会放大,我无法弄清楚为什么...
这是我的 FFmpeg 命令在我的函数中的样子(React JS 钩子):
const onMediaCaptured = useCallback(
(media: PhotoFile | VideoFile, type: 'photo' | 'video') => {
setIsProcessingMedia(!isProcessingMedia);
var path =
type === 'photo'
? RNFS.DocumentDirectoryPath + '/after.png'
: RNFS.DocumentDirectoryPath + '/after.mp4';
const portraitCrop =
type === 'video' ? 'crop=1080:1350' : 'crop=1350:1080';
const ffMPEGcmd = isSquareRatio
? `-y -i ${
media.path
} -aspect 1:1 -vf "crop=1080:1080:exact=1, scale=1080:1080, ${
type === 'photo' ? 'transpose=1' : null
}" -qscale 0 -b:v 10M ${path}`
: `-y -i ${media.path} -vf "${portraitCrop}, ${
type === 'photo' ? 'transpose=1' : null
}" -b:v 10M -qscale 0 ${path}`;
FFmpegKit.execute(ffMPEGcmd).then(async session => {
const returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
// SUCCESS
FFprobeKit.getMediaInformation(path)
.then(async (session: MediaInformationSessionCamera) => {
const information: MediaInformation =
await session.getMediaInformation();
const output = await session.getOutput();
const outputJSON = JSON.parse(output);
const newOne = outputJSON;
const videoHeight = newOne.streams[0].height;
const videoWidth = newOne.streams[0].width;
setIsProcessingMedia(false);
Actions.push('cameraMediaCaptured', {
isSquareRatio: isSquareRatio,
type: type,
ratio: isSquareRatio ? 1080 / 1080 : 1350 / 1080,
color: props.color,
category: props.category,
needsCrop: true,
videoHeight: videoHeight,
videoWidth: videoWidth,
aspectRatio: videoHeight / videoWidth,
});
})
.catch(error => console.error(error));
} else if (ReturnCode.isCancel(returnCode)) {
// CANCEL
} else {
// ERROR
alert('error');
}
});
},
[isSquareRatio, props.category, props.color, isProcessingMedia],
);
我很感激能得到任何反馈!
干杯。
它是否以 30 和 60 fps 的相同分辨率捕获视频?如果不是,并且 30 fps 可以为您提供更高分辨率的视频,crop
过滤器可以有效地为您提供缩放的视频。请改用输入大小表达式:类似 crop=ih:ih
也请阅读 the documentation. There are a lot of examples there as well. If you wish to use more complex expression so you don't need to do portrait/landscape detection in javascript, check out the FFmpeg expression syntax。