FFmpeg: Solve the problem that the video file can't be played due to the lack of codec, get the parameters required by the delogo command of removing the watermark, and some other commonly used commands
P.S. There is a chinese version of this article: Zhihu
The first two contents in the headline are in 1. and 4.1.
Be careful to modify the command parameters according to your needs.
1. Merge and convert m4s files (bilibili default download format) to mp4:[1][2][3]
Open file location, rename the two m4s files as 1.m4s and 2.m4s then press shift and right click mouse at the blank location of the files, select open power shell window here,
then input:ffmpeg -i 1.m4s -i 2.m4s -c copy output.mp4
(If the output video can't be played on the computer, use the command below)
or
ffmpeg -i 1.m4s -i 2.m4s -threads 2 -preset veryfast -crf 20 output.mp4
The various options:
-i: input file
-c copy = -codec copy, if you can't play the output video because of the lack of codec, replace -c copy by -threads 2 -preset veryfast -crf 20 may help you
-threads 2: multiple threads to accelerate the converting, it depends on your computer CPU
-preset veryfast: 10 choice: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo, speed from fast to slow
-crf 20: chose the quality of output video, 0-51, 0 is the best quality, 51 is the worst quality
2. Concatenate and convert ts files (common online video download format) to mp4:[4]
Open file location, rename the ts files in play order as 1.ts, 2.ts..., then press shift and right click mouse at the blank location of the files, select open power shell window here, then input:
ffmpeg -i "concat:1.ts|2.ts|3.ts|4.ts" -c copy output.mp4
3. Convert audio m4s file to mp3:
Open file location, rename the audio m4s file as 1.m4s then press shift and right click mouse at the blank location of the file, select open power shell window here, then input:
ffmpeg -i 1.m4s output.mp3
If it shows "Output file #0 does not contain any stream", it indicates that you had renamed the video m4s file, rename the another audio m4s file then input the same instruction above.
4. Extract an image from m4s/mp4 video file:[5]
Open file location, rename the video m4s (mp4) file (usually the video m4s file is bigger) as 1.m4s (1.mp4). Press shift and right click mouse at the blank location of the file, select open power shell window here, then input:
ffmpeg -ss 00:00:00.00 -i 1.m4s -vframes 1 -s 1366*768 -f image2 out.png
(m4s video file, if it shows "Output file #0 does not contain any stream", you had chosen the audio m4s file, you can just chose the another video m4s file.)
or
ffmpeg -ss 00:00:00.00 -i 1.mp4 -vframes 1 -s 1366*768 -f image2 out.png
(mp4 file)
The various options:
-vframes 1: limit to 1 frame extracted
-ss 00:00:00.00: point of movie to extract from, HH:MM:SS.ZZZZ sexagesimal format, hour: minute: second (you can also use 0.5, ie seek to 0.5 seconds)
-s 1366768: frame size of image to output, 1366768 is my computer default resolution, you can change it according to your own computer (image resized to fit dimensions)
-f image2: forces format
4.1 Remove Photo Watermark using ffmpeg[6]
Step 1: Open photo in GIMP, chose rectangle select tool and select the region where the watermark locates and get the top left corner coordinate (x and y) of the watermark (the first number is x and the second number is y) and the width and height of the watermark. (the third number is w and the fourth number is h)
(The source of the image above: Bilibili-yibaiz, if it infringes copyright, please leave a comment and I’ll delete it.)Step 2: Open file location, press shift and right click mouse at the blank location of the file, select open power shell window here, then input:
ffmpeg -i out.png -vf delogo=x=20:y=20:w=250:h=50:show=0 output.png
The various options:
-vf delogo : use the tool of removing watermark
x=20 : x coordinate of the top left corner of the watermark
y=20 : y coordinate of the top left corner of the watermark
w=250 : the width of the watermark
h=50 : the height of the watermark
show=0 : show no border line, 1 to show border line
4.2 Remove Photo Watermark using GIMP Clone Tool[7]
Step 1: Open an Image. The first step is to open the image using the Open option from the File menu. Select the image from the file system that we want to open and click Open. It will open the image with GIMP. We can also drag the image from the file system.
Step 2: Select the Clone Tool. Now, select the clone tool.
Step 3: Select a Similar Region. Now, select a clear region from the image or other image that matches the image's watermarked area. To select a region, hold the CTRL-key and click on a specific area. It will copy that particular region to paint.
Step 4: Start Painting. Now start painting over the watermark image. To paint a specific part, leave the CTRL key and start sliding the cursor over the region. It works like a brush. It will paint the copied region; We can repeat the cloning process by selecting the different regions (Step 3). It is recommended to zoom the image and adjust the brush size as per the need for an improved result.
Step 5: Click File-- Export as-- chose png or jpg format and destination folder-- Export
5. Extract mp3 from a mp4 file:[8]
Open file location, rename the mp4 file as 1.mp4 then press shift and right click mouse at the blank location of the file, select open power shell window here, then input:
ffmpeg -i 1.mp4 output.mp3
6. Extract a clip of video from mp4 file (can't extract video clip from 2 m4s files):[9][10]
Open file location, rename the mp4 file as 1.mp4. Press shift and right click mouse at the blank location of the file, select open power shell window here, then input:
ffmpeg -ss 00:00:00.00 -to 00:00:00.00 -i 1.mp4 -c copy output.mp4
The various options:
-ss 00:00:00.00: the point of video to start extracting
-to 00:00:00.00: the point of video where the extraction ends
Comments
Post a Comment