FFMPEG Tips and Tricks - Questions and suggestions about this video editing tool

Nobody4353

Archivist and Cyber Security Enthusiast
kiwifarms.net
If I'm not mistake youtube-dl does not currently have an option to download a section of a video without downloading the entire video first, however ffmpeg allowed me to fix that problem:

Use youtube-dl to get the actual URL of the video first:
youtube-dl --get-url -f best --no-cache "<Video URL>"
Parameters:
  • The -g tells youtube-dl to get the actual URL for the video​
  • The -f specifies the format you can change this to whatever you want but I chose best here​
  • The --no-cache parameter means youtube-dl will request a new URL instead of relying on a cached one​

Paste the URL you got from the above command into this ffmpeg command:
ffmpeg -ss <Start Time> -t <End Time> -i <URL From youtube-dl> out.mp4
Parameters:
  • The -ss parameter is the time you want to start downloading the video at for example 00:00:30 starts at 30 seconds
  • The -t parameter is the time you want to stop downloading the video at for example 00:01:40 stops downloading at 1 minute and 40 seconds
  • The -i parameter it the URL you got from youtube-dl from the first command
 
Last edited:

Sam Losco

True & Honest Fan
kiwifarms.net
Probably pretty basic, but the only ffmpeg command I have saved is to combine multiple mp4's into one.

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
If you don't set -safe 0, it'll find reasons to not work.
list.txt is just a list of the mp4s to be joined:
file 'path/to/file.ext'
 

Master Troll

kiwifarms.net
This command encodes a video with good quality, using slower preset to achieve better compression:
ffmpeg -i input.avi -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
Note that in this example the audio stream of the input file is simply stream copied over to the output and not re-encoded.

Convert with Dual Audio support
ffmpeg -i input.avi -c:v libx264 -preset slow -crf 22 -map 0:0 -map 0:1 -map 0:2 -c:a copy output.mp4
 
Last edited:

Sam Losco

True & Honest Fan
kiwifarms.net
Well, if we include youtube-dl too, I got another. I have my defaults set to this:

youtube-dl -o '%(upload_date)s %(title)s.%(ext)s' --write-description --write-thumbnail <Video URL>

-o sets the filename, which is set to the upload date and then the title of the video. And then a tag for writing the description of the video to a txt file and saving the default thumbnail. This is all specifically for youtube videos. If I'm grabbing something from a site that doesn't have an upload date, for example, it just writes"NA" in the filename and won't save anything for description or thumbnail if not present. So it doesn't fuck up anything for non-youtube sites.

The -o parameters apply to the description and thumbnail filename as well.

The upload date has a bit of a quirk. If it was a live stream that went into the next day, the upload date will be the date the stream ended and the video became an upload, instead of the date the stream started.
 

XYZpdq

fbi most wanted sskealeaton
True & Honest Fan
kiwifarms.net
did youtube-dl ever get downloading on twitch for content you needed a subscription for? It used to let you feed in a login/pass but then twitch put in some hidden captcha thing
 

Master Troll

kiwifarms.net
did youtube-dl ever get downloading on twitch for content you needed a subscription for? It used to let you feed in a login/pass but then twitch put in some hidden captcha thing
-u, --username USERNAME
-p, --password PASSWORD
Login with this account ID Account password. If this option is left out, youtube-dl will ask interactively.

-2, --twofactor TWOFACTOR
-n, --netrc
Two-factor authentication code Use .netrc authentication data

--video-password PASSWORD
Video password (vimeo, smotri, youku)

You may also want to configure automatic credentials storage for extractors that support authentication (by providing login and password with --username and --password) in order not to pass credentials as command line arguments on every youtube-dl execution and prevent tracking plain text passwords in the shell command history. You can achieve this using a .netrc file on a per extractor basis. For that you will need to create a .netrc file in your $HOME and restrict permissions to read/write by only you:

touch $HOME/.netrc
chmod a-rwx,u+rw $HOME/.netrc

After that you can add credentials for an extractor in the following format, where extractor is the name of the extractor in lowercase:
machine <extractor> login <login> password <password>

For example:
machine youtube login myaccount@gmail.com password my_youtube_password
machine twitch login my_twitch_account_name password my_twitch_password

To activate authentication with the .netrc file you should pass --netrc to youtube-dl or place it in the configuration file.
 
Last edited:

Yotsubaaa

Discord is the best!
True & Honest Fan
kiwifarms.net
Paste the URL you got from the above command into this ffmpeg command:
ffmpeg -ss <Start Time> -t <End Time> -i <URL From youtube-dl> out.mp4
Parameters:
  • The -ss parameter is the time you want to start downloading the video at for example 00:00:30 starts at 30 seconds
  • The -t parameter is the time you want to stop downloading the video at for example 00:01:40 stops downloading at 1 minute and 40 seconds
  • The -i parameter it the URL you got from youtube-dl from the first command
Yep! Just a slight thing. Specifying -t gives the duration for the clip, not the end time. For the end time you want -to instead.
 

Master Troll

kiwifarms.net
Capturing your Desktop / Screen Recording

Use the x11grab device:

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 output.mp4

This will grab the image from desktop, starting with the upper-left corner at x=100, y=200 with a width and height of 1024⨉768.

If you need audio too, you can use ALSA (see Capture/ALSA for more info):

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 -f alsa -ac 2 -i hw:0 output.mkv

Or the PULSE input device:

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 -f pulse -ac 2 -i default output.mkv

Cntrl+C to Exit and Save

Select recording area

ffmpeg -f [audio-driver] -i default -f x11grab -s [resolution] -i :0.0+[point-X],[point-Y] -r 25 -vcodec libx264 output.mkv

ffmpeg -f alsa -i default -f x11grab -s 720x480 -i :0.0+180,120 -r 25 -vcodec libx264 output.mkv
 
Last edited:

Smaug's Smokey Hole

no corona
kiwifarms.net
If I'm not mistake youtube-dl does not currently have an option to download a section of a video without downloading the entire video first, however ffmpeg allowed me to fix that problem:

Use youtube-dl to get the actual URL of the video first:
youtube-dl --get-url -f best --no-cache "<Video URL>"
Parameters:
  • The -g tells youtube-dl to get the actual URL for the video​
  • The -f specifies the format you can change this to whatever you want but I chose best here​
  • The --no-cache parameter means youtube-dl will request a new URL instead of relying on a cached one​

Paste the URL you got from the above command into this ffmpeg command:
ffmpeg -ss <Start Time> -t <End Time> -i <URL From youtube-dl> out.mp4
Parameters:
  • The -ss parameter is the time you want to start downloading the video at for example 00:00:30 starts at 30 seconds
  • The -t parameter is the time you want to stop downloading the video at for example 00:01:40 stops downloading at 1 minute and 40 seconds
  • The -i parameter it the URL you got from youtube-dl from the first command
That seems like it would encode the video again and youtube is already ass-quality. Start and end the cut on key frames instead to keep it lossless.

Probably pretty basic, but the only ffmpeg command I have saved is to combine multiple mp4's into one.

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
If you don't set -safe 0, it'll find reasons to not work.
list.txt is just a list of the mp4s to be joined:
file 'path/to/file.ext'
Avidemux is a very nice GUI for ffmpeg, use the append option to add shit together with any extra encoding, it writes the streams into a new container and enables you to play and preview the video before committing to anything.

edit: or the reverse, pull segments out without encoding them again.
 
Last edited:
  • Informative
Reactions: Nobody4353
Tags
None