首页 > 解决方案 > 除了使用 FFMPEG 和 MP4Parser 之外,还有什么方法可以修剪视频吗?

问题描述

我已经使用 FFMPEG 进行视频修剪,但视频处理花费了太多时间。

String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", yourRealPath, "-t", "" + (endMs - startMs) / 1000,"-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", filePath};

也使用了 MP4Parser,但有时我遇到了问题。为此在lib下使用。

com.googlecode.mp4parser:isoparser:1.1.21

有没有其他方法可以修剪视频?

就像我的视频持续时间是 20:00 并在 06:00-09:00 持续时间之间修剪视频。

标签: androidandroid-ffmpegmp4parser

解决方案


您上面的示例是根据您给它的命令重新编码视频。如果您不需要重新编码视频,您可以使用流复制选项,它直接将输入流复制到输出流。请注意,您不能严格保证获得精确的开始行为,因为您可能没有在该确切点需要的 I 帧或等效项,或者编解码器必须向前或向后跳转才能找到一个。这种方法非常快,因为没有编码工作要做,它只是从一个(文件)到另一个的副本。在我 2018 级的笔记本电脑上,我花了大约 1.5 秒的时间剪辑了 3 分钟的视频……

$ time ffmpeg -hide_banner -y -i input.mpg -ss 6:00 -t 3:00 -c:v copy output.mpg      
[mpeg @ 0000024ffd46a740] start time for stream 0 is not set in estimate_timings_from_pts
Input #0, mpeg, from 'input.mpg':
  Duration: 00:29:57.45, start: 0.516689, bitrate: 4108 kb/s
    Stream #0:0[0x1bf]: Data: dvd_nav_packet
    Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
[mpeg @ 0000024ffd47d500] VBV buffer size not set, using default size of 230KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, mpeg, to 'output.mpg':
  Metadata:
    encoder         : Lavf58.25.100
    Stream #0:0: Video: mpeg2video (Main), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mpeg @ 0000024ffd47d500] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
frame=10780 fps=0.0 q=-1.0 Lsize=   88314kB time=00:02:59.98 bitrate=4019.5kbits/s speed= 379x    
video:87826kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.556108%

real    0m1.546s
user    0m0.000s
sys     0m0.000s

推荐阅读