Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG doesn't work with mp4 and stdout

Tags:

ffmpeg

I need to add text to mp4 video. If I write result to file then everything is OK, but I want to read data from ffmpeg stream.

I run command:

ffmpeg -i sample.mp4 -filter_complex "drawtext='text=\"Sample Text\"':x=(w-text_w)/2:y=(h-text_h-line_h)/2:fontsize=40:fontcolor=white:fontfile=TimesNewRoman.ttf:enable='between(t,1,5)'"  -f mp4 -

I received the following error:

ffmpeg version 2.2.2-tessus Copyright (c) 2000-2014 the FFmpeg developers
  built on May  7 2014 23:17:42 with clang version 3.3 (tags/RELEASE_33/final)
  configuration: --cc=/opt/local/bin/clang-mp-3.3 --prefix=/Users/tessus/data/ext/ffmpeg/sw --as=yasm --extra-version=tessus --disable-shared --enable-static --disable-ffplay --enable-gpl --enable-pthreads --enable-postproc --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx --enable-libgsm --enable-libopus --enable-libmodplug --enable-fontconfig --enable-libfreetype --enable-libass --enable-libbluray --enable-filters --disable-indev=qtkit --enable-runtime-cpudetect
  libavutil      52. 66.100 / 52. 66.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  2.100 /  4.  2.100
  libswscale      2.  5.102 /  2.  5.102
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a5732-480x320-clip01-sound.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: M4V mp42isom
creation_time   : 2014-02-12 02:23:02
  Duration: 00:00:15.10, start: 0.000000, bitrate: 509 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv), 480x320 [SAR 1:1 DAR 3:2], 457 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
  creation_time   : 2014-02-12 02:23:02
  handler_name    : Mainconcept MP4 Video Media Handler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 32000 Hz, stereo, fltp, 46 kb/s (default)
Metadata:
  creation_time   : 2014-02-12 02:23:02
  handler_name    : Mainconcept MP4 Sound Media Handler
[libx264 @ 0x10400d800] using SAR=1/1
[libx264 @ 0x10400d800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x10400d800] profile High, level 2.1
[libx264 @ 0x10400d800] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=12 lookahead_threads=2 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
[mp4 @ 0x10400d200] muxer does not support non seekable output
Output #0, mp4, to 'pipe:':
  Metadata:
major_brand     : M4V 
minor_version   : 1
compatible_brands: M4V mp42isom
encoder         : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 480x320 [SAR 1:1 DAR 3:2], q=-1--1, 90k tbn, 29.97 tbc (default)
Stream #0:1(eng): Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 32000 Hz, stereo, s16, 128 kb/s (default)
Metadata:
  creation_time   : 2014-02-12 02:23:02
  handler_name    : Mainconcept MP4 Sound Media Handler
Stream mapping:
  Stream #0:0 (h264) -> drawtext (graph 0)
  drawtext (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (aac -> libvo_aacenc)
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Conversion failed!

It seems the problem is related to mp4 and "muxer does not support non seekable output"

Is there a solution how to make such text adding on the fly and return video as we have data and not to wait until all file is processed.

Thanks

like image 379
Max Grigoriev Avatar asked Aug 20 '14 18:08

Max Grigoriev


2 Answers

You can't use MP4 with STDOUT. The MP4 container requires the encoder to go back and make changes to the beginning of the file after it is done writing through the end. Since STDOUT cannot seek, outputting media in an MP4 container is not possible with STDOUT.

like image 76
Brad Avatar answered Oct 31 '22 16:10

Brad


You can use the empty_moov example ffmpeg -y -framerate 0.5 -pattern_type glob -i '*.jpg' -f mp4 -movflags empty_moov - | ffprobe -

-movflags empty_moov

Write an initial moov atom directly at the start of the file, without describing any samples in it. Generally, an mdat/moov pair is written at the start of the file, as a normal MOV/MP4 file, containing only a short portion of the file. With this option set, there is no initial mdat atom, and the moov atom only describes the tracks but has a zero duration.

This option is implicitly set when writing ismv (Smooth Streaming) files. https://www.ffmpeg.org/ffmpeg-formats.html

like image 39
Daniel Kobe Avatar answered Oct 31 '22 15:10

Daniel Kobe