> For the complete documentation index, see [llms.txt](https://a.b.cr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://a.b.cr/dictionary/alphabet/ffmpeg.md).

# FFmpeg

## Usage

### Cut Video

```shell
ffmpeg -ss 00:00:07.2 -to 00:00:12 -i input.mov output.mp4
```

Some people will have problems with the black frames at the beginning/end of the procedure video, the parameter `-c copy` may be the trouble-maker. the following reason may help you fix the problem.

> When specifying `-c copy`, ffmpeg will cut the video without modifying the actual bitstream. In other words, it will take the frames as-is and copy them to the output file. In some cases (simply put, when the starting time does not correspond to an [I-frame](https://en.wikipedia.org/wiki/Intra-frame_coding)), ffmpeg needs to include some more frames that are needed to properly decode the first frame to be displayed. Those will get a negative timestamp, so they shouldn't be shown.
>
> Reference: [Black frames at beginning of video file when file cut](https://superuser.com/a/1222834)

### Video to GIF

```shell
ffmpeg -i output.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
```

I simply use the answer from google, and this works well, no in-depth research.

Reference: [How do I convert a video to GIF using ffmpeg, with reasonable quality?](https://superuser.com/a/556031)

### Combine Multiple M3U8 Files into a Single File

For combining multiple M3U8 files into a single AAC audio file, you can use the following FFmpeg command:

```sh
ffmpeg -i example.m3u8 -c copy output.aac
```

This command copies the audio codec from the input M3U8 files without encoding, resulting in a consolidated AAC file named `output.aac`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://a.b.cr/dictionary/alphabet/ffmpeg.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
