Official website https://ffmpeg.org/download.html
and added to environment variables
ffmpeg -v ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Displaying the version number indicates success
On the browser side, press F12 to enter the interface to view network requests, filter m3u8
information, search for Preview content, click on the video, find the live broadcast playback, click it, and drag the progress bar backwards. If there is no content, refresh it. This request is in Accessed before the video is loaded, it may not be recorded.
The first step is to take a look at the computer room where header
comes from.
In the second step, Ctrl + A selects all the contents of Preview.
Something like this:
#EXTM3U#EXT-X-VERSION:3#EXT-X-MEDIA-SEQUENCE:1#EXT-X-TARGETDURATION:35#EXTINF:33.000,xxx/1.ts?auth_key=xxx ...
Save it as aa.bj.m3u8
, in the same directory as the python script. Note that the bj in the middle may be different . sz means Shenzhen and bj means Beijing.
Then execute the script python3 a.py
A cache folder will be created, which supports resumed downloading and will be automatically deleted after the download is completed.
The parameter -mac-crf
cannot be used to compress the video and the encoder instructions need to be replaced.
Demo version, different from automation script
import requests, os, re, time# sz means Shenzhen, bj means Beijing, base_url = "https://dtliving-sz.dingtalk.com/live_hp/" def get_url(): url_list = [] with open("aa. m3u8", "r") as f: s = f.readlines() for i in s: if re.match(r".*?ts.*?", i): url_list.append(base_url + i) return url_listdef download(): urls = get_url() for i, url in enumerate(urls): with open(f"{i + 1}.ts", "wb") as f: response = requests.get(url[: -1]) # Remove newline characters print(i, "ok") # time.sleep(1)# Integrate file names to facilitate FFmpeg merging def parse_filename(): base_path = os.getcwd() urls = get_url() with open ("file.txt", "w+") as f: for i in range(1, 1 + len(urls)): path = f"file '{base_path}/{i}.ts'n" print( path) f.write(path)if __name__ == "__main__": download() print("download finished...") parse_filename()
If successful, a series of二进制
files will be downloaded, 1.ts, 2.ts, 3.ts, ...
If it is wrong, it is a file with xml
format content, and an error message will be displayed when opened.
The solution is to see if base_url
does not match, or sz and bj are wrong.
ffmpeg -f concat -safe 0 -i file.txt -c copy a.mp4
I believe that if the file is too big after merging, you can use ffmpeg
to re-compress, or use h256/hevc
to re-encode to get a smaller file size.
It is recommended to use permute software compression
Using a more efficient video encoding format is a common method to reduce the size of video files by using a video encoding format with a higher compression rate. Here is an example of using FFmpeg to convert video to H.265 encoding format:
ffmpeg -i input.mp4 -c:v libx265 -crf 28 output.mp4
The above command converts the input video input.mp4 to H.265 encoding format and saves the result as output.mp4 file. Among them, the -c:v option indicates the video encoder, libx265 indicates using the x265 encoder, the -crf option indicates the video quality, and 28 indicates the target video quality. The smaller the value, the higher the video quality and the larger the file size.
Test, 1.3g video is compressed to 231m size, but the speed is too slow speed=0.8, 3 hours of video compression took me 4 hours, looking for other methods
hevc_videotoolbox is not as good as libx265, but it is very fast. On my m1 MacBook air 13,
Like most hardware accelerated encoders, hevc_videtoolbox is not as efficient as libx265. Therefore, you may need to give it a significantly higher bitrate compared to libx265 to match equivalent quality. This may defeat the purpose of recoding from H.264 to HEVC/H.265.
Official website https://trac.ffmpeg.org/wiki/HWAccelIntro#VideoToolbox
# VideoToolbox [¶](https://trac.ffmpeg.org/wiki/HWAccelIntro#VideoToolbox "链接到这一节") [VideoToolbox](https://developer.apple.com/documentation/videotoolbox) is the macOS framework for video decoding and encoding. The following codecs are supported: - Decoding: H.263, H.264, HEVC, MPEG-1, MPEG-2, MPEG-4 Part 2, ProRes - Encoding: H.264, HEVC, ProRes To use H.264/HEVC hardware encoding in macOS, just use the encoder `-c:v h264_videotoolbox` or `-c:v hevc_videotoolbox` for H.264 or HEVC respectively. Check `ffmpeg -h encoder=...` to see encoder options. VideoToolbox supports two types of rate control: - Bitrate-based using `-b:v` - Constant quality with `-q:v`. Note that the scale is 1-100, with 1 being the lowest and 100 the highest. Constant quality mode is only available for Apple Silicon and from ffmpeg 4.4 and higher.
Turn on GPU acceleration 3 and specify the video encoder for encoding. It should be noted that VideoToolbox does not support CRF, so the bitrate must be specified through -b:v
.
Codec AVOption crf (Select the quality for constant quality mode) has not been used for any stream. The most likely reason is either wrong type (eg a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Testing the default options is about 10 times faster
ffmpeg video -i input.mp4 -c:v hevc_videotoolbox output.mp4
frame=126360 fps=114 q=-0.0 Lsize= 413400kB time=02:55:29.95 bitrate= 321.6kbits/s dup=663 drop=0 speed=9.51x video:315854kB audio:93814kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.910847%
It's about 10 times faster than the previous one, and the file size has gone from 800m to 400m, but the compression rate has dropped. I'll test a few more files.
The encodings corresponding to h264 in macOS include libx264 and h264_videotoolbox. The two speeds are similar, but libx264 has a high CPU usage and the transcoded file size is also small. I heard that the decoding requirements for playing videos will be higher.
After my test, I found that the recording and broadcasting files use h264 encoding. H265 encoding has obvious advantages in 4k and many sports scenes. DingTalk live playback only has 12 frames and 1080p image quality. There is no need to use h265, and the recording and broadcasting I studied Most of them are ppt, and there are very few sports shots.
The following instructions are recommended:
find ./ -name '*.mp4' -exec sh -c 'ffmpeg -i "$0" -c:v libx264 -crf 30 -c:a aac "${0%%.mp4}-hevc.mp4"' {} ;
Code source https://blog.51cto.com/u_15366127/6084937 ↩
Several ways to use ffmpeg to reduce video size https://juejin.cn/post/7222575963564654648 ↩
FMPEG hardware acceleration https://blog.xm.mk/posts/1a3h/ ↩