bravobit / FFmpeg-Android

FFMpeg/FFprobe compiled for Android
https://bravobit.nl/
MIT License
739 stars 175 forks source link

Trimming video: incorrect duration #32

Closed ritesh94 closed 6 years ago

ritesh94 commented 6 years ago

@Brianvdb

When I try to trim a video to 3 sec the output video becomes 01 mins :23 sec

Following is the command for trimming: (88 and 91 are the start and end time in seconds) -y -i /storage/emulated/0/abc.mp4 -ss 88 -t 91 -async 1 -c copy /storage/emulated/0/video_trimmed.mp4

Video file details: Duration: 02 mins 51 secs Size: 1280x720

Below are the logs:

TrimUtil -- > Cmd : -y -i /storage/emulated/0/abc.mp4 -ss 88 -t 91 -async 1 -c copy /storage/emulated/0/video_trimmed.mp4
 D/FFmpeg: Build.CPU_ABI : arm64-v8a
D/FFmpeg: ffmpeg is ready!
TrimUtil -- > FFMPEG isSupported
TrimUtil -- > FFMPEG onStart

D/FFmpeg: Running publishing updates method
TrimUtil -- > FFMPEG progress:ffmpeg version n3.4.2-9-ga877ab7 Copyright (c) 2000-2018 the FFmpeg developers
TrimUtil -- > FFMPEG progress:  built with gcc 4.9.x (GCC) 20150123 (prerelease)
TrimUtil -- > FFMPEG progress:  configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-fontconfig --enable-libass --enable-libvpx --enable-ffprobe --enable-yasm --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --pkg-config=/root/bravobit/ffmpeg-android/ffmpeg-pkg-config --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags= --extra-libs='-lpng -lx264 -lexpat -lm -logg'
TrimUtil -- > FFMPEG progress:  libavutil      55. 78.100 / 55. 78.100
TrimUtil -- > FFMPEG progress:  libavcodec     57.107.100 / 57.107.100
TrimUtil -- > FFMPEG progress:  libavformat    57. 83.100 / 57. 83.100
TrimUtil -- > FFMPEG progress:  libavdevice    57. 10.100 / 57. 10.100
TrimUtil -- > FFMPEG progress:  libavfilter     6.107.100 /  6.107.100
TrimUtil -- > FFMPEG progress:  libavresample   3.  7.  0 /  3.  7.  0
TrimUtil -- > FFMPEG progress:  libswscale      4.  8.100 /  4.  8.100
TrimUtil -- > FFMPEG progress:  libswresample   2.  9.100 /  2.  9.100
TrimUtil -- > FFMPEG progress:  libpostproc    54.  7.100 / 54.  7.100
TrimUtil -- > FFMPEG progress:Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/abc.mp4':
TrimUtil -- > FFMPEG progress:  Metadata:
TrimUtil -- > FFMPEG progress:    major_brand     : isom
TrimUtil -- > FFMPEG progress:    minor_version   : 512
TrimUtil -- > FFMPEG progress:    compatible_brands: isomiso2avc1mp41
TrimUtil -- > FFMPEG progress:    creation_time   : 1970-01-01T00:00:00.000000Z
TrimUtil -- > FFMPEG progress:    encoder         : Lavf53.24.2
TrimUtil -- > FFMPEG progress:  Duration: 00:02:50.86, start: 0.000000, bitrate: 1474 kb/s
TrimUtil -- > FFMPEG progress:    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
TrimUtil -- > FFMPEG progress:    Metadata:
TrimUtil -- > FFMPEG progress:      creation_time   : 1970-01-01T00:00:00.000000Z
TrimUtil -- > FFMPEG progress:      handler_name    : VideoHandler
TrimUtil -- > FFMPEG progress:    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
TrimUtil -- > FFMPEG progress:    Metadata:
TrimUtil -- > FFMPEG progress:      creation_time   : 1970-01-01T00:00:00.000000Z
TrimUtil -- > FFMPEG progress:      handler_name    : SoundHandler
TrimUtil -- > FFMPEG progress:Output #0, mp4, to '/storage/emulated/0/video_trimmed.mp4':
TrimUtil -- > FFMPEG progress:  Metadata:
TrimUtil -- > FFMPEG progress:    major_brand     : isom
TrimUtil -- > FFMPEG progress:    minor_version   : 512
TrimUtil -- > FFMPEG progress:    compatible_brands: isomiso2avc1mp41
TrimUtil -- > FFMPEG progress:    encoder         : Lavf57.83.100
TrimUtil -- > FFMPEG progress:    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
TrimUtil -- > FFMPEG progress:    Metadata:
TrimUtil -- > FFMPEG progress:      creation_time   : 1970-01-01T00:00:00.000000Z
TrimUtil -- > FFMPEG progress:      handler_name    : VideoHandler
TrimUtil -- > FFMPEG progress:    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
TrimUtil -- > FFMPEG progress:    Metadata:
TrimUtil -- > FFMPEG progress:      creation_time   : 1970-01-01T00:00:00.000000Z
TrimUtil -- > FFMPEG progress:      handler_name    : SoundHandler
TrimUtil -- > FFMPEG progress:Stream mapping:
TrimUtil -- > FFMPEG progress:  Stream #0:0 -> #0:0 (copy)
TrimUtil -- > FFMPEG progress:  Stream #0:1 -> #0:1 (copy)
TrimUtil -- > FFMPEG progress:Press [q] to stop, [?] for help
TrimUtil -- > FFMPEG progress:frame= 1978 fps=0.0 q=-1.0 size=   14592kB time=00:01:20.25 bitrate=1489.5kbits/s speed= 161x    
TrimUtil -- > FFMPEG progress:frame= 2042 fps=0.0 q=-1.0 Lsize=   15212kB time=00:01:22.83 bitrate=1504.3kbits/s speed= 161x    
TrimUtil -- > FFMPEG progress:video:11277kB audio:3888kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.306889%
TrimUtil -- > FFMPEG onSuccess:ffmpeg version n3.4.2-9-ga877ab7 Copyright (c) 2000-2018 the FFmpeg developers
      built with gcc 4.9.x (GCC) 20150123 (prerelease)
      configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-fontconfig --enable-libass --enable-libvpx --enable-ffprobe --enable-yasm --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --pkg-config=/root/bravobit/ffmpeg-android/ffmpeg-pkg-config --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags= --extra-libs='-lpng -lx264 -lexpat -lm -logg'
      libavutil      55. 78.100 / 55. 78.100
      libavcodec     57.107.100 / 57.107.100
      libavformat    57. 83.100 / 57. 83.100
      libavdevice    57. 10.100 / 57. 10.100
      libavfilter     6.107.100 /  6.107.100
      libavresample   3.  7.  0 /  3.  7.  0
      libswscale      4.  8.100 /  4.  8.100
      libswresample   2.  9.100 /  2.  9.100
      libpostproc    54.  7.100 / 54.  7.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/abc.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 1970-01-01T00:00:00.000000Z
        encoder         : Lavf53.24.2
      Duration: 00:02:50.86, start: 0.000000, bitrate: 1474 kb/s
        Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
        Metadata:
          creation_time   : 1970-01-01T00:00:00.000000Z
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
        Metadata:
          creation_time   : 1970-01-01T00:00:00.000000Z
          handler_name    : SoundHandler
    Output #0, mp4, to '/storage/emulated/0/video_trimmed.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf57.83.100
        Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
        Metadata:
          creation_time   : 1970-01-01T00:00:00.000000Z
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
05-28 18:20:07.584 3488-3488/com.example.ritesh.exoplayertrim I/System.out:     Metadata:
          creation_time   : 1970-01-01T00:00:00.000000Z
          handler_name    : SoundHandler
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    frame= 1978 fps=0.0 q=-1.0 size=   14592kB time=00:01:20.25 bitrate=1489.5kbits/s speed= 161x    
    frame= 2042 fps=0.0 q=-1.0 Lsize=   15212kB time=00:01:22.83 bitrate=1504.3kbits/s speed= 161x    
    video:11277kB audio:3888kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.306889%
TrimUtil -- > FFMPEG onFinish
Brianvdb commented 6 years ago

Your FFmpeg command is wrong. -t is the the duration in seconds and not a timestamp. Please test your command on your pc first because it seems like this is not an issue related with this library.

ritesh94 commented 6 years ago

@Brianvdb

When I use the command to trim video to 15sec (88+15 = 103 sec) it works well.

-y -i /storage/emulated/0/abc.mp4 -ss 88 -t 103 -async 1 -c copy /storage/emulated/0/video_trimmed.mp4

How should I achieve 3 seconds video trim ?

Brianvdb commented 6 years ago

-t 3

ritesh94 commented 6 years ago

@Brianvdb

If I use -t 3 The video trims to 3secs but I get a black video output

Brianvdb commented 6 years ago

ffmpeg -i input.mp4 -ss 20 -t 3 output.mp4

This command works fine for me. Where 20 is the starttime in seconds.

ritesh94 commented 6 years ago

@Brianvdb Dont know how, but now it worked using same command with -t 3 -y -i /storage/emulated/0/abc.mp4 -ss 88 -t 3 -async 1 -c copy /storage/emulated/0/video_trimmed.mp4

Just to confirm, -t will have the duration (in seconds) that we want to trim from startTime, correct? (Eg: 15 for 15secs trim from startTime)

Brianvdb commented 6 years ago

@ritesh94 Yes

ritesh94 commented 6 years ago

ok Thanks @Brianvdb . Great library and great work as well :+1:

daithinh2401 commented 3 years ago

Hi guys, I've using this command for trimming video:

ffmpeg -y -i movie.mp4 -ss 00:00:00.400 -to 00:00:47 -preset ultrafast -c:v copy -c:a copy cut.mp4

But the result always have the duration 46s, that mean it always cut 1s instead of 400ms as the params above. It also cut 2s if I use -ss 00:00:01.200, seem it can only cut by seconds instead of milliseconds

Can you guys please help me in this case.