Xabe.FFmpeg icon indicating copy to clipboard operation
Xabe.FFmpeg copied to clipboard

Slow video split

Open M4jx opened this issue 5 years ago • 6 comments

Conversion.Split() functionality is to get a specific part from the video. The problem with the current implementation is that it's too slow compared to copying -c copy which lead to same results but faster.

I haven't looked at the implementation but it looks like Conversion.Split() renders the video again because it takes long time to complete. However the performance deffer too much between the two.

Using current split() Conversion.Split(input, output, 0, 20) execution time: 17994 ms

Using copying Conversion().Start("-i input -ss 0 -t 20 -c copy output") execution time: 732 ms

Both lead to same results but copying is a lot faster.

M4jx avatar Feb 24 '20 18:02 M4jx

Good to know. Added to my task list :) But feel free to create pull request with change.

tomaszzmuda avatar Feb 24 '20 18:02 tomaszzmuda

Hey, I've tried to change that but I cannot get any accurate result. For example video starts at 8 second instead of 2. (Try it on input.mp4 located in repository). Current solution will work on all file types but if you want to use it on larger files or some second different doesn't matter to you use copy. Maybe I just was unlocky and I don't find the perfect combination.

tomaszzmuda avatar Feb 29 '20 18:02 tomaszzmuda

The video I benchmarked is 30s long and 32.2 MB in size and gave the results above. Since input.mp4 (the one in repo) is not a large file (2 MB), the current implementation would work and there would be no major difference in performance. Otherwise if the video is big in size then copy would be a lot faster. As I know -copy supports all file types (I could be wrong). But it would make a big difference in performance.

M4jx avatar Feb 29 '20 22:02 M4jx

Please try run this in Xabe.FFmpeg.Test/Resources directory: ffmpeg.exe -i .\input.mp4 -ss 00:00:02 -t 00:00:08 -c copy output.mp4 Output.mp4 should have 8 seconds, from 2nd to 10th second of input.mp4. But there is something strange, and I get only 2 second of video stream from 8th second of input.mp4. image (Audio stream has 8 seconds)

tomaszzmuda avatar Mar 01 '20 09:03 tomaszzmuda

Possible related FFMPEG bug.

https://trac.ffmpeg.org/ticket/8456

Sent with GitHawk

06needhamt avatar Mar 01 '20 20:03 06needhamt

Sorry for the delayed response. It looks like the command I provided in the sample has the parameters wrongly placed. As I read on multiple sources it seems like you should seek -ss before providing the input -i. Something like this ffmpeg -ss 00:00:02 -i input.mp4 -t 00:00:08 -c copy output.mp4 should work. But there seems to be a problem/bug related to the output video length. When I tried it on the input.mp4 in the repo it produced a 10sec long video instead of 8sec even though -t 00:00:08 is provided! It seems like it's a codec problems see here. However on other inputs I tried it, and it worked perfectly and produced a video with correct length. I guess re-encoding works for the moment, unless we find the cause and the solution for the copying issue so it becomes more stable.

M4jx avatar Mar 03 '20 23:03 M4jx