简体   繁体   中英

Is there any way to trim video except using FFMPEG and MP4Parser?

I have used FFMPEG for video trimming but it's taking too much time for video processing.

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};

also used MP4Parser for same but some time I'm getting issue. used below lib for that.

com.googlecode.mp4parser:isoparser:1.1.21

Is there any other way available to trim video?

like my video duration is 20:00 and trim video between 06:00-09:00 duration.

Your example above is re-encoding the video based on the commands you give it. If you do NOT need to re-encode the video you can use the stream copy option , which directly copies the input stream to the output stream. Note that you are not strictly guaranteed to get precise beginning behavior, as you may not have the I-frame or equivalent you need at that exact point, or the codec my have to jump forward or backwards to find one. This method is extremely fast because there's no coding work to be done, it's just a copy from one (file) to another. On my 2018-class laptop it took me ~1.5 seconds to clip out 3 minutes of a video...

$ 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM