当前位置:网站首页>Recent progress of ffmpeg go
Recent progress of ffmpeg go
2022-06-24 16:33:00 【Wang Lei -ai Foundation】
Recent developments
stay ffmpeg-goinit after , The project has also received some attention , Several other students sent emails to discuss usage . But time is limited , There are few updates after the first version , Not many new functions , Some new functions introduced in the past six months are as follows :
Support cpu Limit
ffmpeg-go Settings are now supported cpu/memory limit 了 ( Only support linux Environmental Science ), This is in a non container environment , Multi process scenarios are useful , This Command settings cpu Constraints can fairly allocate resources between processes . Examples are as follows :
func ComplexFilterExample(testInputFile, testOverlayFile, testOutputFile string) *ffmpeg.Stream {
split := ffmpeg.Input(testInputFile).VFlip().Split()
split0, split1 := split.Get("0"), split.Get("1")
overlayFile := ffmpeg.Input(testOverlayFile).Crop(10, 10, 158, 112)
return ffmpeg.Concat([]*ffmpeg.Stream{
split0.Trim(ffmpeg.KwArgs{"start_frame": 10, "end_frame": 20}),
split1.Trim(ffmpeg.KwArgs{"start_frame": 30, "end_frame": 40})}).
Overlay(overlayFile.HFlip(), "").
DrawBox(50, 50, 120, 120, "red", 5).
Output(testOutputFile).
OverWriteOutput()
}
// PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
// 1386105 root 20 0 2114152 273780 31672 R 50.2 1.7 0:16.79 ffmpeg
func TestLimitCpu(t *testing.T) {
e := ComplexFilterExample("./sample_data/in1.mp4", "./sample_data/overlay.png", "./sample_data/out2.mp4")
err := e.WithCpuCoreRequest(0.1).WithCpuCoreLimit(0.5).RunLinux()
if err != nil {
assert.Nil(t, err)
}
}Support output s3 Address
ffmpeg-go Support settings s3 For the output address , This mode is suitable for stream The output of mode is more useful , Can be in ffmpeg Do the upload action while processing , To save overall processing time . For compatibility s3 Of the agreement Tencent cloud , Alibaba cloud , Qiniu cloud object storage can also use this function ( In the future, some functions will be performed on the use of related docking cloud resources ), Examples are as follows :
func TestSimpleS3StreamExample(t *testing.T) {
err := ffmpeg.Input("./sample_data/in1.mp4", nil).
Output("s3://data-1251825869/test_out.ts", ffmpeg.KwArgs{
"aws_config": &aws.Config{
Credentials: credentials.NewStaticCredentials("xx", "yyy", ""),
//Endpoint: aws.String("xx"),
Region: aws.String("yyy"),
},
// outputS3 use stream output, so you can only use supported format
// if you want mp4 format for example, you can output it to a file, and then call s3 sdk to do upload
"format": "mpegts",
}).
Run()
assert.Nil(t, err)
}Added more examples
This was discovered after receiving several emails for consultation , There are still few examples , Some examples are scattered in different places , So some simple examples are sorted out .
The introduction of the first edition is attached
Examples of use
import (
ffmpeg "github.com/u2takey/ffmpeg-go"
)
split := ffmpeg.Input(TestInputFile1).VFlip().Split()
split0, split1 := split.Get("0"), split.Get("1")
overlayFile := Input(TestOverlayFile).Crop(10, 10, 158, 112)
err := ffmpeg.Concat([]*Stream{
split0.Trim(KwArgs{"start_frame": 10, "end_frame": 20}),
split1.Trim(KwArgs{"start_frame": 30, "end_frame": 40})}).
Overlay(overlayFile.HFlip(), "").
DrawBox(50, 50, 120, 120, "red", 5).
Output(TestOutputFile1).
OverWriteOutput().Run()Frame extraction
func ExampleReadFrameAsJpeg(inFileName string, frameNum int) io.Reader {
buf := bytes.NewBuffer(nil)
err := ffmpeg.Input(inFileName).
Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
WithOutput(buf, os.Stdout).
Run()
if err != nil {
panic(err)
}
return buf
}
reader := ExampleReadFrameAsJpeg("./sample_data/in1.mp4", 5)
img, err := imaging.Decode(reader)
if err != nil {
t.Fatal(err)
}
err = imaging.Save(img, "./sample_data/out1.jpeg")
if err != nil {
t.Fatal(err)
}result :
Show processing progress
see complete example at: showProgress
func ExampleShowProgress(inFileName, outFileName string) {
a, err := ffmpeg.Probe(inFileName)
if err != nil {
panic(err)
}
totalDuration := gjson.Get(a, "format.duration").Float()
err = ffmpeg.Input(inFileName).
Output(outFileName, ffmpeg.KwArgs{"c:v": "libx264", "preset": "veryslow"}).
GlobalArgs("-progress", "unix://"+TempSock(totalDuration)).
OverWriteOutput().
Run()
if err != nil {
panic(err)
}
}
ExampleShowProgress("./sample_data/in1.mp4", "./sample_data/out2.mp4")result
progress: .0 progress: 0.72 progress: 1.00 progress: done
and Open-cv (gocv) Use together for video face recognition
see complete example at: opencv
result :
Support generation flowchart
边栏推荐
- Global and Chinese market of insect proof clothing 2022-2028: Research Report on technology, participants, trends, market size and share
- Object store signature generation
- Fastjson 漏洞利用技巧
- Global and Chinese markets of stainless steel barbecue ovens 2022-2028: Research Report on technology, participants, trends, market size and share
- Dismantle the industrial chain of synthetic rubber industry, and the supply chain may become a sharp weapon for breakthrough
- What is browser fingerprint recognition?
- [tke] analysis of CLB loopback in Intranet under IPVS forwarding mode
- 期货怎么开户安全些?哪些期货公司靠谱些?
- B. Ternary Sequence(思维+贪心)Codeforces Round #665 (Div. 2)
- Batch BOM Bapi test
猜你喜欢
MySQL Advanced Series: locks - locks in InnoDB

C. Three displays(动态规划)Codeforces Round #485 (Div. 2)

Ps\ai and other design software pondering notes
![[go] concurrent programming channel](/img/6a/d62678467bbc6dfb6a50ae42bacc96.jpg)
[go] concurrent programming channel

ZOJ - 4104 sequence in the pocket

Applet wxss

Some adventurer hybrid versions with potential safety hazards will be recalled

B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)

C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)
Advanced programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization
随机推荐
National standard gb28181 protocol video platform easygbs alarm reporting function adds video alarm reporting and video recording
2021-04-29: given an array arr, it represents a row of balloons with scores. One for each blow
Istio FAQ: failed to resolve after enabling smart DNS
2021-04-28: force buckle 546, remove the box. Give some boxes of different colors
SQL multi table updating data is very slow
2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
Global and Chinese market of insect proof clothing 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of natural insect repellents 2022-2028: Research Report on technology, participants, trends, market size and share
What can Lu yuanjiu Jiao buy?
Snowflake algorithm implemented in go language
Ps\ai and other design software pondering notes
Little red book, hovering on the edge of listing
Tencent blue whale container management platform was officially released!
Greenplum role-based fine-grained permission control
#夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项
Load MySQL table data consumption quick installation configuration through kafka/flink
B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)
What is browser fingerprint recognition?
Annual contribution! Tencent cloud middleware product upgrade conference is in hot registration!
Modern finite element analysis can easily achieve accurate results