उदाहरणों से FFmpeg सीखें
(ffmpegbyexample.com)- FFmpeg के काम में option combinations अक्सर जटिल हो जाते हैं, लेकिन FFmpeg By Example एक ऐसा documentation site है जो असली command examples के जरिए ज़रूरी media processing तरीकों को जल्दी ढूंढने में मदद करता है
- इसमें GitHub repository, Discord community और contribution page भी दिए गए हैं, ताकि उपयोगकर्ता FFmpeg के नए उपयोग ideas को खुद submit कर सकें
testsrcfilter example की तरह, यह input source, resolution, frame rate और output file को एक ही command में दिखाता है, ताकि command structure को वैसे का वैसा follow किया जा सके- examples में bitrate calculation, image resize, audio noise reduction, transition effects, stream mapping, hardware acceleration, metadata processing जैसे media processing tasks का व्यापक दायरा शामिल है
- हर example tag और अलग page में बंटा हुआ है, इसलिए किसी खास filter या conversion उद्देश्य के आधार पर ज़रूरी FFmpeg command खोजना आसान है
उदाहरण-केंद्रित FFmpeg documentation site
- FFmpeg By Example एक वेबसाइट है जो FFmpeg इस्तेमाल करने के अलग-अलग तरीकों को example-आधारित रूप में व्यवस्थित करती है
- community participation और contribution के लिए links भी साथ में दिए गए हैं
testsrc test video generation example
- Generate test video color pattern with 'testsrc' filter
testsrcfilter से test color pattern video बनाने का example है - यह command lavfi input के साथ 10 सेकंड, 1280x720, 30fps वीडियो
testsrc.mpgके रूप में बनाती है
ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 testsrc.mpg
encoding, conversion और hardware acceleration
- video encoding और format conversion से जुड़े examples शामिल हैं
- Recode Your Video With a Modern Codec, Often Saving Space: H.265 encoding example
- Convert Video to Telegram Video Sticker Format (512px Max, 256KB Limit): Telegram video sticker format conversion example
- Use Intel QuickSync Video Hardware Acceleration for Transcoding Video: Intel QuickSync Video hardware-accelerated transcoding example
audio processing
- noise removal, normalization, conversion और extraction जैसे आम audio tasks को examples के जरिए देखा जा सकता है
- Audio Noise Reduction Using Arnndn:
arnndnका उपयोग करके audio noise reduction - Normalize Audio to EBU R128 Loudness Standard (-23 LUFS): EBU R128 मानक के अनुसार
-23 LUFSnormalization - Convert Wav to Mp3 File: WAV को MP3 में convert करना
- Extract an AAC Audio Track From a Video File: video file से AAC audio track extract करना
- Audio Noise Reduction Using Arnndn:
images और animation
- static image processing से लेकर WebP animation generation तक, image-based workflows भी शामिल हैं
- Resize PNG Images While Preserving Transparency and Aspect Ratio: transparency और aspect ratio बनाए रखते हुए PNG resize
- Generate Looping WebP Animation From Image Sequence With Variable Quality: image sequence से looping WebP animation बनाना
- Slow Animated WebP Image Sequence (Carousel): धीमे animated WebP image sequence का example
filters और visual effects
- FFmpeg filters का उपयोग करके animation, transitions और text effects के examples व्यवस्थित किए गए हैं
- Animate an Image Using Zoompan Filter:
zoompanfilter से image animation बनाना - XFade Video Transitions Examples:
xfadeआधारित transition effects - Video Echo Effect With Delay and Hue Using Lagfun:
lagfunसे delay और hue change वाला video echo effect - Fade in and Out Text Using the 'Drawtext' Filter:
drawtextfilter से text fade in/out - "Drawtext" and "Drawbox" Using "Sendcmd" Manifest:
sendcmdmanifest सेdrawtextऔरdrawboxका उपयोग
- Animate an Image Using Zoompan Filter:
extraction, analysis और metadata
- file से ज़रूरी streams निकालना या frames और metadata का analysis करना जैसे काम भी शामिल हैं
- Extract Audio From Video Files With Stream Mapping: stream mapping के जरिए video file से audio extract करना
- Extract Multiple Video Clips From Single Input With Precise Timestamps: एक input से सटीक timestamps के साथ कई clips extract करना
- Analyze Video Frames, Timecode and Metadata With Showinfo Filter:
showinfofilter से frame, timecode और metadata analysis - Getting Streams Information of a Video File: video file की stream information देखना
- Copy Metadata From One Mp3 to Another: एक MP3 से दूसरे में metadata copy करना
generated sources और output pipes
- test source generation, individual frame recording और STDOUT output जैसे automation या debugging में उपयोगी examples भी दिए गए हैं
- Generate Solid Color Video With Custom Hex Color Code: custom Hex color code से solid color video बनाना
- Create SMPTE Color Bars With Centered Text Overlay: SMPTE color bars और centered text overlay बनाना
- Generate "Game of Life" Video Using Lavfi Video Source:
lavfivideo source से Game of Life video बनाना - Print a Data Channel to STDOUT Using Ffmpeg: data channel को STDOUT पर print करना
- Record a Video From Individual Frames: individual frames से video record करना
1 टिप्पणियां
Hacker News टिप्पणियां
ffmpeg इस्तेमाल करने का मज़ा 1000% बढ़ गया है
पहले Google पर Stack Overflow के जवाब ढूंढकर उन्हें जोड़ते हुए बोरिंग तरीके से command बनानी पड़ती थी, अब ChatGPT मेरे लिए command लिख देता है, इसलिए काम बहुत आसान हो गया है
LLM की वजह से मैं ffmpeg हफ्ते में कई बार इस्तेमाल करता हूं
मेरे
llm cmdtool का सबसे अच्छा use case यही है:uv tool install llmllm install llm-cmdllm cmd use ffmpeg to extract audio from myfile.mov and save that as mp3https://github.com/simonw/llm-cmd
लंबे समय तक मैंने ffmpeg को regex जैसी ही एक category में रखा था: “इसे सच में सीखना चाहिए, लेकिन शायद मुझे इससे बहुत नफरत हो जाएगी” वाली feeling थी
फिर ChatGPT आया और दोनों समस्याएं हल कर दीं
मेरे साथ भी यही है। इस तरह का काम AI ने पूरी तरह संभाल लिया है, और मैं बस error trace को copy-paste करने वाला mediator भर हूं
दूसरे tools भी काफी आ गए हैं, लेकिन मैंने अभी-अभी एक script बनाई है जो ऐसी chained commands को काफी सरल कर देती है: llmpeg https://github.com/jjcm/llmpeg
अगर ffmpeg installed है और OpenAI environment variable API key set है, तो यह तुरंत काम करेगी
Demo: https://image.non.io/1c7a92ef-0917-49ef-9460-6298c7a9116c.we...
complex filters कैसे काम करते हैं, यह सीखने के बाद ffmpeg इस्तेमाल करने का अनुभव और बेहतर हो गया
यह खयाल आया कि digital की गई घरेलू videotapes को scene detection से clips में बदलने का तरीका लिखकर publish करना चाहिए
कोई search कर सकता है, इसलिए वह gist छोड़ रहा हूं जो काफी अच्छी तरह काम करती थी [0]. हालांकि camera flash या shake से यह कभी-कभी धोखा खा जाती थी, इसलिए start/end files अलग से देकर उन्हें ffmpeg से फिर जोड़ना पड़ता था [1]
अजीब बात यह थी कि latest Mac update में
-c:v h264_videotoolboxके बिना performance बेहतर थी। हो सकता है यह Sequoia में performance regression हो, पर पक्का नहीं। Nvidia GPU वाली Windows machine पर corresponding flag-c:v h264_nvencहै। सोचता हूं ffmpeg इसे auto-detect क्यों नहीं करता। इससे करीब 8x performance boost मिलाकंपनी में सच में अपनी salary justify करने का एकमात्र पल वह था, जब video processing के लिए GPU वाले cloud server पर महंगा extra खर्च करने ही वाले थे और मैंने पाया कि installed ffmpeg GPU acceleration के बिना compile किया गया था
[0] https://gist.githubusercontent.com/nielsbom/c86c504fa5fd61ae...
[1] https://gist.githubusercontent.com/jazzyjackson/bf9282df0a40...
cloud CPU की समस्या यह है कि उनमें consumer CPU में मिलने वाला hardware video encoder नहीं होता, इसलिए आपको कहीं ज्यादा महंगी GPU machine पर जाना पड़ता है
सच कहूं तो cloud में hardware acceleration इस्तेमाल करके ठीक से price comparison नहीं किया है, लेकिन जानना चाहता हूं कि क्या आपका मतलब है कि आपने वास्तव में ऐसा किया और cost के हिसाब से ठीक लगा
ffmpeg से blank scene detection आजमाया था
मेरे पास SFO flight path की ओर aimed camera है, और जब motion-less frames हटा दिए, तो boring हिस्सों के बिना सिर्फ planes के गुजरने की continuous video बची
-c:v h264_nvencकई videos को एक साथ encode करने वाली batch encoding के लिए उपयोगी है। क्योंकि इससे encoding throughput बढ़ाया जा सकता हैहालांकि पहले limited experiments में output quality libx264 से थोड़ी खराब थी। कोई workaround है या नहीं, नहीं जानता, लेकिन ऐसा सिर्फ मेरे साथ नहीं हुआ था
ffmpeg इसे auto-detect नहीं करता क्योंकि hardware encoding में आम तौर पर settings की range कम होती है, refined software codecs की तुलना में compromises ज्यादा होते हैं, और वही parameters देने पर भी बिल्कुल वही result नहीं मिलता
ऊपर से, system में अक्सर चुनने के लिए कई hardware APIs होती हैं, और उनकी capabilities भी अलग-अलग होती हैं
FFmpeg एक complex command-line tool है और उन users के लिए है जो details सीखने को तैयार हैं, इसलिए assumptions के आधार पर defaults तय करना सही है या नहीं, मुझे नहीं पता
snippet देखकर लगता है कि deinterlace नहीं किया जा रहा
अगर digitization से पहले clips पहले से deinterlace किए गए हैं तो ठीक है, लेकिन नहीं तो interlaced material को progressive में encode करते हुए quality खराब कर रहे होंगे।
bwdiffilter जोड़कर देखें ताकि 30i content 60p में encode हो। यह original videotape के ज्यादा करीब दिखेगासमय के साथ मैं ffmpeg के कई हिस्सों से काफी परिचित हो गया हूं। CLI की अपनी logic है, और यह order-dependent है। हर Unix CLI ऐसा नहीं होता
हाल ही में कुछ ज्यादा obscure features के साथ experiment कर रहा हूं। उदाहरण के लिए, एक काफी slow machine पर video camera की raw footage सीधे save करना। मैंने microscope बनाया है और camera से 120FPS पर raw video format (YUYV 1280x720) frames पढ़ता हूं, लेकिन उन्हें जैसे-का-तैसा disk पर save करने से यह प्रति मिनट gigabytes तक बढ़ जाता है। Disk सस्ती है, पर यह waste जैसा लगा, इसलिए मैंने exact images को तेजी से compress करके save करने की लगभग lossless techniques देखीं
पता चला कि ffmpeg में RGB24 conversion बहुत slow है, इसलिए command line के साथ काफी छेड़छाड़ करने के बाद मैं इस पर settled हुआ:
ffmpeg -f rawvideo -pix_fmt yuyv422 -s 1280x720 -i test.raw -vcodec libx264 -pix_fmt yuv420p movie.mp4 -crf 13 -yकच्चे वीडियो में container नहीं होता, इसलिए उसमें “pixel format” या “image size” जैसे metadata नहीं होते; इन्हें खुद देना पड़ता है। यह order-dependent है, इसलिए
-i test.rawसे पहले की हर चीज़ input decoding के लिए होती है, और उसके बाद की हर चीज़ output लिखने के लिए। बस एक बहुत छोटा pixel format conversion किया जाता है (ffmpeg इसे बहुत तेज़ी से कर सकता है), और डेटा को container वाले लगभग lossless format में लिखा जाता है। ज़्यादातर मामलों में container के लिए.mkvसबसे अच्छा लगाcommand line पसंद नहीं थी, इसलिए आखिरकार ffmpeg-python इस्तेमाल किया, और नीचे के code से command line assemble करवाई:
self.process = (ffmpeg.input("pipe:",format="rawvideo",pix_fmt="yuyv422",s="{}x{}".format(1280, 720),threads=8).output(fname, pix_fmt="yuv422p", vcodec="libx264", crf=13).overwrite_output().global_args("-threads", "8").run_async(pipe_stdin=True))और असल में उस process के standard input में frames को
write()करता हूँ। मशीन में 12 cores हैं और microscope चलाने में हमेशा कम से कम 2 cores लगते हैं, इसलिए thread count को limit करना पड़ाअब भी बेहतर और तेज़ lossless YUV encoding ढूंढ रहा हूँ
order-dependent होना ठीक है। Unix pipelines भी components के order पर निर्भर करती हैं, और complex FFMpeg calls कुछ वैसा ही काम करती हैं
बहुत लोगों को
ffmpeg-pythonजैसी “fluent interface” aesthetics पसंद आती है, लेकिन Python में इसे अक्सर Pythonic नहीं माना जाता। मेरी समझ में ffmpeg-python को command line order को करीब से reflect करने के लिए design किया गया हैstandard library और built-in type design जिस preference को मजबूत करते हैं, वह strong https://en.wikipedia.org/wiki/Command%E2%80%93query_separati... है। इस principle के हिसाब से यह मोटे तौर पर ऐसा दिखेगा:
ffmpeg(global_args=..., overwrite_output=True).process_async(piped_input(...), output(...))input को अलग composition process बनाने से अलग runtime type बनेगा, और processing code को भी signal दिया जा सकेगा कि standard input से पढ़ना है
और ढूंढने की ज़रूरत नहीं: FFV1 https://trac.ffmpeg.org/wiki/Encode/FFV1
मैं सिर्फ एक शब्द recommend करना चाहूँगा: ramdisk
अगर intermediate processing करनी है, लेकिन files को रखना नहीं चाहते, तो ramdisk ही है। सच में बहुत अच्छा
मुझे लगा था यह FFmpeg experts द्वारा जमा किए गए knowledge को curate करने वाली website होगी, लेकिन पहले ही example पर click करते ही निराशा हुई
https://www.ffmpegbyexample.com/examples/l1bilxyl/get_the_du...
string processing के लिए दो और tools call नहीं करने चाहिए। FFprobe अकेला ही duration या जो value चाहिए, सीधे दे सकता है:
ffprobe -loglevel quiet -output_format csv=p=0 -show_entries format=duration video.mp4पहली working चीज़ पर रुकना नहीं चाहिए; काम चलने के बाद सोचना चाहिए कि इसे और बेहतर कैसे किया जा सकता है
फिर भी आपका solution मुझे ज़्यादा पसंद है
अच्छा है। मुझे अपनी ffmpeg cheatsheet याद आ गई। जो लोग ffmpeg अक्सर इस्तेमाल करते हैं, उनके पास शायद ऐसी ही notes की collection होती होगी
https://github.com/fastily/cheatsheet/blob/master/ffmpeg.md
https://github.com/ericfortis/quick-reference/blob/main/ffmp...
FFmpeg उन tools में से है जिन्हें मैं इतनी कम बार इस्तेमाल करता हूँ कि exact syntax कभी दिमाग में नहीं रहती। आखिर में जो command line चाहिए होती है, वह LLM से लिखवा लेता हूँ
इसी तरह मुश्किल लगा एकमात्र tool LSI Logic का 1990s-style MegaCLI था। उसे भी साल में मुश्किल से इस्तेमाल करता था, लेकिन pressure में बिल्कुल सही लिखना पड़ता था
मैं 15 साल से ज़्यादा समय से FFMPEG इस्तेमाल कर रहा हूँ, लेकिन अब भी commands लगभग याद नहीं रहतीं। फिर भी FFMPEG के लिए LLM सच में कमाल है
ChatGPT और Claude से कहें, “video को mkv में remux करो, subtitle.srt को file में include करो, और सिर्फ 0:00:05 से 0:01:00 तक चाहिए”, तो वे बहुत अच्छा handle कर देते हैं। अगर उत्सुक हों, result यह था:
ffmpeg -i input.mp4 -i subtitle.srt -ss 00:00:05 -to 00:01:00 -map 0 -map 1 -c copy -c:s mov_text output.mkvसोचता हूँ कि अगर goal सिर्फ ffmpeg commands generate करना हो, तो कितना छोटा LLM बनाया जा सकता है। शायद इतना छोटा कि static webpage पर डालकर local में run किया जा सके?
15 साल से मैं अपनी अक्सर इस्तेमाल होने वाली syntax वाली personal notes document maintain कर रहा हूँ। फिर भी बात न बने तो bash history में
grepकरता हूँमेरे साथ भी यही है। दिमाग में बस इतना रहता है कि format X से
.mp4में बदलना है। बाकी हर बार फिर से खोजनी पड़ती हैसंबंधित XKCD https://xkcd.com/1168/
कुछ दिन पहले आधे मज़ाक और आधे गंभीर होकर कहा था कि अगर LLM मुझे मेरे मनचाहे ffmpeg flags बता दे, तो शायद पूरे rainforests जला देना भी उसके लायक हो सकता है
यह नहीं भूलना चाहिए कि GStreamer भी मौजूद है। यह pipeline-based है, इसलिए command line और documentation ffmpeg की तुलना में थोड़े ज़्यादा समझने लायक हैं, और composability भी थोड़ी ज़्यादा sane है
मैं भारी video कामों में ffmpeg पूरी तरह छोड़कर सिर्फ GStreamer इस्तेमाल करता हूँ
लेकिन one-off tasks के लिए ffmpeg कहीं ज़्यादा friendly लगता है। उदाहरण के लिए, ffmpeg में reasonable x264 defaults हैं, लेकिन
gst-launchसे अच्छी quality वाली x264 encoding करने के लिए सच में पता होना चाहिए कि आप क्या कर रहे हैंsources, sinks और transform filters के जटिल graphs बनाए जा सकते हैं
इस site को complement करने के लिए एक अच्छा ffmpeg book GitHub repository है:
https://github.com/jdriselvato/FFmpeg-For-Beginners-Ebook
ffmpeg हमेशा ऐसा लगा है जैसे एक GUI application को TUI format में जबरन ठूंस दिया गया हो
C API भी मैंने कुछ बार unpleasant तरीके से इस्तेमाल की है; कई मायनों में intuitive है, लेकिन invalid states को represent करना बहुत आसान है। काश कोई ऐसा real-time AV1 encoding framework हो जो “बस काम कर जाए”
यह लगभग इकलौता tool है जिसके लिए मैं default रूप से पहले GUI alternative HandBrake खोजता हूँ। exception सिर्फ batch processing के समय है
कुछ pure ffmpeg GUIs भी हैं। video work में command line मेरे दिमाग की processing style से somehow मेल नहीं खाती
API के लिए मैं GStreamer recommend कर सकता हूँ। Rust bindings इस्तेमाल किए हैं, इसलिए C API से बहुत परिचित नहीं हूँ, लेकिन अच्छी लगी
GObject की वजह से कुछ हिस्से verbose हो जाते हैं, लेकिन समझ आ जाने के बाद API के सभी objects के साथ consistent तरीके से interact किया जा सकता है। जरूरी complexity वाकई बहुत है (video कठिन है), लेकिन design, implementation और documentation काफी अच्छे हैं
आम use cases के लिए Bins(
decodebin,transcodebin,playbin) चीज़ों को काफी आसान बना देते हैं। ज़्यादा complex use cases भी design की flexibility की वजह से possible हैंinsight पसंद आई, लेकिन TUI कोई graphical चीज़ होती है और ffmpeg तो सिर्फ CLI है
अगर कोई TUI tool हो तो बढ़िया होगा। https://github.com/Twinklebear/fbed जैसा, लेकिन ज्यादा complete features के साथ
Linux systems पर मुझे ffmpeg को static build करना पसंद है। क्योंकि distribution version कभी-कभी बहुत पुराना होता है या पसंदीदा modules missing होते हैं
यह containerized version बहुत useful रहा: https://github.com/wader/static-ffmpeg