Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ffmpeg [2015/05/29 04:16]
slackermedia
ffmpeg [2021/06/03 19:48] (current)
Line 1: Line 1:
-[[{arrowp.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​left:​0;​}digikam|]] 
- 
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​margin-left:​2.5em;​}ffmpeg2theora|]] 
- 
 ====== Ffmpeg HOWTO ====== ====== Ffmpeg HOWTO ======
  
Line 305: Line 301:
  
 Since most videos have sound, at least some portion of your overall file size Since most videos have sound, at least some portion of your overall file size
-is determined by how its audio has been encoded. The same principles apply to +is determined by how its audio has been encoded. The same general ​principles ​that apply to video also apply to audio, with a few variations.
-audio, with a few variations ​in terminology.+
  
-Audio has a bit rate, assigned with the -b:a flag, which determines how much +Audio has a bit rate, assigned with the ''​-b:a'' ​flag, which determines how much data is used to recreate the audio waves. You're probably already familiar with this idea since online music stores usually ​advertise ​their song quality as either ​**128kbps** or the higher quality ​**192kbps** or **256kbps** versions. The higher bit rates usually provide better subtleties, with the more modest ranges (128kbps is a good middle-of-the-road number) ​providing ​a "good enough"​ quality, while the lower ranges start to blatantly ​sacrifice quality. Once again, how much this 
-data is used to recreate the audio waves. You're probably already familiar with +matters to you depends on //you//, and the content of the media itself. A lecture video, for instance, ​can tolerate 80kbps encoding while a lush musical ​soundtrack would suffer ​arguably even at 192kbps.
-this idea since online music stores usually ​advertises ​their song quality as +
-either 128kbps or the higher quality 192kbps or 256kbps versions. The higher +
-bit rates usually provide better subtleties, with more modest ranges (128kbps +
-is a good middle-of-the-road number) ​provide ​a "good enough"​ quality, while the +
-lower ranges start to noticeably ​sacrifice quality. Once again, how much this +
-matters to you depends on you, and the content of the video itself. A lecture +
-video can tolerate 80kbps encoding while a video with a lush soundtrack would +
-suffer.+
  
-Audio also has channels. As you might expect, the more channels you have, the +Audio also has **channels**. As you might expect, the more channels you have, the larger the file will be. It's common practise to reduce any surround sound soundtrack to stereo, and in some cases to simply use one mono channel. ffmpeg uses the ''​-ac'' ​flag to define how many channels you want, with 2 being stereo and
-larger the file will be. It's common practise to reduce any surround sound +
-soundtrack to stereo, and in some cases to simply use one mono channel. ffmpeg +
-uses the -flag to define how many channels you want, with 2 being stereo and+
 1 being mono. 1 being mono.
  
-The sample rate of audio defines how many samples of a soundwave is used per +The sample rate of audio defines how many samples of a soundwave is used per second, and is measured in thousands of samples per second. DVD quality is considered 48000hz ​(48khz) ​while CD quality is 44100hz ​(44.1khz). Anything lower (32000hz, 22050hz, 16000hz) suffers noticeably in quality although they do have remarkable results on file size savings. However, when transcoding,​ changing the sample rate of the audio drastically could throw the audio track out of sync with your video, so use this ability carefully. ​Ffmpeg ​uses the ''​-ar'' ​flag
-second, and is measured in thousands of samples per second. DVD quality is +
-considered 48000hz while CD quality is 44100hz. Anything lower (32000hz, +
-22050hz, 16000hz) suffers noticeably in quality although they do have +
-remarkable results on file size savings. However, when transcoding,​ changing +
-the sample rate of the audio drastically could throw the audio track out of +
-sync with your video, so use this ability carefully. ​ffmpeg ​uses the -ar flag+
 to define sample rate. to define sample rate.
  
Line 337: Line 315:
 compression:​ compression:​
  
- $ ffmpeg -i sintel_1080p.avi -s hd720 +<​code>​ 
--b:v 8000 -b:a 128k -ar 44100 -c 1 sintel.mkv+$ ffmpeg -i hackmovie_goldmaster.mkv -s hd720 
 +-b:v 18000k ​-b:a 128k -ar 44100 -ac 2 hackmovie_online.mkv 
 +</​code>​
  
-Threads+====Threads====
  
-If you're using a computer with multiple CPU cores, ​you can take advantage of +If you're using a computer with multiple CPU cores, take advantage of the ''​-threads'' ​flag. It's simple:
-the -threads flag. It's simple:+
  
-  ​$ ffmpeg -i sintel.mkv -threads 8 sintel.mov+<​code>​ 
 +$ ffmpeg -i hackmovie_goldmaster.mkv -threads 8 hackmovie.webm 
 +</​code>​
  
-How to Test Before Encoding+The rule of thumb for calculating the number of threads your computer can handle is to take the number of CPU cores and either: 
 + 
 +  *To encode and still be able to use your computer: //Number of cores = threads// 
 +  *To encode overnight: //(Number of cores) * 2 = threads// 
 + 
 +To find out how many cores your CPU has, look into ''/​proc'':​ 
 + 
 +<​code>​ 
 +$ grep proc /​proc/​cpuinfo 
 +processor: ​   : 1 
 +processor: ​   : 2 
 +processor: ​   : 3 
 +processor: ​   : 4 
 +processor: ​   : 5 
 +processor: ​   : 6 
 +processor: ​   : 7 
 +processor: ​   : 8 
 +</​code>​ 
 + 
 +Adjust as needed, depending on the actual performance of your computer and what you need to work on while it encodes. 
 + 
 + 
 +=====How to Test Before Encoding=====
  
 Because a computer is doing the work, many people view video encoding as a Because a computer is doing the work, many people view video encoding as a
Line 360: Line 363:
 action is happening within the frames and what qualities are important. Use action is happening within the frames and what qualities are important. Use
 these artistic impressions to guide you in the choices you make about frame these artistic impressions to guide you in the choices you make about frame
-size, bitrate, and frame rate. Encode with two passes, and encode multiple+size, bit rate, and frame rate. Encode with two passes, and encode multiple
 versions of the same video. Compare the results. In no time, you'll get a good versions of the same video. Compare the results. In no time, you'll get a good
 feeling for what different codecs have to offer, what kinds of videos can feeling for what different codecs have to offer, what kinds of videos can
Line 369: Line 372:
 you to encode small sections of a video. you to encode small sections of a video.
  
-The -ss option dictates what time to start encoding, and the -t dictates how +The ''​-ss'' ​option dictates what time to start encoding, and the ''​-t'' ​dictates how long to encode for (not the timecode at which to stop, as a video editor would expect; the values are start time and duration, not in and out). For example, to start encoding at 3 minutes and 30 seconds into a video, and to encode for 1 minute:
-long to encode for (not the timecode at which to stop, as a video editor would +
-expect; the values are start time and duration, not in and out). For example, +
-to start encoding at 3 minutes and 30 seconds into a video, and to encode for 1 +
-minute:+
  
-  ​$ ffmpeg -i sintel.mov -ss 00:03:30:00 -t 00:01:00:00 -threads 8 sintel.mkv+<​code>​ 
 +$ ffmpeg -i hackmovie_snippet.mkv -ss 03:30:00 -t 01:​00:​00 ​
 +-s hd720 -threads 8 compression-test.webm 
 +</​code>​ 
 + 
 +Run a few hundred encoding tests overnight, study the results, and you'll be an expert in no time. 
 + 
 +=====Performance Boost===== 
 + 
 +Linux video and audio editors generally support every possible codec they can, and that's quite a lot. This affords you great freedom, but should you experience performance issues while working with a compressed file format (such as MP3, Vorbis, Theora, Dirac, and so on), consider extracting the video and audio streams from their compressed containers and working with them as native or [nearly] uncompressed files. 
 + 
 +If you do find that you need to convert media, you obviously want to avoid losing quality, so ensure that you are using a //less// compressed container, and that you are retaining the exact same settings as the source video. 
 + 
 +If ''​mediainfo''​ or ''​video-meta''​ reports a bit rate of 67M at 29.97 fps, then when you convert, use at least 67M for the bit rate and 29.97 for the frame rate. 
 + 
 +Here are some example commands for the various native and [mostly] uncompressed formats: 
 + 
 +<WRAP indent>​ 
 +**WAV** 
 + 
 +//​Uncompressed PCM audio.// 
 + 
 +<​code>​ 
 +ffmpeg -i foo.bar -vn -ar 48000 foo.wav 
 +</​code>​ 
 + 
 +**AIFF** 
 + 
 +//​Uncompressed PCM audio.// 
 + 
 +<​code>​ 
 +ffmpeg -i foo.bar -vn -ar 48000 foo.aiff 
 +</​code>​ 
 + 
 +**AU** 
 + 
 +//Sun Microsystems uncompressed PCM data.// 
 + 
 +<​code>​ 
 +ffmpeg -i foo.bar -vn -ar 48000 foo.au 
 +</​code>​ 
 +</​WRAP>​ 
 + 
 +Native and [mostly] uncompressed video formats: 
 + 
 +<WRAP indent>​ 
 +**FFV1** 
 + 
 +//Native ffmpeg video format.// 
 + 
 +<​code>​ 
 +ffmpeg -i foo.bar -an -vcodec FFV1 -b:v 80M -threads 8 foo.mkv 
 +</​code>​ 
 + 
 +**Huff YUV** 
 + 
 +//Lossless video format.// 
 + 
 +<​code>​ 
 +ffmpeg -i foo.bar -an -vcodec huffyuv ​ -b:v 80M -threads 8 foo.mkv 
 +</​code>​ 
 + 
 +**MOV** 
 + 
 +//Quicktime movie file.// 
 + 
 +<​code>​ 
 +ffmpeg -i foo.bar -an -vcodec libquicktime ​ -b:v 80M -threads 8 foo.mov 
 +</​code>​ 
 +</​WRAP>​ 
 + 
 +There are other formats, but these are well supported and tested. 
 + 
 + 
 +=====Lossless Codecs===== 
 + 
 +Ffmpeg supports a number of lossless formats ideal for Gold Masters and long term storage, including FFV1 and HuffYUV for video, FLAC and WAVPACK for sound.
  
-Run a few hundred encoding tests overnight, study the results, and you'll be an 
-expert in no time. 
  
 <WRAP tip> <WRAP tip>
 **See Also** \\ **See Also** \\
-mencoder+[[http://​www.mplayerhq.hu/​DOCS/​HTML/​en/​mencoder.html|Mencoder]] \\ 
 +[[http://​gstreamer.freedesktop.org/​|Gstreamer]] \\ 
 +[[https://​xiph.org/​flac/​|Flac]] \\ 
 +[[http://​www.wavpack.com/​|wavpack]] \\ 
 +[[http://​www.imagemagick.org|Imagemagick]] 
 +</​WRAP>​ 
 + 
 +<WRAP centeralign>​ 
 +<wrap fa>​[[fabla|R]]</​wrap>​ <wrap fa>​[[start|S]]</​wrap>​ <wrap fa>​[[ffmpeg2theora|Q]]</​wrap>​
 </​WRAP>​ </​WRAP>​
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​float:​right;​}ffmpeg2theora|]][[{arrowp.png|border:​0;​background:​none;​width:​0;​float:​right;​}digikam|]]