FFmpeg Target
  • 05 Sep 2024
  • 3 Minutes to read
  • Dark
    Light
  • PDF

FFmpeg Target

  • Dark
    Light
  • PDF

Article summary

The FFmpeg Target is a generic target that uses FFmpeg to send audio/video to different destinations.
On start, the FFmpeg Target will spawn an external FFmpeg process that runs independently of Composer and sends raw audio and video to the FFmpeg process.
There are no limitations on how you can configure FFmpeg. However, your FFmpeg package might contain limitations that affect/limit the features available.

  • Autostart when application starts - Check this option to enable target at application launch. For autostart of targets, the Autostart target options also must be activated on the application level (See the chapter Performance panel)
  • Configuration Templates:
    • Templates - Composer comes with a couple of pre-defined examples (templates) that can be used as a baseline. Select a template from the dropdown, and press Load Template to use the template.
  • Configuration:
    • FFmpeg options - Define the options/parameters used with FFmpeg.
      The FFmpeg option section supports a few macros that you might find helpful:
      @@HOSTNAME
      @@DATE
      @@TIME

      Example usage: 
    • -movflags + empty_moov + default_base_moof + frag_keyframe + negative_cts_offsets + delay_moov -b:v 3M -g 25 -c:a aac -b:a 128k output-@@HOSTNAME-@@DATE.mp4
      
      

    • Video resolution - Setting to scale your content before sending it to FFmpeg. Scaling is performed on the GPU.
  • Process monitoring options:
    • Monitor if process becomes stale or absent - If activated, Composer will monitor the FFmpeg process, and if the process stops outputting data or if the process has been terminated, Composer will restart the process. 
    • Max idle time out - If Composer has been configured to monitor the process, this setting defines the maximum idle time. If there has been no output from FFmpeg during this time out, Composer will consider FFmpeg as stale and will restart the process.
    • Restart interval - Before Composer initializes a restart, Composer will wait a predefined number of seconds. This duration is defined in the Restart interval dropdown.
  • Commands:
    • Start - Start the FFmpeg process
    • Stop - Stop the FFmpeg process
    • Restart - Restart the FFmpeg process
  • Performance & Properties
    • Pipe data throughput - Bitrate of data being sent from Composer to FFmpeg
    • FFmpeg init message - The initial response from FFmpeg (stream information)
    • FFmpeg output message - The last output message from FFmpeg (post launch)
    • FFmpeg frame count - Last detected frame count
    • FFmpeg Process Id - Windows Process Id
    • FFmpeg location - Location from which ffmpeg was launchd (Windows only)
    • FFmpeg uptime - Uptime since start
    • FFmpeg process running - True if FFmpeg process is running (according to Composer)
    • Auto restart enabled - True if auto restart is enabled
    • Number of auto restarts - Number of auto restarts 
    • Message - Runtime message. If an error occurs in the FFmpeg process, the error will be logged by the Composer log system.
  • Debug options:
    • Log all FFmpeg messages - If activated, all output from FFmpeg will be logged by Composer. This can be useful when performing debugging.
    • Log Frame information message - Will log frame by frame information. If Log all FFmpeg messages are enabled, this option can not be enabled since it logs the same thing.
      Example log line:
      {"Timestamp":"2024-09-05T13:44:56.4094113+02:00","Level":"Information","MessageTemplate":"name= FFmpegTarget frame= 355 fps= 27 q=18.0 size= 7578kB time=00:00:14.20 bitrate=4369.3kbits/s dup=0 drop=69 speed=1.06x ","Properties":{"EventId":2058,"UtcTimestamp":"2024-09-05T11:44:56.4094113Z"}}
  • About - Information about the target.

FFmpeg path/version

On Windows, Composer will use the same file path for FFmpeg as the path used by Composer. Find more information here.

On Linux, Composer does not use a predefined file path for FFmpeg. Composer will simply try to spawn FFmpeg from the Linux system.

Data from Composer to FFmpeg

Data in Composer is sent to FFmpeg using a pipe with the following specifications:

  • Video 
    • Uncompressed YUV, AV_CODEC_ID_RAWVIDEO 4:2:0 
  • 4:2:0 is used to save bandwidth between Composer and the FFmpeg process.
    • Configurable resolution. Hardware accelerated scaler.
  • Audio: 
    • AV_CODEC_ID_AAC
  • Container format: 
    • Matroska

Examples
Below are a few examples of FFmpeg options:

MP4 File:
-movflags +empty_moov+default_base_moof+frag_keyframe+negative_cts_offsets+delay_moov -b:v 3M -g 25 -c:a aac -b:a 128k output.mp4


RTMPS:
-c:v h264_nvenc -qp:v 19 -r:v 25 -b:v 3M -g:v 25 -bf:v 0 -c:a aac -b:a 128k -f flv rtmps://your-rtmp-endpoint


SRT:
-c:v h264_nvenc -qp:v 19 -r:v 30 -b:v 3M -g:v 30 -bf:v 0 -c:a aac -b:a 128k -f mpegts srt://your-srt-endpoint";


Internals
When Composer spawns the FFmpeg, it combines a mandatory configuration with the FFmpeg options configured in the FFmpeg Target component.

-progress - -xerror -y -f matroska -i - 

This is needed for the FFmpeg Target to fetch progress and retrieve the audio and video data from Composer.

Logging

If Use extended logging (under “Performance”) is enabled, statistics about the FFmpeg target are logged.

Example:
[2023-09-12 11:53:12.239 [Information] [2055] [SystemLabel] TargetStatistics {"Name": "FFmpegTarget", "PlaybackState": "Running", "Resolution": "OutputResolution1080P", "FrameCount": "108", "VideoFramesWritten": "177", "NumberOfRestarts": "0", "UpTime": "9 seconds "}


Was this article helpful?

What's Next