Showing posts with label ffmpeg. Show all posts
Showing posts with label ffmpeg. Show all posts

Tuesday, 14 January 2025

Win Bat 批处理带货切片


有的小伙伴需要把我之前一个视频切片的批处理文件变成windows可用的bat文件。文件名字qiepian.bat,代码如下:

```

@echo off


:: Define variable

set SOME_VAR=C:\cygwin\path


:: Remove directory if it exists

if exist "%SOME_VAR%" (

    rd /s /q "%SOME_VAR%"

) else (

    echo "file not found"

)


:: Copy a file

copy /y "C:\some\file" "C:\to\another\file"


:: Check if variable is empty

if "%SOME_VAR%"=="" (

    echo "SOME_VAR is empty"

) else (

    echo "SOME_VAR not empty"

)


:: Define a function

call :my_function

call :my_function "some param"

goto :eof


:my_function

echo hello from my_function: %~1

goto :eof

```

运行也简单,这样就好: qiepian.bat 

Sunday, 12 January 2025

ffmpeg一键切片,带货切片视频so easy - ffmpeg One-Click Slicing, E-commerce Videos So Easy

手残党福音!一行命令搞定带货切片,躺着也能赚!- For the Clumsy! One Command to Create Product Clips, Earn While You Relax!

还在苦哈哈地手动剪辑带货视频?还在对着冗长的直播录像抓耳挠腮,不知道哪段能成爆款?别愁了!ffmpeg来拯救你!这可是个免费又强大的神器,能帮你一键切片,快速生成带货短视频,简直不要太爽!


为啥要用ffmpeg切片?因为咱普通人做带货,爆款这玩意儿,说白了就是撞大运。与其花大把时间在那儿精雕细琢,不如广撒网多捞鱼,多切几个视频上传,说不定哪个就火了呢?用ffmpeg切片,效率高到飞起,省下来的时间可以用来刷剧、带娃、甚至发呆,岂不美哉?(土豪请随意,咱比不了~)


想用ffmpeg切片,就得用到它的“segment”功能。中庸之道,截弯取直,直接上命令:

```

ffmpeg -i {theVideoName}.mp4 -c copy -map 0 -f segment -segment_time {how_many_seconds} -segment_list video-list.txt -reset_timestamps 1 {theVideoName}-%03d.mp4
```

看不懂?没关系,我来给你掰开了揉碎了讲:


{theVideoName}.mp4:就是你的原视频文件名。

{how_many_seconds}:你想切成多长的视频,单位是秒。比如15秒就填15,4分钟就填240。

-c copy:这是重点!直接复制视频流,不重新编码,速度快到你怀疑人生,而且画质无损!

-map 0:确保视频里的声音也一起切进去。

-segment_time:设置切片时长。

-segment_list video-list.txt:生成一个文件,记录切片信息,以后想合并视频就靠它。

-reset_timestamps 1:让每个切片的时间都从0开始。

运行完命令,你会得到一堆 {theVideoName}-000.mp4、{theVideoName}-001.mp4 这样的文件,还有个 video-list.txt。


嫌命令行麻烦?没问题!咱还可以做个批处理文件(Mac → .sh, Windows → .bat)。


新建一个 qiepian.sh 文件:touch qiepian.sh

用 Vim 打开:vi qiepian.sh

把这段代码复制粘贴进去···

#!/bin/bash


echo "Please drag and drop the video file here, then press Enter:"

read videoFile


videoFile="${videoFile//\"/}"


if [[ ! -f "$videoFile" ]]; then

  echo "Error: File not found. Please ensure the file path is correct."

  exit 1

fi


echo "Enter the segment duration in seconds (e.g., 15):"

read segmentDuration


if ! [[ "$segmentDuration" =~ ^[0-9]+$ ]]; then

  echo "Error: Invalid duration. Please enter a valid number."

  exit 1

fi


baseName=$(basename "$videoFile" .mp4)


# Run the FFmpeg command

ffmpeg -i "$videoFile" -c copy -map 0 -f segment -segment_time "$segmentDuration" -segment_list video-list.txt -reset_timestamps 1 "${baseName}-%03d.mp4"


echo "Video has been split into segments of $segmentDuration seconds. Check the output files in the current directory."

···,保存退出(按esc,输入:wq)。

给文件加个可执行权限:chmod +x qiepian.sh

以后想切片,直接在终端输入 ./qiepian.sh 就OK啦!是不是超简单?


有了ffmpeg这个免费又高效的利器,带货切片视频还不是分分钟搞定?赶紧试试吧!



Tired of painstakingly manually editing product promotion videos? Frustrated staring at lengthy live recordings, unsure which segment will become a hit? Worry no more! ffmpeg is here to save the day! This free and powerful tool helps you slice videos with one click, quickly generating short videos for e-commerce, it's simply awesome!


Why use ffmpeg for slicing? For us ordinary folks doing online sales, achieving a viral product is mostly a matter of luck. Instead of spending tons of time meticulously editing, why not cast a wide net? Slice more videos and upload them; who knows which one will take off? Using ffmpeg for slicing is super-efficient, and you can use the saved time to binge-watch shows, take care of your kids, or even just chill! (For the big spenders, do as you please, we can't compete~)


To use ffmpeg for slicing, you'll need its "segment" function. Let's get straight to the point with a practical command example:


ffmpeg -i {theVideoName}.mp4 -c copy -map 0 -f segment -segment_time {how_many_seconds} -segment_list video-list.txt -reset_timestamps 1 {theVideoName}-%03d.mp4

Don't understand it? No worries, I'll break it down for you:


{theVideoName}.mp4: This is your original video file name.

{how_many_seconds}: This is the desired length of each video segment in seconds. For example, enter 15 for 15 seconds, or 240 for 4 minutes (240 seconds).

-c copy: This is key! It directly copies the video stream without re-encoding, making it incredibly fast and preserving the original quality!

-map 0: Makes sure the audio is also included in the segments.

-segment_time: Sets the segment duration.

-segment_list video-list.txt: Generates a file recording segment information, useful if you want to merge videos later.

-reset_timestamps 1: Resets the timestamp of each segment to start from 0.

After running the command, you'll get a bunch of files like {theVideoName}-000.mp4, {theVideoName}-001.mp4, and a video-list.txt.


Don't like using the command line? No problem! We can also create a batch file (a .sh file on Mac).


Create a qiepian.sh file: touch qiepian.sh

Open it with Vim: vi qiepian.sh

Copy and paste the code ```

#!/bin/bash


echo "Please drag and drop the video file here, then press Enter:"

read videoFile


videoFile="${videoFile//\"/}"


if [[ ! -f "$videoFile" ]]; then

  echo "Error: File not found. Please ensure the file path is correct."

  exit 1

fi


echo "Enter the segment duration in seconds (e.g., 15):"

read segmentDuration


if ! [[ "$segmentDuration" =~ ^[0-9]+$ ]]; then

  echo "Error: Invalid duration. Please enter a valid number."

  exit 1

fi


baseName=$(basename "$videoFile" .mp4)


# Run the FFmpeg command

ffmpeg -i "$videoFile" -c copy -map 0 -f segment -segment_time "$segmentDuration" -segment_list video-list.txt -reset_timestamps 1 "${baseName}-%03d.mp4"


echo "Video has been split into segments of $segmentDuration seconds. Check the output files in the current directory."

```, then save and exit (press esc, type :wq).

Give the file execute permission: chmod +x qiepian.sh

Now, when you want to slice a video, just enter ./qiepian.sh in the terminal! Isn't it super easy?


With ffmpeg, this free and efficient tool, creating product video clips is a piece of cake! Go ahead and give it a try!


Saturday, 4 January 2025

视频处理不用愁,FFmpeg三招就够 - Video Processing Made Easy: Three FFmpeg Tricks You Need

格式转换、合并、去水印,FFmpeg一键搞定,效率翻倍!- Convert, Merge, Remove Watermarks—FFmpeg Does It All, Boosting Your Efficiency!


自媒体和视频剪辑的小伙伴们,是否经常头疼于视频格式不兼容、视频合并繁琐以及水印难以去除的问题?别急,FFmpeg来帮忙,轻松快速解决你的视频处理难题。

FFmpeg是啥?为啥说它对新手友好?

FFmpeg是一个强大的命令行工具,可以处理各种音视频任务。你可能会觉得命令行听起来很复杂,但其实用起来非常简单。就像学会用计算器一样,掌握几个基本命令,就能解决大部分问题。而且,FFmpeg是免费的!白嫖的快乐,谁用谁知道!

安装FFmpeg,简单!

FFmpeg可以在官网和Github上下载,如果你是Mac用户,并且安装了Homebrew,那就更方便了,一条命令搞定:brew install ffmpeg。安装完成后,打开终端(Windows用户需要配置环境变量),输入ffmpeg -h,就能看到各种帮助信息。

三招教你玩转FFmpeg!

为了方便演示,我们把输入文件统一命名为input.mp4,输出文件统一命名为output.mp4

第一招:闪电格式转换

格式转换是视频处理中最常见的需求之一。FFmpeg的强大之处在于,它可以在不重新编码的情况下进行格式转换,速度飞快,而且画质几乎没有损失!

命令如下:

ffmpeg -i input.mp4 output.mov


就这么简单!一行命令就把input.mp4转换成了output.mov

第二招:合并视频,井井有条

需要合并大量视频?别再手动拖拽了!FFmpeg帮你轻松搞定!首先,需要创建一个文本文件(例如concat.txt),在里面列出需要合并的视频文件:

file 'input1.mp4'

file 'input2.mp4'

file 'input3.mp4'

...


然后,使用以下命令:

ffmpeg -f concat -i concat.txt -c copy output.mp4


-c copy表示直接复制视频流和音频流,避免重新编码,速度更快。

第三招:去除水印,不费力

去除水印是个技术活,根据水印的类型和视频内容,方法各不相同。FFmpeg提供了delogo滤镜,可以简单去除一些静态水印。但对于复杂的水印,建议使用专业的去水印软件。

命令如下:

ffmpeg -i input.mp4 -vf delogo=x=100:y=100:w=200:h=100 output.mp4


其中,xy是水印左上角的坐标,wh是水印的宽度和高度。你需要根据实际情况调整这些参数。

总结:FFmpeg,新手也能轻松上手!

FFmpeg功能强大,用法灵活,绝对是自媒体和视频剪辑小伙伴的得力助手。别再为视频处理问题烦恼了,赶紧来试试FFmpeg吧!你会发现,原来视频处理可以这么简单!


Title: Video Processing Made Easy: Three FFmpeg Tricks You Need

Self-media and video editing folks, do you often get frustrated with incompatible video formats, the hassle of merging videos, and the difficulty of removing watermarks? Fear not, FFmpeg is here to help, easily and swiftly solving your video processing challenges.

What is FFmpeg? Why is it Beginner-Friendly?

FFmpeg is a powerful command-line tool that can handle various audio and video tasks. You might think command lines sound complicated, but they're actually very easy to use. Just like learning to use a calculator, mastering a few basic commands can solve most problems. Plus, FFmpeg is free! The joy of getting something for free, everyone who uses it knows!

Installing FFmpeg is Easier Than Drinking Water!

FFmpeg can be downloaded from the official website and Github. If you're a Mac user and have Homebrew installed, it's even more convenient, just one command: brew install ffmpeg. After installation, open your terminal (Windows users need to configure environment variables), type ffmpeg -h, and you'll see various help information. 

Three Tricks to Master FFmpeg!

For demonstration purposes, we'll name the input file input.mp4 and the output file output.mp4.

Trick 1: Format Conversion, Fast as Lightning!

Format conversion is one of the most common needs in video processing. FFmpeg's strength is that it can perform format conversion without re-encoding, which is super fast and results in almost no loss of quality!

The command is as follows:

ffmpeg -i input.mp4 output.mov


That's it! One line of command converts input.mp4 to output.mov.

Trick 2: Video Merging, Well Organized!

Need to merge a large number of videos? Stop dragging and dropping manually! FFmpeg can easily handle it for you! First, you need to create a text file (e.g., concat.txt) and list the video files to be merged:

file 'input1.mp4'

file 'input2.mp4'

file 'input3.mp4'

...


Then, use the following command:

ffmpeg -f concat -i concat.txt -c copy output.mp4


-c copy indicates directly copying the video and audio streams, avoiding re-encoding and making it faster.

Trick 3: Removing Watermarks, a Little Trick!

Removing watermarks is a technical task, and the method varies depending on the type of watermark and the video content. FFmpeg provides the delogo filter, which can simply remove some static watermarks. But for complex watermarks, it is recommended to use professional watermark removal software.

The command is as follows:

ffmpeg -i input.mp4 -vf delogo=x=100:y=100:w=200:h=100 output.mp4


Where x and y are the coordinates of the top-left corner of the watermark, and w and h are the width and height of the watermark. You need to adjust these parameters according to the actual situation.

Conclusion: FFmpeg, Easy to Use Even for Beginners!

FFmpeg is powerful, flexible, and definitely a great assistant for self-media creators and video editing enthusiasts. Stop worrying about video processing problems and try FFmpeg! You'll find that video processing can be so easy!


Monday, 30 December 2024

视频处理神器FFmpeg,超简单三招,告别模糊卡顿 - FFmpeg: Three Super Easy Tricks to Say Goodbye to Blurry Videos

自媒体、剪辑党福音!FFmpeg 超神助力,难题‘秒’解决,还不赶紧上车! - Good news for self-media and video editors! FFmpeg supercharges your work, solving problems in a flash. Jump on board!

嘿,做自媒体或是搞视频剪辑的小伙伴们,咱是不是都有过这些崩溃瞬间:辛辛苦苦压缩个视频,结果画面糊得像打了马赛克,美感全无;听到一段超赞的背景音乐,心痒痒想拿来当自己作品的 BGM 或者设成个性铃声,却死活找不到提取的门道;还有想快速截个视频片段,用软件操作一番后,得到的却是个画质惨不忍睹的 “残次品”。别愁啦,今天就给大伙介绍个超给力的神器 ——FFmpeg,保准让这些难题统统 “退下”!


FFmpeg,这个听起来就很有技术感的名字,其实比你想象的要亲民得多。它就像是一位隐身的视频专家,随时准备帮你解决那些看似复杂的问题。而且,安装FFmpeg简直不能再简单了。如果你是Mac用户,而且已经安装了Homebrew,那么只需在终端里输入一行命令,FFmpeg就能轻松成为你的囊中之物。或者Github手动安装。如果你更习惯于Windows系统,那么去FFmpeg的官方网站下载安装包,然后添加到环境变量,就能愉快地使用了。FFmpeg支持多平台,无论你是Mac、Windows还是Linux用户,都能轻松驾驭。它的帮助命令是”ffmpeg -h”。

好了,让我们来揭开FFmpeg的神秘面纱,看看它是如何用三个简单的命令,帮你解决视频压缩、音频提取和视频截取的问题。


首先,我们来看压缩视频的命令。你是否遇到过视频文件太大,想要压缩但又担心画质受损的问题?FFmpeg的这个命令能帮你在压缩的同时保持画质:


```

ffmpeg -i input.mp4 -c:v libx264 -r 25 -crf 21 -c:a aac output.mp4

```


这里的`-c:v libx264`指定了视频编码器为H264,`-r 25`设置了帧率为25,而`-crf 21`则是设置了码率,数值越小,质量越高。`-c:a aac`则是指定音频编码为AAC。是的,所谓压缩就是重新设置音频格式,视频格式,帧率和码率。


接下来,如果你听到了一段喜欢的背景音乐,想要提取出来做铃声或者提示音,FFmpeg也能轻松帮你实现:


```

ffmpeg -i input.mp4 -c:v libx264 -crf 21 -an output-v.mp4 -c:a aac -vn output-a.mp4

```


这里的`-an`是用来去掉音频的,而`-vn`则是去掉视频,让你只提取出音频文件(output-a.mp4)。


最后,如果你需要截取视频中的某一段,FFmpeg同样能帮你做到,而且避免了重新编码导致的画质损失:

```
ffmpeg -i input.mp4 -ss 00:00:01 -t 00:00:09 -c:v libx264 -crf 21 -c:a aac output.mp4
```

`-ss 00:00:01`表示从视频的第1秒开始截取,`-t 00:00:09`则是截取9秒的视频。


当你需要检查视频是否正常播放时,可以使用`ffplay output.mp4`命令,而如果你想要获取视频或音频的信息,`ffprobe output.mp4`则是你的好帮手。


FFmpeg就是这样一个简单易用的工具,它不仅能帮你告别视频模糊和卡顿,还能让你在视频处理的道路上越走越远。所以,亲爱的小伙伴们,不要再为视频处理的问题烦恼了,赶紧试试FFmpeg,让它成为你视频剪辑的好伙伴吧!



Hey, friends who are engaged in self-media or video editing. Haven't we all had these frustrating moments? After painstakingly compressing a video, the picture turns out to be as blurry as a mosaic, completely ruining the beauty. When hearing a wonderful background music, we itch to use it as the BGM of our own works or set it as a personalized ringtone, but we just can't find a way to extract it. And when we want to quickly clip a video segment, after using software to operate, what we get is a "defective product" with horrible picture quality. Don't worry. Today, I'm going to introduce you to a super powerful tool - FFmpeg, which will surely make these problems disappear!


FFmpeg, a name that sounds very technical, is actually much more approachable than you think. It's like an invisible video expert, ready to help you solve those seemingly complex problems at any time. And installing FFmpeg is as simple as it gets. If you're a Mac user and have Homebrew installed, you can easily get FFmpeg by typing a command in the terminal. Or Github to install it manually. If you're more accustomed to Windows, just download the installation package from FFmpeg's official website and add it to your environment variables, and you're good to go. FFmpeg supports multiple platforms, so whether you're a Mac, Windows, or Linux user, you can easily master it. Its help command is ‘ffmpeg -h’.


Now, let's unveil the mystery of FFmpeg and see how it uses three simple commands to solve the problems of video compression, audio extraction, and video trimming.


First, let's look at the command for compressing videos. Have you ever encountered the problem of video files being too large and wanting to compress them but worrying about the loss of picture quality? This FFmpeg command can help you compress while maintaining picture quality:


```

ffmpeg -i input.mp4 -c:v libx264 -r 25 -crf 21 -c:a aac output.mp4

```


Here, `-c:v libx264` specifies the video encoder as H264, `-r 25` sets the frame rate to 25, and `-crf 21` sets the bitrate, the smaller the value, the higher the quality. `-c:a aac` specifies the audio encoding as AAC. Yes, compression means resetting the audio format, video format, frame rate and bit rate.


Next, if you hear a piece of background music you like and want to extract it as a ringtone or notification sound, FFmpeg can easily help you achieve this:


```

ffmpeg -i input.mp4 -c:v libx264 -crf 21 -an output-v.mp4 -c:a aac -vn output-a.mp4

```


Here, `-an` is used to remove the audio, and `-vn` is to remove the video, allowing you to extract only the audio file(output-a.mp4).


Finally, if you need to trim a part of a video, FFmpeg can also help you do this while avoiding the blurriness caused by re-encoding:


```

ffmpeg -i input.mp4 -ss 00:00:01 -t 00:00:09 -c:v libx264 -crf 21 -c:a aac output.mp4

```


`-ss 00:00:01` means to start trimming from the 1st second of the video, and `-t 00:00:09` is to trim a 9-second video.


When you need to check if the video plays correctly, you can use the `ffplay output.mp4` command, and if you want to get information about the video or audio, `ffprobe output.mp4` is your good helper.


FFmpeg is such a simple and easy-to-use tool that not only helps you bid farewell to blurry and choppy videos but also allows you to go further on the road of video processing. So, dear friends, don't worry about video processing problems anymore, try FFmpeg, and let it become your good partner in video editing!