Showing posts with label Video. Show all posts
Showing posts with label Video. Show all posts

01 February 2026

How to crop a video on Ubuntu?

ffmpeg -i input.mp4 -vf "crop=1200:626:279:89" -c:v libx264 -crf 20 -c:a copy output.mp4


To crop a video on Ubuntu, you use FFmpeg’s
crop filter. Cropping is different from resizing; it’s like taking a pair of scissors to the video frame to cut out a specific area (like removing a watermark or focusing on a specific person).

The logic for cropping is: crop=width:height:x:y


1. The Basic Crop Command

If you know the exact dimensions you want to keep, use this:

Bash
ffmpeg -i input.mp4 -vf "crop=1280:720:0:0" -c:a copy output_cropped.mp4
  • 1280: The width of the "box" you want to keep.

  • 720: The height of the "box" you want to keep.

  • 0: The X coordinate (distance from the left edge) where the box starts.

  • 0: The Y coordinate (distance from the top edge) where the box starts.


2. Common "Real World" Examples

To crop a square from the center (great for social media):

Bash
ffmpeg -i input.mp4 -vf "crop=ih:ih" -c:a copy output_square.mp4

(Note: ih stands for "Input Height." This tells FFmpeg to make the width equal to the height.)

To cut the video in half (keep only the right side):

Bash
ffmpeg -i input.mp4 -vf "crop=iw/2:ih:iw/2:0" -c:a copy output_right_half.mp4

3. How to find your coordinates (The Easy Way)

Trying to guess "X" and "Y" coordinates in a terminal is hard. Here is a trick to do it visually:

  1. Open your video in VLC.

  2. Go to Tools > Effects and Filters.

  3. Go to Video Effects > Crop.

  4. Type in numbers until the video looks exactly how you want it.

  5. Write down those numbers (Left, Right, Top, Bottom) and use them in this FFmpeg command:

Bash
# If you found: Left=100, Top=50, Width=800, Height=600
ffmpeg -i input.mp4 -vf "crop=800:600:100:50" -c:a copy output_cropped.mp4

Important Tips:

  • Re-encoding: Because you are changing the actual picture, FFmpeg has to re-encode the video. I didn't include quality flags above to keep it simple, but for the best result, add -crf 20: ffmpeg -i input.mp4 -vf "crop=w:h:x:y" -c:v libx264 -crf 20 -c:a copy output.mp4

  • Even Numbers: Just like before, H.264 (MP4) loves even numbers. If you get an error, make sure your width and height are divisible by 2.


How to convert a .webm video into a .mp4 one?

ffmpeg -i output_trimmed.webm -c:v libx264 -crf 23 -preset medium -c:a aac output.mp4

How to trim a video on Ubuntu?

ffmpeg -i toAi.webm -ss 02:42 -to 05:59 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output_trimmed.webm

27 March 2022

.dav video files | play | convert to .mp4 | concatenate .mp4 files

1. How to play .dav video files?

Wondershare UniConverter



2. How to convert .dav files into .mp4 files?

>ffmpeg -y -i input-file.dav -c:v libx264 -crf 24 output-file.mp4



3. How to concatenate .mp4 files?

For Linux:
$ cat mylist.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
    
$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4

For Windows:

(echo file 'first file.mp4' & echo file 'second file.mp4' )>list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4

24 March 2021

How to extract a section from a video with ffmpeg?

How to extract a section from a video with ffmpeg?

https://superuser.com/questions/377343/cut-part-from-video-file-from-start-position-to-end-position-with-ffmpeg

How to cut a video, without re-encoding

Use this to cut video from [start] for [duration]:

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4

Here, the options mean the following:

  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip (same format).
  • Instead of -t you can also supply the end time with -to.
  • -c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.

Note that if you've used -ss, you have to subtract this from the -to timestamp. For example, if you cut with -ss 3 -i in.mp4 -to 5, the output will be five seconds long.

For more info, see https://trac.ffmpeg.org/wiki/Seeking

10 September 2019

how to scale videos/images with ffmpeg?

how to scale videos/images with ffmpeg?

https://trac.ffmpeg.org/wiki/Scaling

Keeping the Aspect Ratio

If we'd like to keep the aspect ratio, we need to specify only one component, either width or height, and set the other component to -1. For example, this command line:
ffmpeg -i input.jpg -vf scale=320:-1 output_320.png
will set the width of the output image to 320 pixels and will calculate the height of the output image according to the aspect ratio of the input image. The resulting image will have a dimension of 320⨉207 pixels.

13 June 2019

Convert DVD videos into mp4 files with ffmpeg

Convert DVD videos into mp4 files with ffmpeg

https://www.tech-g.com/2017/01/15/converting-dvd-to-mp4-h264-on-windows/

ffmpeg -i "concat:VTS_01_1.VOB|VTS_02_1.VOB|VTS_03_1.VOB|VTS_04_1.VOB|VTS_05_1.VOB" outfile.mp4

13 March 2019

How to Concatenate media files

 Concatenating media files


Using intermediate files

If you have MP4 files, these could be losslessly concatenated by first transcoding them to MPEG-2 transport streams. With H.264 video and AAC audio, the following can be used:

ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4

11 February 2019

Download, Extract, Convert videos

Download video with youtube-dl.exe

youtube-dl https://www.youtube.com/watch?v=S277aJyUehw


Converting video formats with ffmpeg.exe

ffmpeg -i input -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k \
-movflags +faststart -vf scale=-2:720,format=yuv420p output.mp4
ffmpeg -i test.mp4 -codec:v libtheora -qscale:v 6 -codec:a libvorbis -qscale:a 6 test.ogv


Extract part of a video with ffmpeg

ffmpeg -ss 00:00:30 -i orginalfile -t 00:00:05 -vcodec copy -acodec copy newfile




24 July 2018

How to convert mp4 videos into flv ones with ffmpeg?

How to convert mp4 videos into flv ones with ffmpeg?

I'm late, but if this can help somebody, it's time well spent.
If I understand correctly, you want to convert MP4 to FLV using FFMPEG. Here are two command lines to help you do that; I'm currently using them myself (you can adjust them to your needs too) :
ffmpeg -i source.mp4 -c:v libx264 -crf 19 destinationfile.flv
and if the first one doesn't work :
ffmpeg -i source.mp4 -c:v libx264 -ar 22050 -crf 28 destinationfile.flv
Please note that -crf XX is the quality of the video you will create. It's between 0 and 51 (but between 17 and 23 is a reasonable range and the lower the number is, the better quality the video is going to be).
The -ar 22050 is for adjusting the audio sample range (audio quality). You can choose 11025, 22050 or 44100.
I suggest you read this Tutorial for FFMPEG . It's really complete and has many useful tips.
Hope this will help you or somebody in the same situation.

31 May 2018

How to resize videos

How to resize videos?

https://www.ffmpeg.org/download.html

Keeping the Aspect Ratio

If we'd like to keep the aspect ratio, we need to specify only one component, either width or height, and set the other component to -1. For example, this command line:
ffmpeg -i input.jpg -vf scale=320:-1 output_320.png
will set the width of the output image to 320 pixels and will calculate the height of the output image according to the aspect ratio of the input image. The resulting image will have a dimension of 320⨉207 pixels.

26 April 2018

A video can be watched in Chrome but not in IE, or in IE but not in Chrome

A video can be watched in Chrome but not in IE, or in IE but not in Chrome


1   <video width="480" height="300" controls autoplay>
2    <source src="https://app.cicscanada.com/video/english/homepage/cics_50th_anniversary_gala.mp4" type="video/mp4" />
3   <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="300">
4    <!--[if !IE]>-->
5    <object type="application/x-shockwave-flash" data="http://app.cicscanada.com/video/player/player.swf" width="480" height="300">
6    <!--<![endif]-->
7    <param name="movie" value="http://app.cicscanada.com/video/player/player.swf" />
8    <param name="wmode" value="transparent" />
9    <param name="bgcolor" value="#FFFFFF" />
10   <param name="quality" value="high" />
11   <param name="allowFullScreen" value="true" />
12   <param name="allowscriptaccess" value="always" />
13   <a href="http://www.adobe.com/go/getflash">
14   <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
15   </a>
16   <param name="flashvars" value="vdo=/video/english/homepage/cics_50th_anniversary_gala.flv&amp;autoplay=true" />
17   <!--[if !IE]>-->
18   </object>
19   <!--<![endif]-->
20   </object>
21  </video>

IE plays flv, while Chrome plays mp4.

Line #16 is for IE. You should not put 'https://app.cicscanada.com' before the file path '/video/english/homepage/...', otherwise, IE would not play the video.

Line #2 is for Chrome. You have to put 'https://app.cicscanada.com' before the file path '/video/english/homepage/...', otherwise, Chrome would not play the video.

(THE END)