Unable to trim piped video stream with FFmpeg

0

Trying to trim a video file that gets piped from the standard input, it only works when the start duration is greater than 2.0s for some videos (fails for ones captured from an Android phone to be specific).

When ss is set to 2.0, i.e., ffmpeg -y -ss 00:00:02.0 -vcodec h264 -acodec aac -i pipe:0 -t 7 output_file.mp4, it fails with the output [mov,mp4,m4a,3gp,3g2,mj2 @ 0xecf920] stream 1, offset 0x65ea3: partial file pipe:0: Invalid data found when processing input.

Here is the full log:

$ cat camera_landscape.mp4 | ffmpeg -y -ss 00:00:02.0 -vcodec h264 -acodec aac -i pipe:0 -t 7 camera_landscape_test.mp4 
ffmpeg version 2.6.4 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libpulse --disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2 --enable-libvidstab --enable-libzvbi --enable-avresample --disable-htmlpages --disable-podpages --enable-libutvideo --enable-libfdk-aac --enable-libx265 --enable-libiec61883 --enable-vaapi --enable-libdc1394 --disable-altivec --shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2015-09-27 09:46:32
  Duration: 00:00:16.96, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 640x480, 5744 kb/s, SAR 1:1 DAR 4:3, 28.68 fps, 28.67 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : SoundHandle
[libx264 @ 0xee1000] using SAR=1/1
[libx264 @ 0xee1000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xee1000] profile High, level 3.0
[libx264 @ 0xee1000] 264 - core 146 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'camera_landscape_test.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 28.67 fps, 11008 tbn, 28.67 tbc (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : VideoHandle
      encoder         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 48000 Hz, mono, s16, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : SoundHandle
      encoder         : Lavc56.26.100 libfaac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (libfaac))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xecf920] stream 1, offset 0x65ea3: partial file
pipe:0: Invalid data found when processing input
frame=    0 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Anything greater than 2.0 succeeds, as such:

$ cat camera_landscape.mp4 | ffmpeg -y -ss 00:00:02.1 -vcodec h264 -acodec aac -i pipe:0 -t 7 camera_landscape_test.mp4 
ffmpeg version 2.6.4 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libpulse --disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2 --enable-libvidstab --enable-libzvbi --enable-avresample --disable-htmlpages --disable-podpages --enable-libutvideo --enable-libfdk-aac --enable-libx265 --enable-libiec61883 --enable-vaapi --enable-libdc1394 --disable-altivec --shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2015-09-27 09:46:32
  Duration: 00:00:16.96, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 640x480, 5744 kb/s, SAR 1:1 DAR 4:3, 28.68 fps, 28.67 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : SoundHandle
[libx264 @ 0xbe5000] using SAR=1/1
[libx264 @ 0xbe5000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xbe5000] profile High, level 3.0
[libx264 @ 0xbe5000] 264 - core 146 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'camera_landscape_test.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 28.67 fps, 11008 tbn, 28.67 tbc (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : VideoHandle
      encoder         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 48000 Hz, mono, s16, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-09-27 09:46:32
      handler_name    : SoundHandle
      encoder         : Lavc56.26.100 libfaac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (libfaac))
frame=  201 fps= 70 q=-1.0 Lsize=     543kB time=00:00:07.01 bitrate= 634.0kbits/s dup=1 drop=0    
video:465kB audio:71kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.238381%
[libx264 @ 0xbe5000] frame I:1     Avg QP:21.12  size:  5005
[libx264 @ 0xbe5000] frame P:200   Avg QP:22.80  size:  2354
[libx264 @ 0xbe5000] mb I  I16..4: 17.2% 82.0%  0.8%
[libx264 @ 0xbe5000] mb P  I16..4:  5.2%  9.7%  0.0%  P16..4: 53.7%  3.0%  3.4%  0.0%  0.0%    skip:25.0%
[libx264 @ 0xbe5000] 8x8 transform intra:65.7% inter:97.4%
[libx264 @ 0xbe5000] coded y,uvDC,uvAC intra: 27.7% 59.6% 0.0% inter: 20.1% 49.5% 0.0%
[libx264 @ 0xbe5000] i16 v,h,dc,p: 21% 31% 24% 24%
[libx264 @ 0xbe5000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 14% 58%  3%  3%  3%  3%  2%  2%
[libx264 @ 0xbe5000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14%  6% 66%  4%  3%  3%  3%  1%  1%
[libx264 @ 0xbe5000] i8c dc,h,v,p: 62% 21% 16%  1%
[libx264 @ 0xbe5000] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0xbe5000] ref P L0: 38.2%  4.0% 33.1% 24.8%
[libx264 @ 0xbe5000] kb/s:542.91

Everything works fine if the input gets referenced as a file (i directly), but piping is mandatory. As a test, a Youtube file was also tested resulting in success. The question here is, why this operation fails for this certain video and how to solve it.

Edit: Temporary video link - http://tempsend.com/8F6F119BCA

razzledazzle

Posted 2015-09-28T09:26:57.550

Reputation: 101

You are trying to seek second second of video, but video duration is less than 2 seconds, what do you expect? – ptQa – 2015-09-28T11:18:42.637

What do you mean? Duration: 00:00:16.96, the actual duration is right there and its beyond 2 seconds. – razzledazzle – 2015-09-28T16:45:21.050

Please provide a sample file. – llogan – 2015-09-28T16:59:37.080

Certainly, will upload that very file. – razzledazzle – 2015-09-28T17:00:38.583

http://tempsend.com/8F6F119BCA, temporary link to the file, will add a persistent link later. @LordNeckbeard please check, its a 12 MB video. – razzledazzle – 2015-09-28T17:29:09.517

No answers