Changes between Version 9 and Version 10 of Null

Jan 3, 2016, 1:53:10 AM (4 years ago)

cleanup, formatting, additions, toc


  • 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.
    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:
     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
     13= Null muxer =
     15The [ null muxer] does not generate any output file. It is mainly useful for testing or benchmarking purposes.
     17== Decoding & demuxing ==
     19To test decoding and demuxing:
    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 -
    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 ==
     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:
    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 -
    14 See also the "-benchmark" FFmpeg command line parameter which outputs some statistics when it ends:
     33== With a particular muxer ==
     35You can output to `/dev/null`, or `NUL` in Windows, if you want to choose a muxer but not actually output a file:
    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
    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 ==
     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.
    26  ffmpeg -benchmark -i INPUT   -filter_complex "[0] split [splitout1][splitout2];[splitout1]nullsink"  -map "[splitout2]" out.mp4
     46$ ffmpeg -benchmark -i input output
     48bench: utime=8.483s
     49bench: maxrss=52736000kB
    29 in the FFMpeg output it specifies (in this case)
     52*nix users can also use the `time` command.
     55$ time ffmpeg -i input output
     57real    0m3.365s
     58user    0m8.533s
     59sys     0m0.541s
     66= Filters =
     68There is a variety of null filters:
     70== anull ==
     72The [ anull] audio filter will pass the audio source unchanged to the output.
     74== null ==
     76The [ null] video filter will pass the video source unchanged to the output.
     78== anullsrc ==
     80The [ anullsrc] audio source filter can create silent audio. For example, to add a silent audio stream to a video:
     83ffmpeg -i input.mp4 -f lavfi -i anullsrc -c:v copy -c:a aac -shortest output.mp4
     86anullsrc can be particularly useful with the [ 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:
     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
     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.
     96== nullsrc ==
     98The [ 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 [ geq] filter:
     101ffmpeg -f lavfi -i nullsrc=s=256x256:d=5 -vf "geq=random(1)*255:128:128" output
     104== anullsink ==
     106The [ anullsink] audio sink with do absolutely nothing with the input audio.
     108== nullsink ==
     110The [ 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 [ filtergraph] does not "output" anything it will just re-encode the inputs and ignore the filter. Example:
     113ffmpeg -i input -filter_complex "[0:v]split[a][b];[a]nullsink" -map "[b]" output.mkv
     116In this case the `ffmpeg` output specifies:
    31119  split:output1 -> Stream #0:0 (libx264)
    33 which means the second output from the split is being encoded (the first output has effectively been sent to the  nullsink).
    35 There is also a null video input, see [ here].
     122...which means the second output from the split is being encoded and the first output has been sent to nullsink.