Custom FFmpeg Commands in WriteGear API¶
WriteGear API now provides the execute_ffmpeg_cmd
Method in Compression Mode that enables the user to pass any custom FFmpeg CLI (Command Line Interface) commands as input to its internal FFmpeg Pipeline by formating it as a list.
This opens endless possibilities of exploiting every FFmpeg params within WriteGear without relying on a third-party API to do the same and while doing that it robustly handles all errors/warnings quietly.
Important Information
-
This Feature Requires WriteGear's Compression Mode enabled(
compression_mode = True
). Follow these dedicated Installation Instructions ➶ for its installation. -
Only python list is a valid datatype as input for this function, any other value will throw
ValueError
. -
Kindly read FFmpeg Docs carefully, before passing any values to
output_param
dictionary parameter. Wrong values may result in undesired Errors or no output at all.
Features¶
-
Provides the ability to pass any custom command to WriteGear FFmpeg Pipeline.
-
Compatible with any FFmpeg terminal command.
-
Standalone On-the-fly functioning.
-
Can work without interfering with WriteGear API's Writer pipeline.
-
Minimum hassle and extremely easy to enable and use.
Methods¶
execute_ffmpeg_cmd
¶
This method allows the users to pass the custom FFmpeg terminal commands as a formatted list directly to WriteGear API's FFmpeg pipeline for processing/execution. Its usage is as follows:
# format FFmpeg terminal command `ffmpeg -y -i source_video -acodec copy input_audio.aac` as a list
ffmpeg_command = ["-y", "-i", source_video, "-acodec", "copy", "input_audio.aac"]
# execute this list using this function
execute_ffmpeg_cmd(ffmpeg_command)
Usage Examples¶
Following usage examples is just an idea of what can be done with this powerful function. So just Tinker with various FFmpeg parameters/commands yourself and see it working. Also, if you're unable to run any terminal FFmpeg command, then report an issue.
Using WriteGear to separate Audio from Video¶
In this example, we will extract and save audio from a URL stream:
After running this script, You will get the final 'output_audio.aac'
audio file.
Using WriteGear to merge Audio with Video¶
In this example, we will merge audio with video:
You can also directly add external audio input to video-frames in WriteGear. For more information, See this FAQ example ➶
Example Assumptions
-
You already have a separate video(i.e
'input-video.mp4'
) and audio(i.e'input-audio.aac'
) files. -
Both these Audio and Video files are compatible.
After running this script, You will get the final 'Output_with_audio.mp4'
file with both video and audio merged.