ffmpeg kit android Cannot add audio to some videos

120 Views Asked by At

I am using the following ffmpeg kit libray in Android To add music to video file.

    implementation 'com.arthenica:ffmpeg-kit-full-gpl:5.1'

And I am using the following command to add audio.mp3 file to the video.mp4 file.

        StringBuilder command = new StringBuilder()
            .append("-y") // overWrite
            .append(" -i ").append(video) // video
            .append(" -i ").append(audio) // audio
            .append(" -c:v ").append("copy")
            .append(" -c:a ").append("copy")
            .append(" -shortest ")  
            .append(" -f ").append("mp4 ")
            .append(tempFile.getAbsolutePath());

The command is working great. But in some Videos, the audio is not added. That's the problem.

Here are the logs.

Output #0, mp4, to '......./files/temp20230610_223225.mp4':
  Metadata:
    major_brand     : 
isom

    minor_version   : 
512

    compatible_brands: 
isomiso2avc1mp41

    comment         : 
vid:v10044g50000ci19mj3c77u6if7ahsug

    encoder         : 
Lavf59.27.100

  Stream #0:0
(und)
: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 576x1024 [SAR 1:1 DAR 9:16], q=2-31, 1289 kb/s
, 
30 fps, 
30 tbr, 
15360 tbn
 (default)

    Metadata:
      handler_name    : 
VideoHandler

      vendor_id       : 
[0][0][0][0]

  Stream #0:1
(und)
: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
 (default)

    Metadata:
      handler_name    : 
SoundHandler

      vendor_id       : 
[0][0][0][0]

Stream mapping:
  Stream #0:0 -> #0:0
 (copy)

  Stream #0:1 -> #0:1
 (copy)

Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=-1.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame= 1257 fps=0.0 q=-1.0 Lsize=    7296kB time=00:00:41.95 bitrate=1424.4kbits/s speed= 425x    
video:6594kB audio:656kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.629013%
frame= 1257 fps=0.0 q=-1.0 Lsize=N/A time=00:00:41.95 bitrate=N/A speed= 423x    
video:6594kB audio:656kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
0

There are 0 best solutions below