{"id":13459975,"url":"https://github.com/u2takey/ffmpeg-go","last_synced_at":"2025-05-14T03:10:44.816Z","repository":{"id":38351982,"uuid":"311583768","full_name":"u2takey/ffmpeg-go","owner":"u2takey","description":"golang binding for ffmpeg","archived":false,"fork":false,"pushed_at":"2024-05-24T01:49:22.000Z","size":2403,"stargazers_count":1739,"open_issues_count":54,"forks_count":172,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-10-29T15:21:52.392Z","etag":null,"topics":["ffmpeg","ffmpeg-wrapper","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/u2takey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-10T07:50:08.000Z","updated_at":"2024-10-29T14:53:28.000Z","dependencies_parsed_at":"2024-04-23T11:46:31.731Z","dependency_job_id":"3f236e53-b1a4-46ac-a5e5-f2dd69a770d6","html_url":"https://github.com/u2takey/ffmpeg-go","commit_stats":{"total_commits":42,"total_committers":16,"mean_commits":2.625,"dds":"0.45238095238095233","last_synced_commit":"898ebfd93985f0f69cde36e466094cd453caa349"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/u2takey%2Fffmpeg-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/u2takey%2Fffmpeg-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/u2takey%2Fffmpeg-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/u2takey%2Fffmpeg-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/u2takey","download_url":"https://codeload.github.com/u2takey/ffmpeg-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059512,"owners_count":22007769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ffmpeg","ffmpeg-wrapper","go","golang"],"created_at":"2024-07-31T10:00:33.259Z","updated_at":"2025-05-14T03:10:39.807Z","avatar_url":"https://github.com/u2takey.png","language":"Go","readme":"# ffmpeg-go\n\nffmpeg-go is golang port of https://github.com/kkroening/ffmpeg-python\n\ncheck examples/example_test.go and ffmpeg_test.go for more examples.\n\n# How to get and use\nYou can get this package via:\n```\ngo get -u github.com/u2takey/ffmpeg-go\n```\n\n\u003e **Note**: `ffmpeg-go` makes no attempt to download/install FFmpeg, as `ffmpeg-go` is merely a pure-Go wrapper - whereas FFmpeg installation is platform-dependent/environment-specific, and is thus the responsibility of the user, as described below.\n\n### Installing FFmpeg\n\nBefore using `ffmpeg-go`, FFmpeg must be installed and accessible via the `$PATH` environment variable.\n\nThere are a variety of ways to install FFmpeg, such as the [official download links](https://ffmpeg.org/download.html), or using your package manager of choice (e.g. `sudo apt install ffmpeg` on Debian/Ubuntu, `brew install ffmpeg` on OS X, etc.).\n\nRegardless of how FFmpeg is installed, you can check if your environment path is set correctly by running the `ffmpeg` command from the terminal, in which case the version information should appear, as in the following example (truncated for brevity):\n\n```\n$ ffmpeg\nffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers\n  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)\n```\n\n\u003e **Note**: The actual version information displayed here may vary from one system to another; but if a message such as `ffmpeg: command not found` appears instead of the version information, FFmpeg is not properly installed.\n\n# Examples\n\n```go\nsplit := Input(TestInputFile1).VFlip().Split()\n\tsplit0, split1 := split.Get(\"0\"), split.Get(\"1\")\n\toverlayFile := Input(TestOverlayFile).Crop(10, 10, 158, 112)\nerr := Concat([]*Stream{\n    split0.Trim(KwArgs{\"start_frame\": 10, \"end_frame\": 20}),\n    split1.Trim(KwArgs{\"start_frame\": 30, \"end_frame\": 40})}).\n    Overlay(overlayFile.HFlip(), \"\").\n    DrawBox(50, 50, 120, 120, \"red\", 5).\n    Output(TestOutputFile1).\n    OverWriteOutput().\n    Run()\n```\n\n## Transcoding From One Codec To Another\n\n```go\nerr := ffmpeg.Input(\"./sample_data/in1.mp4\").\n\t\tOutput(\"./sample_data/out1.mp4\", ffmpeg.KwArgs{\"c:v\": \"libx265\"}).\n\t\tOverWriteOutput().ErrorToStdOut().Run()\n```\n\n## Cut Video From Timestamp\n\n```go\nerr := ffmpeg.Input(\"./sample_data/in1.mp4\", ffmpeg.KwArgs{\"ss\": 1}).\n    Output(\"./sample_data/out1.mp4\", ffmpeg.KwArgs{\"t\": 1}).OverWriteOutput().Run()\nassert.Nil(t, err)\n```\n\n## Add Watermark For Video\n```go\n// show watermark with size 64:-1 in the top left corner after seconds 1\noverlay := ffmpeg.Input(\"./sample_data/overlay.png\").Filter(\"scale\", ffmpeg.Args{\"64:-1\"})\nerr := ffmpeg.Filter(\n    []*ffmpeg.Stream{\n        ffmpeg.Input(\"./sample_data/in1.mp4\"),\n        overlay,\n    }, \"overlay\", ffmpeg.Args{\"10:10\"}, ffmpeg.KwArgs{\"enable\": \"gte(t,1)\"}).\n    Output(\"./sample_data/out1.mp4\").OverWriteOutput().ErrorToStdOut().Run()\n```\n\nresult:\n\n![img.png](./docs/example_overlay.png)\n\n## Cut Video For Gif \n\n```go\nerr := ffmpeg.Input(\"./sample_data/in1.mp4\", ffmpeg.KwArgs{\"ss\": \"1\"}).\n    Output(\"./sample_data/out1.gif\", ffmpeg.KwArgs{\"s\": \"320x240\", \"pix_fmt\": \"rgb24\", \"t\": \"3\", \"r\": \"3\"}).\n    OverWriteOutput().ErrorToStdOut().Run()\n```\n\nresult:\n\n![img.png](./docs/example_gif.gif)\n\n## Task Frame From Video\n\n```bash\nfunc ExampleReadFrameAsJpeg(inFileName string, frameNum int) io.Reader {\n\tbuf := bytes.NewBuffer(nil)\n\terr := ffmpeg.Input(inFileName).\n\t\tFilter(\"select\", ffmpeg.Args{fmt.Sprintf(\"gte(n,%d)\", frameNum)}).\n\t\tOutput(\"pipe:\", ffmpeg.KwArgs{\"vframes\": 1, \"format\": \"image2\", \"vcodec\": \"mjpeg\"}).\n\t\tWithOutput(buf, os.Stdout).\n\t\tRun()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn buf\n}\n\nreader := ExampleReadFrameAsJpeg(\"./sample_data/in1.mp4\", 5)\nimg, err := imaging.Decode(reader)\nif err != nil {\n    t.Fatal(err)\n}\nerr = imaging.Save(img, \"./sample_data/out1.jpeg\")\nif err != nil {\n    t.Fatal(err)\n}\n```\nresult : \n\n![image](./examples/sample_data/out1.jpeg)\n\n## Get Multiple Output\n\n```go\n// get multiple output with different size/bitrate\ninput := ffmpeg.Input(\"./sample_data/in1.mp4\").Split()\nout1 := input.Get(\"0\").Filter(\"scale\", ffmpeg.Args{\"1920:-1\"}).\nOutput(\"./sample_data/1920.mp4\", ffmpeg.KwArgs{\"b:v\": \"5000k\"})\nout2 := input.Get(\"1\").Filter(\"scale\", ffmpeg.Args{\"1280:-1\"}).\nOutput(\"./sample_data/1280.mp4\", ffmpeg.KwArgs{\"b:v\": \"2800k\"})\n\nerr := ffmpeg.MergeOutputs(out1, out2).OverWriteOutput().ErrorToStdOut().Run()\n```\n\n## Show FFmpeg Progress\n\nsee complete example at: [showProgress](./examples/showProgress.go)\n\n```bash\nfunc ExampleShowProgress(inFileName, outFileName string) {\n\ta, err := ffmpeg.Probe(inFileName)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\ttotalDuration := gjson.Get(a, \"format.duration\").Float()\n\n\terr = ffmpeg.Input(inFileName).\n\t\tOutput(outFileName, ffmpeg.KwArgs{\"c:v\": \"libx264\", \"preset\": \"veryslow\"}).\n\t\tGlobalArgs(\"-progress\", \"unix://\"+TempSock(totalDuration)).\n\t\tOverWriteOutput().\n\t\tRun()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\nExampleShowProgress(\"./sample_data/in1.mp4\", \"./sample_data/out2.mp4\")\n```\n\nresult \n\n```bash\nprogress:  .0\nprogress:  0.72\nprogress:  1.00\nprogress:  done\n```\n\n## Integrate FFmpeg-go With Open-CV (gocv) For Face-detect\n\nsee complete example at: [opencv](./examples/opencv_test.go)\n\nresult: ![image](./examples/sample_data/face-detect.jpg)\n\n## Set Cpu limit/request For FFmpeg-go\n\n```go\ne := ComplexFilterExample(\"./sample_data/in1.mp4\", \"./sample_data/overlay.png\", \"./sample_data/out2.mp4\")\nerr := e.RunWithResource(0.1, 0.5)\nif err != nil {\n    assert.Nil(t, err)\n}\n```\n\nresult from command top: we will see ffmpeg used 0.5 core as expected.\n\n```bash\n\u003e top \nPID    USER       PR  NI    VIRT    RES    SHR S  %CPU   %MEM     TIME+ COMMAND\n1386105 root      20   0 2114152 273780  31672 R  50.2   1.7      0:16.79 ffmpeg\n```\n\n# View Progress Graph\n\nfunction view generate [mermaid](https://mermaid-js.github.io/mermaid/#/) chart, which can be use in markdown or view [online](https://mermaid-js.github.io/mermaid-live-editor/)\n\n```go\nsplit := Input(TestInputFile1).VFlip().Split()\n\tsplit0, split1 := split.Get(\"0\"), split.Get(\"1\")\n\toverlayFile := Input(TestOverlayFile).Crop(10, 10, 158, 112)\nb, err := Concat([]*Stream{\n    split0.Trim(KwArgs{\"start_frame\": 10, \"end_frame\": 20}),\n    split1.Trim(KwArgs{\"start_frame\": 30, \"end_frame\": 40})}).\n    Overlay(overlayFile.HFlip(), \"\").\n    DrawBox(50, 50, 120, 120, \"red\", 5).\n    Output(TestOutputFile1).\n    OverWriteOutput().View(ViewTypeFlowChart)\nfmt.Println(b)\n```\n![image](./docs/flowchart2.png)\n","funding_links":[],"categories":["Go","HarmonyOS","语言资源库","Libraries and Wrappers"],"sub_categories":["Windows Manager","go"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fu2takey%2Fffmpeg-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fu2takey%2Fffmpeg-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fu2takey%2Fffmpeg-go/lists"}