question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trimming video: incorrect duration

See original GitHub issue

@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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ritesh94commented, May 28, 2018

ok Thanks @Brianvdb . Great library and great work as well 👍

0reactions
daithinh2401commented, Jul 18, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ffmpeg: cut video but getting the wrong length - Stack Overflow
In my case, I don't use -c copy but still get a wrong duration. After an investigation, I found that it caused by...
Read more >
Cutting videos with ffmpeg : length not accurate - Super User
I have used the @Rajib guide to construct a query that works perfectly with trimming a video with precise duration/length
Read more >
MP4 file has incorrect length (duration) and plays back 5x ...
8 hour class duration. I am importing them into Camtasia to trim some parts from them and then exporting them back out.
Read more >
Incorrect time duration of video file - Microsoft Community
I copied a VHS home video to a DVD via a dedicated device. I then copied the VOB files off the DVD onto...
Read more >
YouTube Video Editor shows incorrect duration
YouTube Video Editor shows incorrect duration. I want to trim a video I just live streamed on Windows 10 PC running Chrome: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found