gpt4 book ai didi

java - 如何修复 "FFmpeg cannot edit existing files in-place."- Java 中的问题

转载 作者:行者123 更新时间:2023-12-02 03:23:16 36 4
gpt4 key购买 nike

我正在尝试将音频文件写入现有视频文件。不幸的是,我收到了日志消息,表明我无法就地编辑现有文件。

我发现了一些关于视频和音频之间所谓的混合的线程,但它们都不能真正帮助我。也许你们中的某个人可以。此外,这也不是我能做的。我只是需要使用它的人,所以我必须修复它。

感谢您的帮助

String[] args = { FFMPEG_FILE.getAbsolutePath(), "-y", "-i", videoPath, "-ss", String.valueOf(-offset.toFrames() / 50.0f), "-i", audioPath, "-c", "copy", "-map", "0:v", "-map","1:a", "-bsf:v", "h264_mp4toannexb","-r", String.valueOf(project.getFramerate()), "-shortest",outputPath };

ProcessBuilder pb = new ProcessBuilder(args).inheritIO();
Process p = pb.start();
int exit = p.waitFor();
if (exit != 0) {
throw new IOException("ffmpeg terminated with a failure");
}

编辑:正如有人评论的那样,outputPath 与 videopath 相同。于是换了一个,这样就不会再出现这个问题了。但我的输出视频仍然没有声音。我给你日志信息,所以也许你可以从中读到一些东西。

INFO: start ffmpeg: [C:\Program Files\ffmpeg\bin\ffmpeg.exe, -y, -i, C:\Users\USERNAME\Desktop\Test_Workflow\1.mkv, -ss, 0.0, -i, C:\Users\USERNAME\Desktop\Test\resources/videos/P1000501.MP4\audio.ogg, -c, copy, -map, 0:v, -map, 1:a, -bsf:v, h264_mp4toannexb, -r, 25, -shortest, C:\Users\USERNAME\Desktop\Test\testoutput.mp4]
ffmpeg version N-92087-gdcbd89e000 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180813
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 19.101 / 56. 19.101
libavcodec 58. 31.102 / 58. 31.102
libavformat 58. 18.104 / 58. 18.104
libavdevice 58. 4.105 / 58. 4.105
libavfilter 7. 33.100 / 7. 33.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, matroska,webm, from 'C:\Users\USERNAME\Desktop\Test_Workflow\1.mkv':
Metadata:
ENCODER : Lavf56.4.101
Duration: 00:00:04.60, start: 0.080000, bitrate: 1377 kb/s
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
Input #1, ogg, from 'C:\Users\USERNAME\Desktop\Test\resources/videos/P1000501.MP4\audio.ogg':
Duration: 00:04:20.65, start: 0.000000, bitrate: 86 kb/s
Stream #1:0(und): Audio: vorbis, 48000 Hz, stereo, fltp, 112 kb/s
Metadata:
CREATION_TIME : 2018-11-09T13:20:07.000000Z
LANGUAGE : und
ENCODER : Lavc58.31.102 libvorbis
MAJOR_BRAND : mp42
MINOR_VERSION : 1
COMPATIBLE_BRANDS: mp42avc1
[mp4 @ 000001e67c0a00c0] track 1: codec frame size is not set
Output #0, mp4, to 'C:\Users\USERNAME\Desktop\Test\testoutput.mp4':
Metadata:
encoder : Lavf58.18.104
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
Stream #0:1(und): Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 112 kb/s
Metadata:
CREATION_TIME : 2018-11-09T13:20:07.000000Z
LANGUAGE : und
ENCODER : Lavc58.31.102 libvorbis
MAJOR_BRAND : mp42
MINOR_VERSION : 1
COMPATIBLE_BRANDS: mp42avc1
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 113 fps=0.0 q=-1.0 Lsize= 824kB time=00:00:04.41 bitrate=1530.8kbits/s speed= 634x
video:772kB audio:43kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 1.092082%

最佳答案

对于最初的问题,“FFmpeg 无法就地编辑现有文件。”,这是因为 ffmpeg 需要读取输入,因此它无法同时替换输入。

就当前问题而言,vorbis 不是 MP4 的标准音频编解码器,因此需要重新编码音频。

C:\Program Files\ffmpeg\bin\ffmpeg.exe、-y、-i、C:\Users\USERNAME\Desktop\Test_Workflow\1.mkv、-ss、0.0、-i、C :\Users\用户名\桌面\测试\资源/视频/P1000501.MP4\audio.ogg、-c:v、复制、-map、0:v、-map、1:a、-r、25、-shortest , C:\Users\USERNAME\Desktop\Test\testoutput.mp4

(由于您正在写入 MP4,-bsf:v, h264_mp4toannexb 与您想要的相反,这里不需要)

关于java - 如何修复 "FFmpeg cannot edit existing files in-place."- Java 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56917890/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com