Changes between Version 9 and Version 10 of Null


Ignore:
Timestamp:
Jan 3, 2016, 1:53:10 AM (4 years ago)
Author:
llogan
Comment:

cleanup, formatting, additions, toc

Legend:

Unmodified
Added
Removed
Modified
  • Null

    v9 v10  
    1 There are several ways to "output to null" in FFmpeg (like a null sink).  This can be helpful for benchmarking purposes, for instance testing encoding speeds (without having to worry about the cost of disk writes) or testing speed of input from a device, etc.
     1[[PageOutline]]
    22
    3 There is the null muxer, use it like this:
     3There are several ways to utilize "null" in `ffmpeg`.  This can be useful for testing and benchmarking purposes, creating inputs, and filtering. For example:
     4
     5* testing decoding speed
     6* testing encoding speed without the cost of disk writes
     7* testing speed of input from a device
     8* creating a blank video "canvas" for filtering
     9* making silent audio
     10
     11----
     12
     13= Null muxer =
     14
     15The [https://ffmpeg.org/ffmpeg-formats.html#null null muxer] does not generate any output file. It is mainly useful for testing or benchmarking purposes.
     16
     17== Decoding & demuxing ==
     18
     19To test decoding and demuxing:
     20
    421{{{
    5    ffmpeg -i INPUT -f null out.null # file out.null will not be created, decoding will occur, no encoding will occur
     22ffmpeg -i input -f null -
    623}}}
    724
    8 or just output to /dev/null (or the reserved filename NUL in windows) for your file to just disappear, if you want to perform encoding but not create a file
     25== Encoding ==
     26
     27It can also be used to test encoding without the overhead of outputting a file. This example will map the first video stream, encode with libx264, then discard the output:
    928
    1029{{{
    11    ffmpeg -i INPUT -f mpeg4 -f mp4 -y /dev/null # no file is created, encoding and placing in container occur
     30ffmpeg -i input -map 0:v:0 -c:v libx264 -f null -
    1231}}}
    1332
    14 See also the "-benchmark" FFmpeg command line parameter which outputs some statistics when it ends:
     33== With a particular muxer ==
     34
     35You can output to `/dev/null`, or `NUL` in Windows, if you want to choose a muxer but not actually output a file:
    1536
    1637{{{
    17   ffmpeg -benchmark -i input output
    18 ...
    19 bench: utime=53.670s
    20 bench: maxrss=145227776kB
     38ffmpeg -y -i input -c:v mpeg4 -f mp4 /dev/null
    2139}}}
    2240
    23 There is also a "nullsink" (null video sink) however, in order to have it work you have to be careful, because by default FFmpeg is "greedy" and will grab whatever stream it can find, so if your filter_complex output doesn't "output" anything, it will just re-encode the inputs and ignore the filter, etc.   Here is an example of its use:
     41== `-benchmark` option ==
     42
     43Adding the `-benchmark` global option will output benchmarking information at the end of an encode which can be informative with the null muxer. Shows CPU time used and maximum memory consumption. Maximum memory consumption is not supported on all systems; it will usually display as 0 if not supported.
    2444
    2545{{{
    26  ffmpeg -benchmark -i INPUT   -filter_complex "[0] split [splitout1][splitout2];[splitout1]nullsink"  -map "[splitout2]" out.mp4
     46$ ffmpeg -benchmark -i input output
     47...
     48bench: utime=8.483s
     49bench: maxrss=52736000kB
    2750}}}
    2851
    29 in the FFMpeg output it specifies (in this case)
     52*nix users can also use the `time` command.
     53
     54{{{
     55$ time ffmpeg -i input output
     56...
     57real    0m3.365s
     58user    0m8.533s
     59sys     0m0.541s
     60}}}
     61
     62
     63----
     64
     65
     66= Filters =
     67
     68There is a variety of null filters:
     69
     70== anull ==
     71
     72The [https://ffmpeg.org/ffmpeg-filters.html#anull anull] audio filter will pass the audio source unchanged to the output.
     73
     74== null ==
     75
     76The [https://ffmpeg.org/ffmpeg-filters.html#null null] video filter will pass the video source unchanged to the output.
     77
     78== anullsrc ==
     79
     80The [https://ffmpeg.org/ffmpeg-filters.html#anullsrc anullsrc] audio source filter can create silent audio. For example, to add a silent audio stream to a video:
     81
     82{{{
     83ffmpeg -i input.mp4 -f lavfi -i anullsrc -c:v copy -c:a aac -shortest output.mp4
     84}}}
     85
     86anullsrc can be particularly useful with the [https://ffmpeg.org/ffmpeg-filters.html#concat concat filter] because all inputs to the filter must have the same number of streams. Example where `input0` and `input1` have video and stereo audio with 48000 Hz sample rate, and `input2` has video only:
     87
     88{{{
     89ffmpeg -i input0 -i input1 -i input2 -t 1 -f lavfi -i anullsrc=r=48000:cl=stereo -filter_complex \
     90"[0:v][0:a][1:v][1:a][2:v][3:a]concat=n=3:v=1:a=1[v][a]" \
     91-map "[v]" -map "[a]" output
     92}}}
     93
     94Note the `-t 1` input option: you do not need to match this duration value with the associated video stream. It only needs to be shorter as the concat filter will pad the remaining duration with additional silence.
     95
     96== nullsrc ==
     97
     98The [https://ffmpeg.org/ffmpeg-filters.html#nullsrc nullsrc] video source filter returns unprocessed video frames. It can be used as a foundation for other filters where the input is ignored. Example to generate noise in the luminance plane with the [https://ffmpeg.org/ffmpeg-filters.html#geq geq] filter:
     99
     100{{{
     101ffmpeg -f lavfi -i nullsrc=s=256x256:d=5 -vf "geq=random(1)*255:128:128" output
     102}}}
     103
     104== anullsink ==
     105
     106The [https://ffmpeg.org/ffmpeg-filters.html#anullsink anullsink] audio sink with do absolutely nothing with the input audio.
     107
     108== nullsink ==
     109
     110The [https://ffmpeg.org/ffmpeg-filters.html#nullsink nullsink] video sink will do absolutely nothing with the input video. `ffmpeg` is "greedy" and will grab whatever stream it can find, so if your [https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-syntax filtergraph] does not "output" anything it will just re-encode the inputs and ignore the filter. Example:
     111
     112{{{
     113ffmpeg -i input -filter_complex "[0:v]split[a][b];[a]nullsink" -map "[b]" output.mkv
     114}}}
     115
     116In this case the `ffmpeg` output specifies:
     117
    30118{{{
    31119  split:output1 -> Stream #0:0 (libx264)
    32120}}}
    33 which means the second output from the split is being encoded (the first output has effectively been sent to the  nullsink).
    34121
    35 There is also a null video input, see [http://stackoverflow.com/a/15795112/32453 here].
     122...which means the second output from the split is being encoded and the first output has been sent to nullsink.