FFmpeg commands to help you play video clips

2021/01/0100:20:20 entertainment 2627

FFmpeg commands to help you play video clips - DayDayNews

In this guide, I will use examples to illustrate how to use the FFmpeg media framework to do various audio and video transcoding and conversion operations. I have compiled more than 20 most commonly used FFmpeg commands for beginners, and I will add more examples from time to time to keep this guide updated. Please bookmark this guide and check back for updates later. Let's get started, if you haven't installed FFmpeg on your Linux system, refer to the guide below.

  • Install FFmpeg in Linux

More than 20 FFmpeg commands for beginners The typical syntax of

FFmpeg command is:

  1. ffmpeg [global options] {[input file options] -i input_url_address} ...
  2. {[output file options ] Output_url_address} ...

Now we will look at some important and useful FFmpeg commands.

1. Get audio/video file information

To display the details of your media files, run:

  1. $ ffmpeg -i video.mp4

Sample output:

  1. ffmpeg version n4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
  2. built with gcc 8.2.1 (GCC) 20181127
  3. configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable- ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable- libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable- libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis--enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable- libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-versi on3
  4. libavutil 56. 22.100 / 56. 22.100
  5. libavcodec 58. 35.100 / 58. 35.100
  6. libavformat 58.20.100 / 58. 20.100
  7. libavdevice 58. 5.100 / 58. 5.100
  8. libavfilter 7. 40.101 / 7. 40.101
  9. libswscale 5. 3.100 / 5. 3.100
  10. libswresample 3. 3.100 / 3. 3.100
  11. libpostproc 55. 3.100 / 55. 3.100zlibpostproc Input 0, mov9 mp4,m4a,3gp,3g2,mj2, from'video.mp4':
  12. Metadata:
  13. major_brand: isom
  14. minor_version: 512
  15. compatible_brands: bitomiso2avc1mp41
  16. enzcoder: startzzz 00:00: 00:00: 454zrate 00:00: 00:00: 00:00 0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,smpte170m/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 318 kb/s, 30 fps, 30 tbr ,15360 tbn, 60 tbc (default)
  17. Metadata:
  18. handler_name: ISO Media file produced by Google Inc. Created on: 04/08/2019.
  19. Stream 0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s(default)
  20. Metadata:
  21. handler_name: ISO Media file produced by Google Inc. Created on: 04/08/2019.
  22. At least one output file mu st be specified

As you can see in the above output, FFmpeg displays the media file information, as well as FFmpeg details, such as version, configuration details, copyright mark, build parameters, library options, etc.

If you don't want to see the FFmpeg banner and other details, but just want to see the media file information, use the -hide_banner flag, as shown below.

  1. $ ffmpeg -i video.mp4 -hide_banner

Sample output:


FFmpeg commands to help you play video clips - DayDayNews


Use FFMpeg to view audio and video file information.

see it? Now, it only displays the media file details.

2, convert video files to different formats

FFmpeg is a powerful audio and video converter, so it can convert media files between different formats. For example, to convert mp4 files to avi files, run:

  1. $ ffmpeg -i video.mp4 video.avi

Similarly, you can convert media files to any format you choose.

, for example, to convert YouTube flv format video is in mpeg format, run:

  1. $ ffmpeg -i video.flv video.mpeg

If you want to maintain the quality of your source video file, use -qscale 0 parameter:

  1. $ ffmpeg -i input.webm -qscale 0 output.mp4

is to check the list of supported formats of FFmpeg, run:

  1. $ ffmpeg -formats

3, convert video file to audio file

I convert a video file to audio file, just specify the output format, like .mp3, or .ogg , Or any other audio format. The above command

will convert the input.mp4 video file to the output.mp3 audio file.

  1. $ ffmpeg -i input.mp4 -vn output.mp3

In addition, you can also use various audio conversion encoding options for the output file, as shown below.

  1. $ ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 output.mp3

Here,

  • -vn – indicates that we have disabled video recording in the output file.
  • -ar-Set the audio frequency of the output file. Commonly used values ​​are 22050 Hz, 44100 Hz, 48000 Hz.
  • -ac-Set the number of audio channels.
  • -ab-Indicates the audio bit rate.
  • -f-output file format. In our example, it is in mp3 format.

4, change the resolution of the video file

If you want to set a video file to a specified resolution, you can use the following command:

  1. $ ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4

or,

  1. $ ffmpeg -i input.mp4 -s 1280x720 -c:a copy output.mp4

The above command will set the resolution of the given video file to 1280×720.

Similarly, to convert the above file to 640×480 size, run:

  1. $ ffmpeg -i input.mp4 -filter:v scale=640:480 -c:a copy output.mp4

or,

  1. $ ffmpeg -i input .mp4 -s 640x480 -c:a copy output.mp4

This trick will help you scale your video files to smaller display devices, such as tablets and mobile phones.

5. Compressing video files

It is always a good idea to reduce the size of media files to a smaller size to save hardware space. The command below

will compress and reduce the size of the output file.

  1. $ ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4

Please note that if you try to reduce the size of the video file, you will lose the video quality. If 24 is too aggressive, you can lower the -crf value to or lower.

You can also use the following options to convert the encoded audio to reduce the bit rate, make it have a sense of stereo, thereby reducing the size.

  1. -ac2 -c:a aac -strict -2 -b:a 128k

6. Compressed audio files

are just like compressed video files. To save some disk space, you can also use the -ab flag to compress audio files.

For example, you have an audio file with a bitrate of 320 kbps. You want to compress it by changing the bitrate to any lower value, like below.

  1. $ ffmpeg -i input.mp3 -ab 128 output.mp3

The list of various available audio bitrates is:

  1. 96kbps
  2. 112kbps
  3. 128kbps
  4. 160kbps
  5. 192kbps
  6. 256kbpsz10, if you don't want an audio stream from a video file, you don’t want to remove a video stream from a video file of 4zz21kbps
  7. zz10. an sign.

    1. $ ffmpeg -i input.mp4 -an output.mp4

    Here, -an means no audio recording. The command above

    will cancel all audio-related flags, because we don't want audio from input.mp4.

    8. Remove a video stream from a media file

    Similarly, if you don't want a video stream, you can simply remove it from the media file using the -vn flag. -vn means there is no video recording. In other words, this command converts the given media file into an audio file. The command below

    will remove the video from the given media file.

    1. $ ffmpeg -i input.mp4 -vn output.mp3

    You can also use the -ab flag to indicate the bit rate of the output file, as shown in the following example.

    1. $ ffmpeg -i input.mp4 -vn -ab 320 output.mp3

    9. Extracting images from video. Another useful feature of

    FFmpeg is that we can easily extract images from a video file. This can be very useful if you want to create an album from a video file. To extract images from a video file, use the following command:

    1. $ ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png

    Here,

    • -r-set the frame rate. That is, the number of frames to images is extracted every second. The default value is 25.
    • -f-indicates the output format, that is, in our case it is an image.
    • image-%2d.png – shows how we want to name the extracted image. In this example, the naming should start like image-01.png, image-02.png, image-03.png, etc. If you use %3d, then the image naming starts like image-001.png, image-002.png, etc.

    10, cropped video

    FFMpeg allows to crop a given media file in any range we choose. The syntax of

    cropping a video file is given as follows:

    1. ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4

    Here,

    • input.mp4-source video file.
    • -filter:v-indicates the video filter.
    • crop-represents a crop filter.
    • w – The width of the rectangle we want to crop from the source video.
    • h-the height of the rectangle.
    • x-we want to self-source the videoThe x coordinate of the cropped rectangle.
    • y – The y coordinate of the rectangle.

    For example, if you want a video with a width of 640 pixels and a height of 480 pixels from the position of the video (200,150), the command should be:

    1. $ ffmpeg -i input.mp4 -filter:v "crop=640:480: 200:150" output.mp4

    Please note that cutting the video will affect the quality. Do not cut unless necessary.

    11. Convert a specific part of a video

    Sometimes, you may want to convert only a specific part of a video file to a different format. To illustrate with an example, the following command will convert the first 10 seconds of the given video input.mp4 file to the video .avi format.

    1. $ ffmpeg -i input.mp4 -t 10 output.avi

    Here, we specify the time in seconds. In addition, it is also possible to specify the time in the hh.mm.ss format.

    12. Set the aspect ratio of the video screen

    You can use the -aspect flag to set the aspect ratio of a video file, as shown below.

    1. $ ffmpeg -i input.mp4 -aspect 16:9 output.mp4

    The commonly used aspect ratio is:

    • 16:9
    • 4:3
    • 16:10
    • 5:4
    • 2:21:1
    • 9
    • 2:10zzz13, add the poster image to the image of zzz11:11:13 Audio file

      You can add a poster image to your file so that the image will be displayed when the audio file is played. This is useful for audio files hosted on video hosting or sharing websites.

      1. $ ffmpeg -loop 1 -i inputimage.jpg -i inputaudio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4

      14, use the start and stop time to cut a piece of media file

      can use the start and stop time to cut a video into a short clip, we can use the following command.

      1. $ ffmpeg -i input.mp4 -ss 00:00:50 -codec copy -t 50 output.mp4

      Here,

      • –s – represents the start time of the video clip. In our example, the start time is the 50th second.
      • -t-represents the total duration.

      It is very useful when you want to cut a part of an audio or video file using the start and end time.

      Similarly, we can cut the audio like below.

      1. $ ffmpeg -i audio.mp3 -ss 00:01:54 -to 00:06:53 -c copy output.mp3

      15, split the video file into multiple parts

      Some websites will only allow you to upload videos of specific sizes . In this case, you can split a large video file into multiple smaller parts, like below.

      1. $ ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4

      Here,

      • -t 00:00:30 means from the beginning of the video Create a part of the video to the 30th second of the video.
      • -ss 00:00:30 shows the start timestamp for the next part of the video. It means that Part 2 will start at the 30th second and will continue to the end of the original video file.

      16. Join or merge multiple video parts into one

      FFmpeg. You can also join multiple video parts and create a single video file.

      creates join.txt containing the exact path of the file you want to join. All files should be in the same format (same encoding format). The path of all files should be listed one by one, like below.

      1. file /home/sk/myvideos/part1.mp4
      2. file /home/sk/myvideos/part2.mp4
      3. file /home/sk/myvideos/part3.mp4
      4. file /home/sk/myvideos/part4.mp4

      Now, join all files, use the command

      1. $ ffmpeg -f concat -i join.txt -c copy output.mp4

      If you get some errors like the following;

      1. [concat @ 0x555fed174cc0] Unsafe file name'/path/to/mp4'
      2. join.txt: Operation not permitted

      Add -safe 0 :

      1. $ ffmpeg -f concat -safe 0 -i join.txt -c copy output.mp4

      The above command will join part1.mp4, part2.mp4, part3.mp4 and part4.mp4 files into one called output.mp4 in a single file.

      17. Add subtitles to a video file

      We can use FFmpeg to add subtitles to the video file. Download the correct subtitles for your video and add it to your video as shown below.

      1. $ fmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4

      18, preview or test video or audio files

      you may want to preview To verify or test whether the output file has been properly transcoded. To complete the preview, you can play it from your terminal with the command:

      1. $ ffplay video.mp4

      Similarly, you can test the audio file as shown below.

      1. $ ffplay audio.mp3

      19, increase/decrease the video playback speed

      FFmpeg allows you to adjust the video playback speed.

      To increase the video playback speed, run:

      1. $ ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4

      This command will double the video speed.

      To reduce the speed of your video, you need to use a multiple greater than 1. To reduce the playback speed, run:

      1. $ ffmpeg -i input.mp4 -vf "setpts=4.0*PTS" output.mp4

      20. Create animated GIFs

      For various purposes, we use GIFs on almost all social and professional networks image. Using FFmpeg, we can create animated video files simply and quickly. The following guide explains how to use FFmp on Unix-like systemseg and ImageMagick create an animated GIF file. How to create animated GIF

      • in Linux

      21, create video from PDF files

      I have collected many PDF files over the years, most of which are Linux tutorials, which are saved on my tablet. Sometimes I am too lazy to read them from the tablet. Therefore, I decided to create a video from a PDF file and watch them on a large screen device (like a TV or a computer). If you want to know how to make a movie from a batch of PDF files, the following guide will help you.

      • How to create a video from a PDF file in Linux

      22, get help

      In this guide, I have covered most of the frequently used FFmpeg commands. It has many different options to do various advanced functions. To learn more usage, please refer to the man page.

      1. $ man ffmpeg

      That's all. I hope this guide will help you get started with FFmpeg. If you find this guide useful, please share it on your social and professional networks. More good things are coming. Stay tuned!

      Thank you!


      via: https://www.ostechnix.com/20-ffmpeg-commands-beginners/

      Author: sk topics: lujun9972 Translator: robsean proofread: wxy

      LCTT original article by the compiler, Linux China is proud

      transferred from https: / /linux.cn/article-10932-1.html

entertainment Category Latest News

Zhuang Shengchun: For the first time, he is the first male anchor in CCTV News to appear in a sleeveless shirt to host the film╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮Focus on the latest trends of artists and convey mainstream voices in the circle. [Xiaojinyu] The entire network p - DayDayNews

Zhuang Shengchun: For the first time, he is the first male anchor in CCTV News to appear in a sleeveless shirt to host the film╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮Focus on the latest trends of artists and convey mainstream voices in the circle. [Xiaojinyu] The entire network p

Zhuang Shengchun: For the first time, he is the first male anchor to appear in CCTV News to appear in a sleeveless shirt