9 पॉइंट द्वारा GN⁺ 2025-01-15 | 1 टिप्पणियां | WhatsApp पर शेयर करें
  • FFmpeg के काम में option combinations अक्सर जटिल हो जाते हैं, लेकिन FFmpeg By Example एक ऐसा documentation site है जो असली command examples के जरिए ज़रूरी media processing तरीकों को जल्दी ढूंढने में मदद करता है
  • इसमें GitHub repository, Discord community और contribution page भी दिए गए हैं, ताकि उपयोगकर्ता FFmpeg के नए उपयोग ideas को खुद submit कर सकें
  • testsrc filter 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 testsrc filter से 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

audio processing

images और animation

filters और visual effects

extraction, analysis और metadata

generated sources और output pipes

1 टिप्पणियां

 
GN⁺ 2025-01-15
Hacker News टिप्पणियां
  • ffmpeg इस्तेमाल करने का मज़ा 1000% बढ़ गया है
    पहले Google पर Stack Overflow के जवाब ढूंढकर उन्हें जोड़ते हुए बोरिंग तरीके से command बनानी पड़ती थी, अब ChatGPT मेरे लिए command लिख देता है, इसलिए काम बहुत आसान हो गया है

    • LLM की वजह से मैं ffmpeg हफ्ते में कई बार इस्तेमाल करता हूं
      मेरे llm cmd tool का सबसे अच्छा use case यही है:

      uv tool install llm
      llm install llm-cmd

      llm cmd use ffmpeg to extract audio from myfile.mov and save that as mp3

      https://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 खराब कर रहे होंगे। bwdif filter जोड़कर देखें ताकि 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 चीज़ पर रुकना नहीं चाहिए; काम चलने के बाद सोचना चाहिए कि इसे और बेहतर कैसे किया जा सकता है

    • original post का author हूँ। इसे “crazy” कहना थोड़ा overstatement लगता है
      फिर भी आपका solution मुझे ज़्यादा पसंद है
  • अच्छा है। मुझे अपनी ffmpeg cheatsheet याद आ गई। जो लोग ffmpeg अक्सर इस्तेमाल करते हैं, उनके पास शायद ऐसी ही notes की collection होती होगी
    https://github.com/fastily/cheatsheet/blob/master/ffmpeg.md

  • 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 इस्तेमाल करता हूँ

    • Programming के ज़रिए pipelines बनाते समय GStreamer ज़्यादा control और friendly API दे सकता है
      लेकिन one-off tasks के लिए ffmpeg कहीं ज़्यादा friendly लगता है। उदाहरण के लिए, ffmpeg में reasonable x264 defaults हैं, लेकिन gst-launch से अच्छी quality वाली x264 encoding करने के लिए सच में पता होना चाहिए कि आप क्या कर रहे हैं
    • मुझे लगा था FFmpeg भी pipeline-based है। उसमें filter graph होते हैं, है न? क्या मैं कुछ miss कर रहा हूँ
      sources, sinks और transform filters के जटिल graphs बनाए जा सकते हैं
    • GStreamer किसी abandoned project जैसा महसूस होता है। हाल ही में एक बड़ा vulnerability भी था और documentation भी काफी टूटी-फूटी है
  • इस 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