Hi everyone , i want to merge multiple videos in a...
# android
h
Hi everyone , i want to merge multiple videos in android . Is it possible using Media3 for that
not kotlin but kotlin colored 1
g
No, media3 doesn't have any video creation things, only playback them
v
Ffmpeg library does that
h
I used ffmpeg but take so long to process I tried merging 10 video of 1min and it took 10min to process
g
There are 2 main options: ffmpeg or use video codex directly, second one is way more challenging to do right I would suggest to check with ffmpeg, looks what you are doing does full re-encoding of videos, which may be what you need or not, depending on source videos For media3 I was not aware that they added those features, I believe they use Android video codex directly under the hood
h
To prevent re-encoding we use -copy , but for merging the frame rate should be same of every video
g
yep, exactly
h
But if the frame rate bis different we need to use sink
-vsync
g
so if videos are different, you have to re-encode them, which is slow
Reducing output video bitrate/resolution may be in option But I wouldn't expect magic from native hardware execrated one too
h
I cannot compromise video quality, even though you r right reducing bitrate speed up the process
But I'm wondering how video editing app does that , they have lots of feature , capcut , kinemaster and they won't take that long to process output
g
well, they work with codecs directly, a bunch of work is put there to optimize
Also ffmpeg is not a codec, there are different codecs there, they have different results, also depending on how you build it
video is hard
h
Using codec directly talking to hardware , is this a. Hard concept for a beginning?
g
Not directly, it's not correct, there is MediaCodec API, it's fully abstracted from hardware and even from specific codecs But doesn't make it easy anyway, it's still require a lot of knowledge how it works and still need a lot of handling to work on all/many devices
I just found our benchmarking, comparing libx264 libopenh264 libx265 MediaCodec Just for your information: result of encoding 20 second video on three phones with arm64 architecture: Bit rate: 400000 Frame rate: 25 Width: 640 Height: 480 Encoding with: libx264 FrameCount: 501 Encoding time: 2678877 (2.7 sec) Encoded size:: 1042868 (1.0 MB) Encoding with: libopenh264 FrameCount: 501 Encoding time: 3030407 (3.0 sec) Encoded size:: 1926019 (1.9 MB) Encoding with: libx265 FrameCount: 474 ← it drops frames Encoding time: 68466158 (6.8 sec) Encoded size:: 985413 (990.6 KB) Encoding with: native FrameCount: 501 Encoding time: 12867000 (1.29 sec) Encoded size:: 1002592 (1.0 MB) Other phones give different results, but native codec always faster
So, I would try media3 abstraction, looks very similar to what we built under the hood in our application
h
Thanks for the detailed explanation
Hey i used media3 's transformer it use mediaCodec , i tried merging 2 video of size 1 minutes , and it took around 1min20sec to merge , fastet then ffmpeg it took 2 minutes , few seconds less if I use libx264
g
yes, that what I would expect
h
Thinking of reducing frame rate before merge to 24 , it's current 30
g
I think first thing to do is fine lowest resolution and bitrate from all videos and set output format accordingly
h
Video is recorded from the mobile camera
It's same bitrate or fps for every video
g
Isn't in this case it should be possible combine them without full re-decoding? Because videos from the same device should have same resolution, codec and frame rate
h
yes , but how can i do that
g
I would expect that even ffmpeg could do this, for media3 not sure about their internal logic, but maybe if just match input configs with output
h
Ffmpeg -i first.mp4 -i second.mp4 concat "something video audio related " output.mp4
This is the basic command for merging video but it take time in android ,
g
I don't think it's so simple, but may be, depends on ffmpeg implementation for it