Computer >> कंप्यूटर >  >> सॉफ्टवेयर >> सॉफ्टवेयर

ffmpeg के लिए एक गाइड - मल्टीमीडिया के लिए आपकी वन-स्टॉप शॉप

इन वर्षों में, ऐसे कई अवसर आए जब मुझे किसी प्रकार का मल्टीमीडिया संपादन करने की आवश्यकता पड़ी। ऑडियो, वीडियो, आप इसे नाम दें। चाहे वह मेरे Youtube चैनल के लिए मेरी बेकार क्लिप बनाना हो, संगीत निकालना या परिवर्तित करना, उपशीर्षक एम्बेड करना, बार-बार, मैं खुद को कमांड-लाइन पर ffmpeg का उपयोग करते हुए पाऊंगा और हमेशा इस सरल कार्यक्रम की क्षमताओं से बहुत सूक्ष्म रूप से चकित होते हुए प्रक्रिया का आनंद ले रहा हूं। ।

और इसलिए मैंने सोचा, शायद मुझे ffmpeg पर एक अधिक व्यापक मार्गदर्शिका लिखनी चाहिए, जो विभिन्न प्रकार के कार्यों और कार्यों को सूचीबद्ध करती है, और फिर उन्हें वास्तविक जीवन के उदाहरणों और उपयोग के मामलों में भी लपेटती है। जबकि मैंने पहली बार 2008 में अपने फ्लैश एडिटिंग ट्यूटोरियल में गुस्से में ffmpeg का उल्लेख किया था, यह एक नए, अप-टू-डेट लेख के लिए समय है। यह कमांड-लाइन होने जा रहा है, यह नीरस होने वाला है, लेकिन यह मजेदार भी होना चाहिए। मेरे पीछे आओ।

मूल बातें

Ffmpeg लगभग सभी और किसी भी लिनक्स वितरण में उपलब्ध है, और विंडोज और मैक के लिए भी बनाता है। यदि आप जानना चाहते हैं कि यह क्या कर सकता है, तो आप तर्क के बिना ffmpeg चलाकर या वैकल्पिक -hide_banner ध्वज के साथ इसकी क्षमताओं की जांच कर सकते हैं। आप मुख्य कार्यक्रम के साथ-साथ इसके कई उप-आदेशों में से किसी के लिए भी सहायता विकल्प का उपयोग कर सकते हैं। सुविधाओं की चमकदार सरणी डराने वाली हो सकती है, इसलिए हम धीरे-धीरे लेकिन निश्चित रूप से आगे बढ़ेंगे। फिर, वास्तविक दस्तावेज़ीकरण को न भूलें, जो बहुत साफ-सुथरा है।

रूपांतरण और ट्रांसकोडिंग

सबसे आम कार्यों में से एक फाइलों को एक प्रारूप से दूसरे प्रारूप में परिवर्तित करना है। एक FLV क्लिप से ऑडियो फ़ाइलें निकालने का मेरा उदाहरण याद रखें? एक ही बात। लेकिन आप कैमरे पर रिकॉर्ड किए गए वीडियो को MP4 जैसी किसी चीज़ में बदलना चाह सकते हैं, या हो सकता है कि आप अपनी OGG फ़ाइलों को MP3, या समान में परिवर्तित कर लें। ffmpeg में परिदृश्यों की एक अंतहीन विविधता है, और समान रूप से समर्थित मोड और प्रारूपों की एक अंतहीन संख्या है। आम तौर पर, आप क्या करेंगे:

  • इनपुट फ़ाइल निर्दिष्ट करें।
  • इच्छित वीडियो और ऑडियो कोडेक निर्दिष्ट करें।
  • आउटपुट फ़ाइल निर्दिष्ट करें।

यदि आप वीडियो स्ट्रीम में हेरफेर नहीं करना चाहते हैं, तो आप कॉपी कोडेक का उपयोग कर सकते हैं। ऑडियो के लिए भी यही सच है। यदि आप कंटेनर को बदलना चाहते हैं तो आप इस विकल्प का उपयोग कर सकते हैं, जैसे वास्तविक एन्कोडिंग को बदले बिना MOV से MP4 में जाना।

ffmpeg -i MVI_1348.MOV -c:v copy -c:a copy new.mp4

नोट:सभी प्रारूप सभी कोडेक्स और विकल्पों का समर्थन नहीं करते हैं, इसलिए यह आवश्यक नहीं है कि यह सभी मामलों में काम करे। जैसे:

[mp4 @ 0x55a21519fb20] स्ट्रीम #0 में कोडेक vp8 के लिए टैग नहीं मिला, कोडेक वर्तमान में कंटेनर में समर्थित नहीं है
आउटपुट फ़ाइल #0 के लिए हेडर नहीं लिख सका (गलत कोडेक पैरामीटर?):अमान्य तर्क
स्ट्रीम मैपिंग:
स्ट्रीम #0:0 -> #0:0 (कॉपी)
स्ट्रीम #0:1 -> #0:1 (कॉपी)
अंतिम संदेश 1 बार दोहराया गया

यदि आप केवल एक निश्चित धारा - ऑडियो, वीडियो, उपशीर्षक, या डेटा निकालना चाहते हैं - तो आप अन्य धाराओं के प्रसंस्करण को दबा सकते हैं (ऑपरेशन के लिए आवश्यक समय और सीपीयू चक्रों को बचाने के लिए)। उदाहरण के लिए, यदि आप केवल एक संयुक्त ऑडियो-वीडियो मीडिया फ़ाइल से ऑडियो चाहते हैं, तो आप -vn (कोई वीडियो नहीं) विकल्प का उपयोग कर सकते हैं।

ffmpeg -i MVI_1348.MOV -vn -ar 44100 -ab 192k साउंड-ओनली.mp3

यह शानदार यूटिलिटी आपको चीजों को करने के तरीके में काफी लचीलापन देती है। उदाहरण के लिए, codec:v, vcodec और c:v समान हैं, और आप अपनी इच्छानुसार किसी का भी उपयोग कर सकते हैं। यदि आप केवल ऊपर की तरह एक ऑडियो आउटपुट चाहते हैं, तो ffmpeg अनुमान लगाएगा और मान लेगा कि आपका मतलब -vn भी है। आप आउटपुट स्वरूप को बाध्य करने के लिए -f ध्वज का भी उपयोग कर सकते हैं, लेकिन फिर से, उपकरण आपके आदेश से अंतिम परिणाम का अनुमान लगाने का प्रयास करेगा। उदाहरण के लिए, आप -f mp3 या acodec mp3 का उपयोग कर सकते हैं।

अलग-अलग कोडेक्स के अलग-अलग विकल्प होंगे। उदाहरण के लिए, एक ऑडियो फ़ाइल के लिए, आप ऑडियो सैंपलिंग दर और ऑडियो बिटरेट, चैनलों की संख्या और बहुत कुछ निर्दिष्ट कर सकते हैं। यदि आप कुछ विकल्पों को छोड़ देते हैं, तो आदेश विफल हो सकता है, या डिफ़ॉल्ट का उपयोग किया जाएगा।

पैमाना और गुणवत्ता

एक अन्य सामान्य कार्य वीडियो के आकार (रिज़ॉल्यूशन) और स्ट्रीम की गुणवत्ता को बदलना है। ffmpeg आपको यह विभिन्न तरीकों से करने देता है। आप अनुपात को बाध्य कर सकते हैं (और डिफ़ॉल्ट पहलू अनुपात को तोड़ सकते हैं), या इसे लंबवत या क्षैतिज मान और एक जादू क्वालीफायर निर्दिष्ट करके संरक्षित कर सकते हैं। आप वीडियो बॉर्डर क्रॉप कर सकते हैं, और आप स्ट्रीम को फिर से एनकोड कर सकते हैं। इस स्तर पर उदाहरणों की आवश्यकता है।

ffmpeg -i input.avi -c:v mpeg4 -vtag xvid -qscale:v 3 -c:a libmp3lame -qscale:a 4 output.avi

यहाँ क्या हो रहआ हैं? हम MPEG4 वीडियो स्ट्रीम का उपयोग करके एक AVI इनपुट फ़ाइल ट्रांसकोड कर रहे हैं, जिसकी गुणवत्ता 3 (qscale) पर सेट है। कुछ कोडेक्स के लिए, गुणवत्ता 1-31 के बीच होती है, जिसमें 1 उच्चतम होता है। मैंने कई सामान्य इनपुट फ़ाइलों पर परीक्षण किया, और उच्चतम गुणवत्ता के परिणामस्वरूप आम तौर पर लगभग दोगुना आकार हुआ, जबकि 3 या 4 ने लगभग 20-30% की कमी दी। Vtag xvid एक MPEG-4 विशिष्ट विकल्प है। Similarly, we're using LAME for audio.

ffmpeg -i MVI_1348.MOV -vfilters scale=1280:-1 -c:a copy scaled.mp4

This example shows video scaling (you can use -vf or -vfilters), with the aspect ratio being preserved through the -1 qualifier. We don't change the quality of the stream. The audio stream is simply being copied into the output container. If your original video has a higher resolution than the stated one, then you will be downscaling, and if it's lower, then you will be upscaling.

Image extraction, combination, GIFs

Ffmpeg can also manipulate pictures, even though it's a media utility. But hey, pictures are media, and essentially, videos are moving pictures, right! Some of the tasks you'd want - extract frames from a video in order to create thumbnails (high-quality ones, too) rather than manually pausing video or creating hectic screenshots. You can also do the opposite - combine stills into a stopmotion video - or a full one. You can also convert videos to animated GIFs, which can be handy for dank memeism around the Web. Once again, we shall demonstrate with some ... dank examples.

ffmpeg -i input.mp4 -r 1 -f image2 thumb-%3d.png

We specify an input file, we specify the rate (in this case we want 1 image per 1 second of video), we specify the format (image2), and we specify the output format. In this case, we're doing something clever. If you've ever seen C language code, this will look familiar. We want the numbering sequence for the thumbnails to have three digits. You can choose any amount of digits, but ideally, you want more than the expected number of extracted images.

ffmpeg के लिए एक गाइड - मल्टीमीडिया के लिए आपकी वन-स्टॉप शॉप

Then, combining images into a video is very similar:

ffmpeg -f image2 -i thumb-%3d.png stopmotion.mp4

You can also specify the rate (you want your video to be something like 24 or 30 FPS), but we will touch on this a bit more later in the guide, when we talk about making video playback slower and/or faster. And since we're talking about images, you can resize them too:

ffmpeg -i thumb-004.png -vf scale=400:-1 test.png

Animated GIFs are really interesting. Also rather simple to create. Just specify an input file and set the output to have a gif extension. Ffmpeg will auto-guess the rest and create nice, high-quality animated GIF for you.

ffmpeg -i MVI_6654.MOV test.gif

ffmpeg के लिए एक गाइड - मल्टीमीडिया के लिए आपकी वन-स्टॉप शॉप

Finally, the opposite of GIFs, you may also want to have a video composed of a single image - a constant preview but then have something like music or a podcast playing in the background. Ffmpeg allows you to do this with a clever trick.

ffmpeg -loop 1 -i thumb-001.png -i sound-only.mp3 -c:v libx264 -shortest video-static-image.mp4

We provide two inputs, with the first being an image set to loop. We're also re-encoding the video. But since the image is set to loop indefinitely, we also need the shortest option, so the operation ends when the shortest clip ends, which would be the video in this case.

Splitting and joining videos

This is another useful scenario. If you have a very big clip, but you only need a few minutes or seconds, ffmpeg can cut out the necessary pieces. Likewise, you can combine multiple files into one stream - both video and audio. Ffmpeg lets you choose the desired start and end timestamps, so you have a lot of leeway in how you do handle the task.

-t duration record or transcode "duration" seconds of audio/video
-to time_stop record or transcode stop time
-fs limit_size set the limit file size in bytes
-ss time_off set the start time offset
-sseof time_off set the start time offset relative to EOF
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time set the recording timestamp ('now' to set the
current time)

So, you may want to try something like:

ffmpeg -i MVI_1348.MOV -ss 4 -t 4 spliced.mp4

This command will extract 4 seconds from the input clip starting at time offset of 4 seconds into the clip. You can use short notation (4 indicates seconds) or use the full one hh:mm:ss.mmm. This gives you accuracy down to one millisecond, which ought to be more than enough for all practical usecases.

Joining files is a bit more complicated. Technically termed concatenation (concat), it works differently from the cutting option. You do not specify the desired parts you want to join on the command line, you put them into a file, using a very specific notation, and then read that file with ffmpeg. उदाहरण के लिए:

ffmpeg -f concat -i list.txt -codec copy joined.mp4

The contents of the list.txt file will be:

file 'part-1.mp4'
file 'part-2.mp4'
file 'part-3.mp4'

Please note the usage of the word file and single quotation marks. You can use both absolute and relative paths. If you make a mistake in the file format, you will see an error:

[concat @ 0x555ca89c38c0] Line 1:unknown keyword 'part-1.mp4'
list.txt:Invalid data found when processing input

If you try to provide the list of files on the command line (rather than the text file):

part-1.mp4:Invalid data found when processing input

Embed and extract subtitles

Remember my VLC &subtitles article? Well, if you're not intimidated by the command line, you can do the same thing with ffmpeg. As a trivial example, say you have separate audio and subtitle files. Without any additional processing, you can just use the video filtering option for this:

ffmpeg -i input.avi -vf subtitles=subtitle.srt output.avi

A more complicated use case, the command below will take separate MP4 and subtitle files, and combine them into an output file with video transcoding. The -map options (showing twice, not an error) define the order the streams will be mapped into the output. But then there's a clever and somewhat confusing listing of codecs. Because we have multiple streams, we only want to manipulate the video part - but not audio or subtitles.

To that end, -c copy specifies all codecs should be copied, but using -c:v provides an override to this option, and the video stream will be transcoded. Since we're using the libx264 codec, we're also using Constant Rate Factor (CRF) option for variable bitrate, set to 23 (ranges from lossless 0 to lowest-quality 51) and the veryfast preset, which creates a relatively small output.

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

Extracting subtitles takes the following form:

ffmpeg -txt_format text -i input.file out.srt

Speed up and slow videos

This is another interesting usecase. Like any human being, you may want to take any video, speed it up 2x and then add Benny Hill music, and there should be much rejoicing. You could also slow down action, and then, to spice things up, also add smoothing so the slowed sequence does not feel stilted.

For example, we may have our stop motion video - with only say 15-20 thumbnails, it takes only a second to play. So you may want to stretch it to say 5 seconds, but that means each frame will show for five times as long. Instead you could potentially "insert" extra frames to make it look like a smooth slo-mo. We did this with an interior design gallery back in the day. We use AviSynth and VirtualDub for this task.

The video speed filter works by changing the presentation timestamp (PTS) of each video frame. Simply put, fractional values speed up the video, multipliers higher than 1 slow it down. When you speed it up, ffmpeg will drop frames, but you can specify a higher framerate. To preserve the original, you can multiply the FPS in your input by the 1/PTS you're using. So if you double the speed of your 24FPS clip, you should use 48FPS rate.

ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" output.mp4

ffmpeg -i input.mp4 -r 96 -filter:v "setpts=0.25*PTS" output.mp4

ffmpeg -i input.mp4 -filter:v "setpts=2*PTS" output.mp4

Smoothing videos is more complicated. I did have to consult the documentation. Essentially, for a video that's slowed down 5 times (and 5 times longer than the original), I'm using video interpolation to create the smoothing effect. Here, too, you need to add FPS, so that ffmpeg has sufficient data to guess the frames in between. In my example, 5x slowed down, you need 5x24 FPS (original speed), ergo 120 FPS.

ffmpeg -i input.mp4 -filter:v "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120'" output.mp4

This is a CPU-intensive task, and it can take a while to finish. I used ffplay to preview videos, and I found the results reasonable, but you can't really magic something from nothing, so while this works, it works well when there's a small amount of data missing (not one frame per second every two seconds or such).

For audio, you can use atempo. This option has a range of 0.5-2.0, which means half or double the speed at most, however, it is possible to chain multiple atempo filters to get additional speed changes. Something like the example below:

ffmpeg -i input.mp4 -filter:a "atempo=2.0,atempo=2.0" -vn output.mp4

And that brings us to the end of this tutorial.

निष्कर्ष

I hope you found this fruitful, enjoyable and relevant. Ffmpeg is the workhorse - no, it's a whole cavalry - of audio and video tweaking in Linux, and it has so many practical tools, options and configurations that getting started can be confusing and maybe even intimidating. Those emotions should have evaporated by now as you've read through this tutorial.

Anyway, we talked about conversion and transcoding, scaling and quality, image extraction, combination and GIF creation, splitting and joining of videos, subtitle extraction and embedding, video speedup and slowdown, and then some. That should keep you happy and busy for a while. If you have any ffmpeg-related requests or questions, fire away, the email is only a click away. या कुछ और। Finally, if this tutorial was truly useful, do give some love back, because why not.

Cheers.


  1. अपने समय को कुशलतापूर्वक कैसे प्रबंधित करें इस पर एक संपूर्ण मार्गदर्शिका

    समय कीमती है और हम निश्चित रूप से इसके लिए पर्याप्त नहीं हो सकते हैं! हम में से अधिकांश लोग अक्सर अपने दैनिक कार्यों को पूरा करने के लिए संघर्ष करते हैं और इस बात से हताश हो जाते हैं कि समय कैसे बीत गया। कुंआ! यह लेख आपके लिए है यदि आप अपने समय प्रबंधन कौशल का समाधान तलाश रहे हैं। आज मनुष्य अपना अध

  1. ठीक करें - ऑडियो रेंडरर त्रुटि, कृपया अपने कंप्यूटर को पुनरारंभ करें

    YouTube वीडियो चलाते समय ऑडियो रेंडरर त्रुटि के कारण परेशान हैं? उत्तर को हां मानते हुए, आइए जानें कि आपकी विंडोज मशीन पर ऑडियो रेंडरर त्रुटियों को कैसे हल किया जाए। कई विंडोज़ उपयोगकर्ताओं ने YouTube त्रुटि का सामना करने की सूचना दी है, ऑडियो रेंडरर त्रुटि, कृपया अपने कंप्यूटर को पुनरारंभ करें।

  1. अपने सिस्टम पर ऑडियो फाइलों की खोज कैसे करें (2022 अद्यतन गाइड)

    सब कुछ डिजिटल होने के साथ, आपकी छवियां, किताबें, दस्तावेज़, ऑडियो और वीडियो अब आपके कंप्यूटर पर संग्रहीत हैं। इन हज़ारों फाइलों के बीच, कभी-कभी आपके ऑडियो/एमपी3 फाइलों का पता लगाना मुश्किल हो जाता है। यह मार्गदर्शिका अपने पीसी पर डिस्क एनालाइज़र प्रो का उपयोग करके ऑडियो फ़ाइलों को खोजने . की प्रक्रि