Post-Processing videos
This guide explains how to use FFmpeg and OBS Studio to automate the post-processing of recorded videos. It covers trimming, editing, adding titles, improving audio quality, and exporting videos for platforms like YouTube. Basic familiarity with FFmpeg and OBS Studio is assumed.
Step 1: Setting Up Your Environment
Before diving into the process, ensure you have the necessary tools installed:
-
FFmpeg:
Download and install FFmpeg from https://ffmpeg.org.
Make sure it’s added to your system’s PATH so you can run it from the command line.
-
OBS Studio:
Download and install OBS Studio from https://obsproject.com.
-
Kdenlive:
-
Download and install Kdenlive from https://kdenlive.org.
Windows: Use the installer from the official website.
Linux: Install via your distribution’s package manager (e.g.,
sudo apt install kdenlive
on Ubuntu/Debian).macOS: Use Homebrew (
brew install kdenlive
) or download the DMG file from the website.
-
Step 2: Recording Your Video with OBS
-
Configure OBS for Recording:
Open OBS Studio and set up your scenes and sources (e.g., webcam, screen capture, etc.).
Go to Settings > Output and configure the recording format. Use
.mp4
or.mkv
for compatibility with FFmpeg.Under Audio, ensure your microphone and desktop audio are properly configured.
-
Start Recording:
Once everything is set up, click the Start Recording button in OBS. Record your content as needed.
-
Stop Recording:
When done, click Stop Recording. The video file will be saved in the directory specified under Settings > Output > Recording Path.
Step 3: Cutting Recorded Videos with FFmpeg
Before editing in Kdenlive, trim your raw footage into manageable clips using FFmpeg. This ensures minimal quality loss by avoiding re-encoding.
Step 3.1: Identify Start and End Times
Open your raw video file in a media player (e.g., VLC).
-
Note the start time (
start_time
) and end time (end_time
) of the segment you want to keep. Example: If you want to keep a clip from00:01:15
to00:03:45
:start_time = 00:01:15
(1 minute 15 seconds)end_time = 00:03:45
(3 minutes 45 seconds)
Step 3.2: Use FFmpeg to Cut the Video
Run the following command to cut the video:
-i input.mp4
: Specifies the input video file.-ss 00:01:15
: Skips to the start time (75 seconds).-to 00:03:45
: Stops at the end time (225 seconds).-c copy
: Copies the video and audio streams without re-encoding, preserving the original quality.cut_output.mkv
: The output file name.
Step 3.3: Verify the Cut
Play the trimmed video (
cut_output.mkv
) in a media player to ensure it starts and ends where intended.
Step 4: Creating a Kdenlive Project for Mini-Videos
Use Kdenlive to assemble and enhance the trimmed video clips into short, visually appealing segments. These mini-videos can later be combined into a full presentation or used individually.
Step 4.1: Organize Your Assets
Before starting Kdenlive, ensure all your assets are ready: - Trimmed
Video Clips: Outputs from Step 3 (e.g., cut_output.mkv
). - Audio
Files: Background music, sound effects, or voiceovers. - Graphics
and Titles: Logos, overlays, or text elements for branding. -
Transitions: Pre-made transitions (if needed) or use Kdenlive’s
built-in effects.
Place all these files in a dedicated folder (e.g., kdenlive_assets
)
for easy access.
Step 4.2: Set Up the Kdenlive Project
-
Create a New Project:
Open Kdenlive and go to File > New Project.
Choose a profile that matches your video resolution and frame rate (e.g., 1080p 30fps).
-
Import Media:
Drag and drop your trimmed video clips, audio files, and graphics into the Project Bin (left panel in Kdenlive).
-
Set the Timeline Layout:
-
Use multiple tracks for better organization:
Track 1: Main video clips.
Track 2: Titles, overlays, or graphics.
Track 3: Background music or sound effects.
Track 4: Transitions or additional effects.
-
Step 4.3: Assemble the Mini-Videos
-
Add Video Clips to the Timeline:
Drag your trimmed video clips onto Track 1 and arrange them in the desired order.
-
Add Titles and Text:
Go to the Titles and Text section in the toolbar.
Create eye-catching titles for each mini-video. Use bold fonts, animations, and colors that match your branding. Place the titles on Track 2 above the video clips.
-
Incorporate Graphics and Overlays:
Add logos, lower-thirds, or decorative overlays to enhance the visuals. Use keyframes to animate these elements for a dynamic effect.
-
Add Background Music:
Drag a background music file onto Track 3. Adjust the volume using Volume Keyframes to ensure it doesn’t overpower the main audio (e.g., voiceover or dialogue).
-
Apply Transitions:
Use Kdenlive’s built-in transitions (e.g., fade, slide, or dissolve) between clips for smooth visual flow. Alternatively, import custom transitions if you have them.
-
Enhance Audio:
-
Use the Audio Effects tab to improve clarity:
Add compression for consistent volume levels.
Apply equalization (EQ) to enhance specific frequencies.
If needed, record a voiceover using Kdenlive’s Record Monitor feature.
-
Step 5: Analyze the Cut Output with ffprobe
Before creating a custom render profile in Kdenlive, analyze the
properties of the trimmed video (cut_output.mkv
) using ffprobe
.
Step 5.1: Run ffprobe
on cut_output.mkv
Open your terminal or command prompt and run:
This will display detailed information about the video file, including:
- Video codec: Check if it’s already H.264 (libx264
). - Resolution:
Note the width and height (e.g., 1920x1080). - Frame rate: Verify the
frame rate (e.g., 30 fps). - Audio codec: Check if it’s AAC or another
codec.
For more granular details, use:
Step 6: Adding a Custom Render Profile in Kdenlive
Option 1: Add the Profile in Kdenlive
Open Kdenlive and go to Settings > Configure Kdenlive > Environment > FFmpeg Export Settings [[1]].
-
Add a new custom profile with the following details:
Profile Name:
OBS Export
-
Parameters:
Extension:
.mkv
Save the profile.
Explanation of Parameters
Uses MLT 7.4:
Container Format
f=matroska
: Specifies the Matroska container format.
Video Encoding
vcodec=libx264
: Uses the H.264 codec.preset=medium
: Sets the encoding speed/quality tradeoff.profile=high
: Specifies the High Profile for H.264.crf=23
: Sets the Constant Rate Factor (CRF).pix_fmt=yuv420p
: Specifies the pixel format.r=30
: Sets the frame rate to 30 fps.vf="scale=trunc(iw/2)*2:trunc(ih/2)*2,setdar=16/9"
: Resizes the video and sets the aspect ratio.
Audio Encoding
acodec=aac
: Uses the AAC codec.ab=128k
: Sets the audio bitrate to 128 kbps.ar=48000
: Sets the audio sample rate to 48 kHz.ac=2
: Configures the audio to be stereo (2 channels).
Option 2: Create an MLT XML Profile
Locate Kdenlive’s Profiles Directory
Kdenlive stores its rendering profiles in a specific directory:
Linux:
~/.local/share/kdenlive/renderprofiles/
Windows:
C:\Users\<YourUsername>\AppData\Local\kdenlive\renderprofiles\
macOS:
~/Library/Application Support/kdenlive/renderprofiles/
Navigate to this directory.
Create the Custom Render Profile
Open a text editor (e.g., Notepad, VS Code).
Paste the following XML code into the editor:
<?xml version="1.0"?> <profile> <name>OBS Export</name> <description>Custom profile for OBS-compatible video export</description> <extension>mkv</extension> <parameters> f=matroska vcodec=libx264 preset=medium profile:v=high crf=23 pix_fmt=yuv420p r=30 vf=scale=trunc(iw/2)*2:trunc(ih/2)*2,setdar=16/9 acodec=aac ab=128k ar=48000 ac=2 </parameters> </profile>
Save the file as
obs_export.xml
in therenderprofiles
directory.
Verify the Profile
Restart Kdenlive if it’s already open.
Go to File > Render. In the Rendering Profile dropdown, you should now see “OBS Export” listed.
Step 7: Use the “OBS Export” Profile
Render the trimmed video using the new profile.
Open the trimmed video (
cut_output.mkv
) in Kdenlive.Go to File > Render.
Choose the “OBS Export” profile from the dropdown.
Specify the output file name and location (e.g.,
final_output.mkv
).Click Render to export the video.
Step 8: Test the Final Output
After rendering, test the final video to ensure it meets your requirements.
Step 8.1: Run ffprobe
Check: - Container: Should be Matroska (mkv
). - Video codec: Should
be H.264 (libx264
). - Resolution and aspect ratio: Should match the
scaling filter (16:9). - Audio codec: Should be AAC with stereo
channels.
Step 8.2: Play the Video
Test the video in a media player like VLC to confirm smooth playback, proper audio sync, and correct resolution.
Step 9: Concatenating Videos Using FFmpeg
Combine the mini-presentation video (created in Kdenlive) and the
trimmed video (cut_output.mkv
) into a single MKV file.
Step 9.1: Prepare the Files
Ensure both videos have the same resolution, frame rate, and codec settings.
Step 9.2: Create a Text File to List the Files
Create a text file (concat_list.txt
) with the following format:
file 'mini_presentation.mkv' file 'cut_output.mkv'
Step 9.3: Run the Concatenation Command
Step 9.4: Verify the Concatenated Video
Test the final video using ffprobe
and a media player.
Step 10: Adjusting Volume After the Mini-Presentation
Use FFmpeg to increase the volume of the second part of the concatenated video.
Step 10.1: Probe the Length of the Mini-Presentation Video
To determine the duration of the mini-presentation video
(mini_presentation.mkv
), use ffprobe
. The output will provide
the exact length of the video in seconds.
Run the following command in your terminal or command prompt:
-i mini_presentation.mkv
: Specifies the input file.-show_entries format=duration
: Extracts the duration of the video.-v quiet
: Suppresses unnecessary logging.-of csv="p=0"
: Outputs only the duration value.
Example Output: If the mini-presentation video is 17.5 seconds long, the output will be:
17.500000
This value (e.g., 17.5
) represents the duration of the
mini-presentation video in seconds. You’ll use this value in the next
step to adjust the audio volume.
Step 10.2: Use the Duration in the FFmpeg Command
The duration of the mini-presentation video determines where the volume
adjustment begins. Specifically, the start
parameter in the FFmpeg
command should match the duration of the mini-presentation video.
Here’s the updated FFmpeg command with placeholders for clarity:
ffmpeg -i final_concatenated.mkv -filter_complex \ "[0:a]atrim=end=<DURATION>,asetpts=PTS-STARTPTS[a_before]; \ [0:a]atrim=start=<DURATION>,asetpts=PTS-STARTPTS,volume=3.0[a_trimmed]; \ [a_before][a_trimmed]concat=n=2:v=0:a=1[aout]" \ -map 0:v -map "[aout]" -c:v copy output_with_adjusted_volume.mkv
Replace <DURATION>
with the actual duration of the mini-presentation
video (e.g., 17.5
).
Example Command:
If the mini-presentation video is 17.5 seconds long, the command becomes:
ffmpeg -i final_concatenated.mkv -filter_complex \ "[0:a]atrim=end=17.5,asetpts=PTS-STARTPTS[a_before]; \ [0:a]atrim=start=17.5,asetpts=PTS-STARTPTS,volume=3.0[a_trimmed]; \ [a_before][a_trimmed]concat=n=2:v=0:a=1[aout]" \ -map 0:v -map "[aout]" -c:v copy output_with_adjusted_volume.mkv
end=17.5
: Specifies the end time for the first audio segment (the mini-presentation part).start=17.5
: Specifies the start time for the second audio segment (the part after the mini-presentation).volume=3.0
: Increases the volume of the second audio segment by a factor of 3.0.
Step 10.3: Verify the Final Output
After running the command, test the resulting video
(output_with_adjusted_volume.mkv
) to ensure the audio transitions
smoothly and the volume adjustment starts at the correct point.
-
Play the Video: Use a media player like VLC to confirm:
The audio remains unchanged during the mini-presentation (first 17.5 seconds).
The audio volume increases after the mini-presentation ends.
Check Audio Sync: Ensure the audio is properly synchronized with the video throughout the entire duration.
Summary Here’s what we’ve accomplished in this step:
Used
ffprobe
to determine the duration of the mini-presentation video (e.g.,17.5
seconds).-
Updated the FFmpeg command to split the audio into two parts:
The first part (up to 17.5 seconds) remains unchanged.
The second part (after 17.5 seconds) has its volume increased.
Verified the final output to ensure smooth transitions and balanced audio levels.
The resulting file, output_with_adjusted_volume.mkv
, now has
consistent audio levels and is ready for further processing or
publishing.
Key Notes
The duration of the mini-presentation video is critical for ensuring the volume adjustment starts at the correct point.
Always verify the duration using
ffprobe
to avoid manual errors.Adjust the
volume
parameter (e.g.,3.0
) as needed to achieve the desired audio level.
Step 10.2: Play the Video
Test the video in a media player to confirm smooth transitions and balanced audio levels.
Step 11: Re-encode for YouTube Upload
Transcode the final video into a YouTube-compatible format.
Step 11.1: Run the Command
Step 11.2: Verify the Output
Test the video in a media player and upload it to YouTube.
Summary
This guide covered:
Setting up FFmpeg, OBS Studio and Kdenlive.
Recording and trimming videos.
Editing in Kdenlive.
Creating a custom render profile.
Concatenating videos and adjusting audio.
Re-encoding for YouTube upload.
The resulting file (output_youtube.mp4
) is now ready for publishing!
😊