除了使用FFMPEG和MP4Parser之外,还有其他方法可以修剪视频吗?

时间:2019-01-01 09:12:57

标签: android android-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时长之间修剪视频。

1 个答案:

答案 0 :(得分:0)

您上面的示例是根据您提供的命令对视频进行重新编码。如果您不需要重新编码视频,则可以使用stream copy option,它将直接将输入流复制到输出流。请注意,我们不严格保证您会获得精确的开始行为,因为您可能在那个确切点上没有所需的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