Convert videos, audio and image sequences quickly and efficiently.

本文介绍了一系列FFmpeg实用命令,涵盖视频编码、音频提取、视频拼接等操作,帮助读者快速掌握这一强大的多媒体处理工具。
部署运行你感兴趣的模型镜像

Ok, sometimes you need a quick way to convert image sequence to video clip, join clips, rip audio, mux audio from other clip, deinterlace footage (anybody still shooting interlaced videos? yeah, I need a new camcorder) and do that with minimal quality loss or even without re-encoding.

The way I do this is the ffmpeg way, and the x264 way. Even though not everyone favour the format, it’s ok for simple tasks. And, yeah, it’s command line way – the fastest way.

Good news is, once you get a grasp of it, you will better understand all of the GUI’s frontends that use ffmpegs, mencoders etc. anyway for actually doing all the work behind. No, that doesn’t sound funny.

All of the commands are one-liners, just so you know. Let’s go:


FIRST, SIMPLY ENCODE A FILE

ffmpeg -i InputFile -c:v libx264 -preset ultrafast -crf 0 Output.mp4

This line means you want to encode a lossless file as fast as possible, good for batch jobs etc. but also with the biggest file sizes. You can get around that with single switch from -preset ultrafast to -preset veryslow, which means the same quality (because the -crf 0 parameter means lossless output), but better compression – you just contribute a little more time for the task.

And if you ever need real compression, just tweak the -crf 0 parameter to -crf 18 (that is near to lossless visually, but provides real gain in terms of file size; this value is good for final footage):

ffmpeg -i inputFile -c:v libx264 -preset veryslow -crf 18 Output.mp4


IMAGE SEQUENCE TO A FILE

ffmpeg -r 25 -i frame%04d.png -vcodec libx264 -crf 18 Output.mp4

This -i (input file) switch assumes, your files are named in convention:frame0000.png, frame0001.png, etc. You get that just using the prefix (“frame” in this case) and the number of digits (4 in this case, passed as “%04d“).

In case your frames start from number of – lets say 70 – then you need to pass this information as well:

ffmpeg -r 25 -start_number 70 -i frame%04d.png -vcodec libx264 -crf 18 Output.mp4

The -r 25 switch means output will play at 25 frames per second.


IMAGE SEQUENCE TO A SPRITESHEET (MAY BE VIDEO AS WELL)

ffmpeg -skip_frame nokey -i sequence_%04d.png -vf 'tile=8x8' -an -vsync 0 spritesheet.png

If you have image sequence that would look nice in a game, you want to create a sprite sheet. With this example 8×8 grid is created and ready to import to Unity3D for example.


VIDEO TO AN IMAGE SEQUENCE

ffmpeg -i InputFile -an -f image2 "frame%05d.jpg"

Of course, if you plan to re-encode the sequence to video or any other job, it’s better to use lossless format, like png.


JOIN MULTIPLE CLIPS WITHOUT RE-ENCODING

ffmpeg -f concat -i FileList.txt -c copy Output.mp4

Just create a FileList.txt text file that looks like this:
file '/path/file1'
file '/path/file2'
file '/path/file3'

These can be either relative or absolute paths. If your clips have the same parameters you can join them without re-encoding (-c copy switch), however if they vary in parameters or codecs, you can still join them, but you need to encode the output file:

ffmpeg -f concat -i FileList.txt -c:v libx264 -preset veryslow -crf 18 Output.mp4


CUT CLIPS WITHOUT RE-ENCODING

ffmpeg -i InputFile -ss 00:00:30.0 -c copy -t 00:00:10.0 -async 1 Output.mp4

Simply cuts a 10-second long clip, starting at 30.0s time.

-ss seeks to time,

-t output clip length.


BATCH CONVERT ALL FILES IN DIRECTORY (LINUX)

for vid in *.MTS; do ffmpeg -y -i "$vid" -c:v libx264 -preset veryslow -crf 18 -c:a libfdk_aac -b:a 196k "${vid%.MTS}.mp4"; done

This may look intimidating but is as simple as the previous ones. Only this one iterates through all files in directory that have .MTS extension and compresses them individually into files of the same name, but with .mp4 extension. Also compresses audio into AAC 196k bitrate format. If you don’t need to compress audio, but simply copy  audio to output, just use -c:a copy switch instead.


BATCH CONVERT ALL FILES IN DIRECTORY (WINDOWS)

for %%f in (*.MTS) do ffmpeg -i %%f -c:v libx264 -preset veryslow -crf 18 %%f.mp4
pause

If used from a command line and not a .bat file simply switch “%%f” with a “%f”. Pause is just to keep the terminal window opened on finish, to review encoding process.


RIP AUDIO STREAM TO AN .MP3

ffmpeg -i InputFile -ab 192k -ac 2 -ar 48000 -vn audio.mp3

Quite self explanatory: -ab is a bitrate, -ac channel number (2 for stereo), -arsampling frequency.


MUX AUDIO FROM ONE VIDEO TO ANOTHER WITHOUT RE-ENCODING

From an .mp3 file:

ffmpeg -i AudioInputFile -i VideoInputFile -c copy -map 0:a:0 -map 1:v:0 -c:a copy Output.mp4

From another video clip:

ffmpeg -r 25 -i InputVideoFileWithAudioSource -i InputVideoFileThatNeedsAudio -c copy -map 0:a:0 -map 1:v:0 -c:a copy -shortest Output.mp4

-map switch copies first audio stream from the InputVideoFileWithAudioSource (file can have multiple audio streams) and video stream from the InputVideoFileThatNeedsAudio and combines them into Output.mp4. All without re-encoding.

-r switch is for framerate,

-shortest switch means that output will have length of the shorter input file.


DESHAKE VIDEO

ffmpeg -i InputFile -vf deshake Output.mp4

Just a simple video filter that will deshake (or try at least) your clip a little. There are better filters for that, but the deshake filter will get the job done with the simplest cases.


DEINTERLACE A VIDEO

So my camcorder shoots 1080i video, which means interlaced footage. I decided to get something out of it and convert 1080i 25 fps video to, 720p 50fps video:

ffmpeg -i InputFile -filter:v yadif=1 -s "1280x720" -sws_flags spline -r 50 -c:a libfdk_aac -b:a 196k -c:v libx264 -preset veryslow -crf 18 Output.mp4

Filter yadif=1 uses top and bottom field as separate frames, which means double fps,

-s is an output footage resolution,

-sws_flags spline is a filter for upscaling a vid (1080i frame is actually a 1920×540 frame size, interlacing top and bottom fields line by line) that returns best quality from my experience,

-r as always means framerate.

These are just most common tasks with the ffmpeg Ido.

Command line may be intimidating, but once you get a hang of it, it gets the job done insanely fast.

And while this is no news by any means, it’s good to have cheat sheet with all of the most common tasks listed in one place.

Something extra that I find using a lot: rip stills from an interlaced footage:

ffmpeg -i 00034.mts -filter:v yadif=1 -s "1280x720" -sws_flags spline -r 5 -q:v 1 -an -f image2 "frame%05d.jpg"

-r is fps, which means 5 frames every second for 25fps footage.

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

内容概要:本文系统阐述了企业新闻发稿在生成式引擎优化(GEO)时代下的全渠道策略与效果评估体系,涵盖当前企业传播面临的预算、资源、内容与效果评估四大挑战,并深入分析2025年新闻发稿行业五大趋势,包括AI驱动的智能化转型、精准化传播、首发内容价值提升、内容资产化及数据可视化。文章重点解析央媒、地方官媒、综合门户和自媒体四类媒体资源的特性、传播优势与发稿策略,提出基于内容适配性、时间节奏、话题设计的策略制定方法,并构建涵盖品牌价值、销售转化与GEO优化的多维评估框架。此外,结合“传声港”工具实操指南,提供AI智能投放、效果监测、自媒体管理与舆情应对的全流程解决方案,并针对科技、消费、B2B、区域品牌四大行业推出定制化发稿方案。; 适合人群:企业市场/公关负责人、品牌传播管理者、数字营销从业者及中小企业决策者,具备一定媒体传播经验并希望提升发稿效率与ROI的专业人士。; 使用场景及目标:①制定科学的新闻发稿策略,实现从“流量思维”向“价值思维”转型;②构建央媒定调、门户扩散、自媒体互动的立体化传播矩阵;③利用AI工具实现精准投放与GEO优化,提升品牌在AI搜索中的权威性与可见性;④通过数据驱动评估体系量化品牌影响力与销售转化效果。; 阅读建议:建议结合文中提供的实操清单、案例分析与工具指南进行系统学习,重点关注媒体适配性策略与GEO评估指标,在实际发稿中分阶段试点“AI+全渠道”组合策略,并定期复盘优化,以实现品牌传播的长期复利效应。
【EI复现】基于主从博弈的新型城镇配电系统产消者竞价策略【IEEE33节点】(Matlab代码实现)内容概要:本文介绍了基于主从博弈理论的新型城镇配电系统中产消者竞价策略的研究,结合IEEE33节点系统进行建模与仿真分析,采用Matlab代码实现。研究聚焦于产消者(兼具发电与用电能力的主体)在配电系统中的竞价行为,运用主从博弈模型刻画配电公司与产消者之间的交互关系,通过优化算法求解均衡策略,实现利益最大化与系统运行效率提升。文中详细阐述了模型构建、博弈机制设计、求解算法实现及仿真结果分析,复现了EI期刊级别的研究成果,适用于电力市场机制设计与智能配电网优化领域。; 适合人群:具备电力系统基础知识和Matlab编程能力,从事电力市场、智能电网、能源优化等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①学习主从博弈在电力系统中的建模方法;②掌握产消者参与电力竞价的策略优化技术;③复现EI级别论文的仿真流程与结果分析;④开展配电网经济调度与市场机制设计的相关课题研究。; 阅读建议:建议读者结合提供的Matlab代码,深入理解博弈模型的数学表达与程序实现细节,重点关注目标函数构建、约束条件处理及算法收敛性分析,可进一步拓展至多主体博弈或多时间尺度优化场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值