ShareSpark

 

Author Topic: How to use FFmpeg [Tutorial] [Cinemadrop]  (Read 2139 times)

0 Members and 1 Guest are viewing this topic.

Offline Cinemadrop

  • Topic Author
  • V.I.P.
  • Hero Member
  • *
  • Thanked: 759
  • Reputation: 84
  • Activity:
    0%
  • Join Date: Aug 2021
  • Posts: 338
  • Gender: Male
How to use FFmpeg [Tutorial] [Cinemadrop]
« on: February 26, 2022, 02:36:47 PM »
How to use FFmpeg [Tutorial] [Cinemadrop]

First of all download the FFmpeg.
You can use You are not allowed to view links. Register or Login link to download the latest stable version of FFmpeg.

After downloading you need to set path to FFmpeg
Or
Type the path in beginning of the command.


How to set path to FFmpeg

Right click on "This PC" and select "Properties"
Now click on "Advanced system settings"



Then select "Environment Variables..."



Then select "Path" row and hit "Edit"



Click on "New" button and add your downloaded ffmpeg.exe's folder path to it.



You can just copy the path from "Copy path" button.



Remove the "\ffmpeg.exe" from the path
eg : "C:\ffmpeg_folder\bin\ffmpeg.exe" --> "C:\ffmpeg_folder\bin"
This must include the folder location only.

Now you have set the path successfully.


How to use FFmpeg

Open "Command Prompt" or "PowerShell"

If you haven't set the path to FFmpeg, type the path in beginning of the command.
eg : "C:\FFmpeg 5.0\bin\ffmpeg.exe" .....

Or

If you have set the path to FFmpeg, simply type "ffmpeg" in beginning of the command.
eg : ffmpeg .....


Basics of FFmpeg

ffmpeg -i (INPUT_FILE) (OPTIONS) (OUTPUT_FILE)


-i              : Introducing the input file.
(INPUT_FILE)    : Path of the input file.
(OPTIONS)      : Set options according to your necessary.
(OUTPUT_FILE)  : Set the path to output file.
(Set the extension with a dot | eg: output.mp4 / output.mkv / output.webm....)


REMUX Videos

ffmpeg -i (INPUT_FILE) -c copy (OUTPUT_FILE)

This will copy first video track, first audio track and first subtitle track from input to output format.
eg : ffmpeg -i input_video.mkv -c copy output_video.mp4


ffmpeg -i (INPUT_FILE) -c:v copy -c:a copy -c:s copy (OUTPUT_FILE)

You can copy video/audio/subtitle track one by one from above code

ffmpeg -i (INPUT_FILE) -c:v copy -c:a copy -sn (OUTPUT_FILE)

This will remux the video without subtitle track
-sn --> Don't copy subtitle track

ffmpeg -i (INPUT_FILE) -c:v copy -an -sn (OUTPUT_FILE)

This will remux the video without audio and subtitle tracks
-an --> Don't copy audio track

ffmpeg -i (INPUT_FILE) -vn -c:a copy -sn (OUTPUT_FILE)

-vn --> Don't copy video track
eg : ffmpeg -i input_video.mp4 -vn -c:a copy -sn output_audio.m4a

Track Selecting

ffmpeg -i input.mkv -map 0 -c copy output.mkv

-map 0 --> Select all the streams available in the input file (0 means the first input)

eg : Assume you are using 3 input files and you want to add
the first stream from first input and the all audios from second input and all subtitles from third input to the output file,
below is the command,

ffmpeg -i 1.mkv -i 2.mkv -i 3.mkv -map 0:0 -map 1:a -map 2:s -c copy output.mkv

When using -map the first stream is 0, second stream is 1, third stream is 2 ......etc.

"-map" Usage



-map 0    --> Select first input
-map 0:0  --> Select first input's first stream (track)
-map 0:v  --> Select first input's all video streams (tracks)
-map 0:a  --> Select first input's all audio streams (tracks)
-map 0:s  --> Select first input's all subtitle streams (tracks)
-map 0:v:0 --> Select first input's first video stream (track)
-map 0:a:0 --> Select first input's first audio stream (track)
-map 0:s:0 --> Select first input's first subtitle stream (track)


Track Extracting

Assume you have a MKV file with following tracks


1 - H.264 | Video track
2 - AAC   | First audio track
3 - EAC3  | Second audio track
4 - SRT   | First subtitle track
5 - SRT   | Second subtitle track
6 - SRT   | Third subtitle track

Extract the video track (Any of below codes)

ffmpeg -i input_video.mkv -map 0:0 -c copy output.h264
ffmpeg -i input_video.mkv -map 0:0 -c copy output.264
ffmpeg -i input_video.mkv -map 0:0 -c copy output.avc
ffmpeg -i input_video.mkv -map 0:v:0 -c copy output.h264
ffmpeg -i input_video.mkv -map 0:v:0 -c copy output.264
ffmpeg -i input_video.mkv -map 0:v:0 -c copy output.avc


NOTE : Codec extensions


H.264 --> .h264 / .264 / .avc
H.265 --> .h265 / .265 / .hevc
VP9   --> .ivf
AV1   --> .ivf
Extract the audio track | AAC (Any of below codes)

ffmpeg -i input_video.mkv -map 0:1 -c copy output.aac
ffmpeg -i input_video.mkv -map 0:1 -c copy output.m4a
ffmpeg -i input_video.mkv -map 0:a:0 -c copy output.aac
ffmpeg -i input_video.mkv -map 0:a:0 -c copy output.m4a


Extract the audio track | EAC3 (Any of below codes)

ffmpeg -i input_video.mkv -map 0:2 -c copy output.eac3
ffmpeg -i input_video.mkv -map 0:2 -c copy output.mka
ffmpeg -i input_video.mkv -map 0:a:1 -c copy output.eac3
ffmpeg -i input_video.mkv -map 0:a:1 -c copy output.mka


NOTE : Codec extensions


AAC    --> .aac / .m4a / .mka
AC-3   --> .ac3 / .mka
EAC3   --> .eac3 / .mka
Opus   --> .opus / .ogg / .mka /.webm
FLAC   --> .flac / .ogg / .mka
WAV    --> .wav / .mka
DTS    --> .dts / .mka
TrueHD --> .thd / .mka
Extract the subtitle track as .srt (Any of below codes)

ffmpeg -i input_video.mkv -map 0:3 -c:s srt output.srt | First subtitle track
ffmpeg -i input_video.mkv -map 0:4 -c:s srt output.srt | Second subtitle track
ffmpeg -i input_video.mkv -map 0:5 -c:s srt output.srt | Third subtitle track
ffmpeg -i input_video.mkv -map 0:s:0 -c:s srt output.srt | First subtitle track
ffmpeg -i input_video.mkv -map 0:s:1 -c:s srt output.srt | Second subtitle track
ffmpeg -i input_video.mkv -map 0:s:2 -c:s srt output.srt | Third subtitle track

Track Encoding

ffmpeg -i (INPUT_FILE) -c:v (VIDEO_CODEC) -c:a (AUDIO_CODEC) -c:s (SUBTITLE_CODEC) (OUTPUT_FILE)

* If you don't want to re-encode the audio track use -c:a copy

VIDEO_CODEC


H.264 --> libx264
H.265 --> libx265
VP9   --> libvpx-vp9
AV1   --> libaom-av1
AUDIO_CODEC

AAC          --> aac
AC-3         --> ac3
EAC3         --> eac3
Opus         --> libopus
FLAC         --> flac
WAV (16bit)  --> pcm_s16le
WAV (24bit)  --> pcm_s24le
SUBTITLE_CODEC

SRT  --> srt
*NOTE : For adding subtitles to a MP4/MOV file use -c:s mov_text code.

Crop

Use -filter:v "crop=1920:816" or -vf "crop=1920:816"

eg: Assume you have a footage with 1920x1080 resolution and you want to crop it to 1920x800, you can use below code,
ffmpeg -i (INPUT_FILE) -c:v (VIDEO_CODEC) -vf "crop=1920:800" -c:a copy (OUTPUT_FILE)


Resize/Rescale

Use -filter:v scale=1920x1080 or -vf scale=1920x1080

Or

Use -filter:v scale=1920:-1 or -vf scale=1920:-1

This automatically adjust the height according to the width according to the original aspect ratio
for 1440p (2K) downscaling -vf scale=2560:-1
for 1080p downscaling -vf scale=1920:-1
for 720p downscaling -vf scale=1280:-1



Trim


Trim by timestamps

ffmpeg -i (INPUT_FILE) -ss 00:00:00 -to 00:00:00 -map 0 -c copy (OUTPUT_FILE)

-ss 00:00:00 --> Set trim start time.
-to 00:00:00 --> Set trim end time.
(Format is HH:MM:SS)


Trim by frames

ffmpeg -i (INPUT_FILE) -ss I/FPS -to I/FPS -map 0 -c copy (OUTPUT_FILE)

-ss I/FPS --> Set trim start time.
-to I/FPS --> Set trim end time.

I - Frame number
FPS - Input file's frame rate

eg : Assume you have a 25fps footage and you want to trim it from 250 frame to 3500 frame, below is the code,

ffmpeg -i (INPUT_FILE) -ss 10 -to 140 -map 0 -c copy (OUTPUT_FILE)

-ss 10 = -ss 250/25
-to 140 = -ss 3500/25








Ⓒ 2022 Cinemadrop | All rights reserved.


« Last Edit: March 02, 2022, 08:01:33 PM by Cinemadrop »

Offline 𝓢𝓣𝓔𝓝𝓒

  • Uploader
  • Senior Member
  • *
  • Thanked: 127
  • Reputation: 4
  • Activity:
    0%
  • Join Date: Aug 2020
  • Location: India 🇮🇳
  • Posts: 203
  • Gender: Male
  • Join - https://t.me/Steve_Encodes
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #1 on: February 26, 2022, 03:59:34 PM »
Excellent . . .
Waiting for your in-depth explanation update . . .
ℚ𝕦𝕒𝕝𝕚𝕥𝕪 𝕚𝕤 𝕒𝕝𝕝 𝕥𝕙𝕒𝕥 𝕞𝕒𝕥𝕥𝕖𝕣𝕤 𝕓𝕒𝕓𝕪!
Join - You are not allowed to view links. Register or Login
 
The following users thanked this post: Cinemadrop

Offline 𝐏𝐫𝐚𝐧𝐚𝐯𝐗𝐓

  • V.I.P.
  • Special Member
  • *
  • Thanked: 281
  • Reputation: 46
  • Activity:
    0%
  • Join Date: Dec 2020
  • Location: ~𝐵𝟥𝑅𝐿𝟣𝒩~
  • Age: 20
  • Posts: 699
  • Gender: Male
  • 𝕷𝖆 𝕮𝖆𝖘𝖆 𝕯𝖊 𝕻𝖆𝖕𝖊𝖑
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #2 on: February 28, 2022, 07:22:31 PM »
Iska Tutorial Bana Sakte HO Kya ? Youtuber Ban Jao
" END IS :gun: THE BEGINING & BEGINING IS THE  :hooray: END
UNKNOWN
 

Offline Cinemadrop

  • Topic Author
  • V.I.P.
  • Hero Member
  • *
  • Thanked: 759
  • Reputation: 84
  • Activity:
    0%
  • Join Date: Aug 2021
  • Posts: 338
  • Gender: Male
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #3 on: February 28, 2022, 08:38:50 PM »
You are not allowed to view links. Register or Login
Iska Tutorial Bana Sakte HO Kya ? Youtuber Ban Jao
Can anyone translate this to English please?
You mean you want a video tutorial?
 

Offline 𝐏𝐫𝐚𝐧𝐚𝐯𝐗𝐓

  • V.I.P.
  • Special Member
  • *
  • Thanked: 281
  • Reputation: 46
  • Activity:
    0%
  • Join Date: Dec 2020
  • Location: ~𝐵𝟥𝑅𝐿𝟣𝒩~
  • Age: 20
  • Posts: 699
  • Gender: Male
  • 𝕷𝖆 𝕮𝖆𝖘𝖆 𝕯𝖊 𝕻𝖆𝖕𝖊𝖑
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #4 on: March 01, 2022, 08:42:59 AM »
You are not allowed to view links. Register or Login Sorry Again  :lol: I Said Could You Plz Provide Us A Tutorial  :heart:
BTW Where R U From My Brother ? :think:
" END IS :gun: THE BEGINING & BEGINING IS THE  :hooray: END
UNKNOWN
 
The following users thanked this post: Cinemadrop

Offline Cinemadrop

  • Topic Author
  • V.I.P.
  • Hero Member
  • *
  • Thanked: 759
  • Reputation: 84
  • Activity:
    0%
  • Join Date: Aug 2021
  • Posts: 338
  • Gender: Male
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #5 on: March 01, 2022, 11:19:34 AM »
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login Sorry Again  :lol: I Said Could You Plz Provide Us A Tutorial  :heart:
BTW Where R U From My Brother ? :think:
Sure, I'll add a video tutorial.
Anyway, I'm from Sri Lanka.  :hearteyes:
 

Offline Cinemadrop

  • Topic Author
  • V.I.P.
  • Hero Member
  • *
  • Thanked: 759
  • Reputation: 84
  • Activity:
    0%
  • Join Date: Aug 2021
  • Posts: 338
  • Gender: Male
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #6 on: March 02, 2022, 05:36:56 PM »
Updated...!
 
The following users thanked this post: 𝐏𝐫𝐚𝐧𝐚𝐯𝐗𝐓

Offline freaks

  • Newbie
  • *
  • Thanked: 1
  • Reputation: 0
  • Activity:
    0%
  • Join Date: Mar 2022
  • Posts: 1
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #7 on: April 16, 2022, 11:45:34 AM »
please add video tutorial for how to use ffmpeg in detail
 
The following users thanked this post: 𝐏𝐫𝐚𝐧𝐚𝐯𝐗𝐓

Offline SAHILSINGHSOI

  • Devoted Member
  • **
  • Thanked: 137
  • Reputation: 4
  • Activity:
    0.2%
  • Join Date: Mar 2022
  • Posts: 175
Re: How to use FFmpeg [Tutorial] [Cinemadrop]
« Reply #8 on: January 23, 2023, 07:43:52 AM »
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login Sorry Again  :lol: I Said Could You Plz Provide Us A Tutorial  :heart:
BTW Where R U From My Brother ? :think:
Sure, I'll add a video tutorial.
Anyway, I'm from Sri Lanka.  :hearteyes:



Still waiting for the video tutorial bro...


 

Tags:
 

SimplePortal 2.3.7 © 2008-2024, SimplePortal