r/ffmpeg

▲ 2 r/ffmpeg

How do I correctly select the GPU ID for the `-init_hw_device vulkan=vk:` parameter?

Hello everyone. I am running FFmpeg on a system with three GPUs: an Intel iGPU, an RX 6400, and an RTX 3060. Here is my FFmpeg command line:

[ argumentosString ] -init_hw_device vulkan=vk:0 -filter_hw_device vk -v repeat+error -i "D:\OBS\record\teste.mp4" -vf "hwupload,libplacebo=w=1920:h=1080:colorspace=bt709:color_primaries=bt709:color_trc=bt709:range=limited:custom_shader_path='D\:/upscale/shaders/shader.glsl',hwdownload,format=yuv420p" -fps_mode passthrough -c:v h264_amf -rc cqp -qp_i 19 -qp_p 21 -tag:v avc1 -c:a copy -y -gpu 0 "D:\OBS\record\teste_process.mp4"

The `-gpu` parameter specifies which GPU to use for encoding, while the `-init_hw_device vulkan=vk:0` parameter specifies which GPU runs the shader. To my surprise, when using the value `0` for both parameters, I discovered that this value does not point to the same GPU; I see a scenario where the shader runs on the RX 6400 while the encoding takes place on the RTX 3060. This happens because the GPU ordering differs for each of these parameters.

Can anyone help me?

reddit.com
u/Few_Profit5031 — 8 hours ago
▲ 3 r/ffmpeg

How do I convert progressive jpg to baseline jpg?

I'm trying to convert progressive jpg files for use in older tech that doesn't like progressive jpgs, but I can't find any documentation on how to specify non-progressive jpgs in ffmpeg. Anyone have any insight?

reddit.com
u/PsychicChime — 1 day ago
▲ 30 r/ffmpeg+2 crossposts

Why am I getting WORSE file size reduction with 2-pass encoding vs single pass encoding??

u/Calm-Preparation-679 — 3 days ago
▲ 7 r/ffmpeg

Concatenate files and maintain all subtitle and audio tracks

I've ripped a movie that is split into two parts. I wish to concatenate it, but maintain all audio and subtitle files.

A simple concatenation will join the two video files with the main audio, but not the other audio tracks, and none of the subtitles:

ffmpeg \
  -f concat -i videofiles.txt \
  -c copy -map 0 movie.mkv

where videofiles.txt is a list of the original two files.

I found the following command to concatenate subtitles:

ffmpeg \
  -f concat -safe 0 -i videofiles.txt \
  -f concat -safe 0 -i subfiles.txt \
  -map 0:v -map 1 -c:v copy -c:s copy movie.mkv

This joined the two video files, but none of the audio tracks, and the subtitles only appeared for the first half of the movie.

As this is a rip, the subtitles I have extracted with mkvextract are in the .sub/.idx format, so I thought I'd need to include both in order to make this work:

ffmpeg \
  -f concat -safe 0 -i videofiles.txt \
  -f concat -safe 0 -i subfiles.txt \
  -f concat -safe 0 -i idxfiles.txt \
  -map 0:v -map 1 -c:v copy -c:s copy movie.mkv

But this yielded the same results. No audio, and only half of the subtitles.

It should probably be noted that ffmpeg is confusing for me, and I don't even know half of what these options are trying to do in these commands, since the places where I got them just say "enter this here", rather than explaining what each option does. As such, I don't know what I can change, and what I can keep the same.

reddit.com
u/JRCSalter — 3 days ago
▲ 3 r/ffmpeg

copying some, but not all, subtitle tracks

my input is this:

ffmpeg -i "INPUT" -vcodec libx265 -preset medium -crf 28 -map 0 -c:a copy -map 0:s:1 -c:s:0 copy "OUTPUT"

the input file has a dozen or so subtitle tracks that bloat up the file size. I'm trying just to keep track 2. I know -map:0:s:1 designates the second track, but without -c:s copy, I get the error "subtitle encoding currently only possible from text to text or bitmap to bitmap". I found that -c:s:0 copy after the map argument is supposed to copy just the mapped subtitle, but I still get the same error. and if I just have -c:s copy, even after the -map argument, it copies over every sub track.

reddit.com
u/telnaga — 4 days ago
▲ 17 r/ffmpeg

Cannot Access FFMPEG source code at git.ffmpeg.org?

I am trying to access ffmpeg source website but receiving error code 403? Is anyone else having the same problem or is it just me? Due to this, git pull is also not working.

u/rai_volt — 5 days ago
▲ 12 r/ffmpeg

Unreadable color scheme on documentation site

Is it just me or does everyone see the pale gray on white text on the documentation site, eg at https://ffmpeg.org/ffmpeg.html#Advanced-options I'm sure it wasn't like this last time I used the site a few weeks ago, I've tried all 3 browsers on my computer with the same result. I know there's various ways I can work around it, just wondering if this is deliberate.

u/pcb1962 — 5 days ago
▲ 6 r/ffmpeg

with johnvansickle.com/ffmpeg currently down is there any other trusted repo for binaries?

Title says it all - ran into lamba deployment issues due to the binaries being in accessible and am currently looking into alternatives.

reddit.com
u/budgiekings — 4 days ago
▲ 0 r/ffmpeg+1 crossposts

Worth publishing? Used AI to build an AV1 / H.265 Smart-Cutter that fixes static CRF file bloat & PyAV crashes

I don't actually know how to code, but I got fed up with current video editing options:

  • NLEs (Premiere/Resolve): Too slow just to cut and stitch videos.
  • Standard Lossless Trimming (ffmpeg -c copy): Imprecise (cuts only on keyframes).
  • Existing Smart-Cutters: Re-encode boundary frames using static CRF, which kept making my 30-second cuts larger (46mb) in file size than my 1-minute originals (30mb). Why would someone code it in this way?

So I said to myself, why not just alter what smartcut does? So, I spent the last few days using AI (Claude free version) to build a custom PyAV/Python smart-cutting engine to fix this for my own workflow. We ended up hitting a few major breakthroughs. I fed my changes into gemini and talked with it for a long while trying to find out if what I did was actually game changing. It thought so, but I have no idea if it is:

  • Player-First Workflow (Movist Pro): I mark cut points (IN and OUT) using Movist Pro's bookmark feature. The script reads the timestamps in the bookmark file and cuts everything headlessly in the background. I'm using this in place of a standard video editing tool (like capcut). It makes timestamp extraction much easier and I can easily add/remove bookmarks.
  • Localized Bitrate Matching: Ditched static CRF completely. The engine measures the exact source bitrate of the head and tail keyframes independently and forces x265 / libsvtav1 to match them. No file bloat, no visual seams. File sizes stay small.
  • Frame-Accurate AV1 Smart-Cutting: Solved the PyAV level override and timestamp bugs that normally crash AV1 boundary re-encodes. The only issue is self testing. I am currently doing all this on a 2019 Intel MacBook Pro, so it has been annoying to test the final output. I have access to a M3 MacBook Air, but not often. The final cut video works perfectly fine on the M3 Macbook Air, but i get slight lag on the last couple seconds on my Intel MacBook Pro. I am still fixing this slight issue, the AI suggests it will be a simple fix, but it never is.
  • Parallel C Extension: Wrote a C module to handle H.265 NAL unit scanning (CRA Type 21 → BLA Type 16), jumping CPU usage on my Intel Mac from 100% (GIL capped) to 600% and eliminating repeated frames at cut points.

I built this purely for my own personal use, but I'm curious: Is there actual demand for a lightweight, frame-accurate AV1/H.265 smart-cutter like this, or is this too niche to bother releasing? I've also built additional functionality for the Movist Pro Media Player. I use this to run the smartcut features.

I am not the most technical when it comes to all of this. The AI did a lot of the heavy lifting, I just pushing it in the correct direction.

EDIT:
I created a github and with the ai's help, i created the zip folder that houses all the relevant files and scripts. As well as a readme that will with most questions you have.

https://github.com/AbdulazizMorad/Smartcut-proof-of-concept

EDIT2:
Github updated and no longer shows a zip file

u/aswas123 — 7 days ago
▲ 1 r/ffmpeg

[Help] Playing more local video formats (AVI, WMV, 3GP...) in a pywebview desktop app

I'm building a Python desktop app (using pywebview, Windows, WebView2/Chromium backend) that works as an offline personal file manager / local media library — think local notes, documents, photos, and personal video files a user already has on their own drive, all organized and browsable from one offline app with no internet/streaming component.

One built-in feature is a simple in-app video preview player using an HTML5 <video> tag inside the webview. Right now it only plays what Chromium's native <video> element supports: MP4 (H.264/AAC), WebM, MOV, and MKV (when the codecs inside are H.264/H.265+AAC). Other local formats users might already have on disk — AVI, WMV, 3GP, FLV, MKV with older codecs like XviD/DivX — currently just fall back to opening in the OS's default video app instead of playing inline.

I'd like to expand format support inside the app. Options I'm considering:

  • FFmpeg-based transcoding to MP4/WebM on the fly (either fully pre-converting or streaming while converting).
  • A JS/WASM video decoder (e.g. libav-based) that plays inside the webview without relying on OS codecs.
  • Embedding a native player (like mpv) instead of the HTML5 <video> element — unsure how well that integrates inside a pywebview window.

Has anyone solved this for a pywebview (or similar Python-desktop / Electron / Tauri) app? Looking for something that plays these formats inline in the app rather than falling back to an external player. Thanks!

reddit.com
u/Offlined_OS — 5 days ago
▲ 5 r/ffmpeg

Replicate Replay Buffer from OBS with FFMPEG

Hello, everyone. I have a somewhat specific request. You see, I have a separate device for screen recording of a console. The console in question doesn't support replays or anything, so instead I use a capture card. However I don't have a need to record every hour and every minute, only good moments, last 30 seconds at least. I did a lengthy search on the web but couldn't find exactly what I need. Maybe you know a bash script that can do this? I will appreciate that.

edit: fixed some mistakes

reddit.com
u/Creative-Outside-350 — 5 days ago
▲ 6 r/ffmpeg

Cannot figure out telecine re-encode.

I have a short film Blu-Ray rip that is 29.97fps MBAFF scan type, pattern 3 progressive frames followed by two combed frames repeating, but I cannot for the life of me figure out what settings to use or alternate tools to utilize to re-encode the film to 23.976 progressive. No matter what frame rate output I try, detelecine on or off, various attempts at deinterlacing, bob or otherwise, etc, and nothing. Always misses frames and the timing and duplicate frames feels inconsistent and wrong. The closest approximation I have is when viewing the original mkv in vlc media player and checking sections frame-by-frame (also how I know re-encode outputs come out wrong) with "Film NTSC (IVTC)" enabled, which seems to do exactly what I want minus the last two frames of the 5 frame pattern being duplicates (which I suspect is a result of the 29.97fps). It does not seem to miss anything or worse the quality of the comb frames or otherwise. Note, though, that I enable it manually as deinterlace detection (off, auto, on) being set to auto does not trigger it. I may be missing key details here, or misunderstanding certain aspects of the original video file, but I have tried searching and digging for inverse telecine solutions and whatnot only to turn up empty. The VLC IVTC deinterlace filter is almost perfect, but part of me still wants to re-encode the file. Does anyone have any insight into this or what could be done with handbrake or other programs? If any additional details are needed from me, feel free to ask. Also, again, I do not doubt that there are some aspects of the situation I am misunderstanding or forgetting about.

EDIT UPDATE: Upon much closer inspection, alongside a mostly successful ffmpeg re-encode, I find that finer details or shadows or other specific parts of even the "progressive" frames (even the ones in the original mkv upon looking cover) also have a fainter combing pattern present, just not as visible and not as blatantly related to frame conversion like with the 2 telecine frames of the group of 5. Now, I don't know what this is or if it could be remedied without worsening the quality.

reddit.com
u/nik0121 — 7 days ago
▲ 0 r/ffmpeg

PSA: `-af apad` with no `whole_dur` pads forever. It turned my 2-second test clip into a 12,662-second file.

Posting this because the fix for one bug handed me a worse one, and the failure is completely

silent until you look at the duration.

I was muxing a narration track onto a finished 55.5s render. The obvious command is:

```bash

ffmpeg -i video.mp4 -i vo.wav -c:v copy -c:a aac -shortest out.mp4

```

`-shortest` is the trap everyone warns about — if your audio is even slightly short, it truncates

the *video* to match and you silently lose the end of your film. I'd already been bitten by that

one: it ate 1.25 seconds off an outro and produced a file that played perfectly and passed every

check I had.

So I did what the docs and most StackOverflow answers suggest: drop `-shortest`, pad the audio

instead.

```bash

ffmpeg -i video.mp4 -i vo.wav -c:v copy -c:a aac -af apad out.mp4

```

**This never terminates.** Bare `apad` pads with silence indefinitely. `-shortest` was the only

thing bounding it. Remove one, you arm the other.

I didn't notice at first because it *looks* like it's working — it writes a valid growing MP4. I

killed it at the 10-minute mark and probed the output:

```

size = 120,529,993 bytes

video = 55.500 s

audio = 284,615.765 s <-- 79 hours of silence

```

Reduced to a known-answer case so it's easy to confirm (ffmpeg 6.1.1):

```bash

ffmpeg -f lavfi -i testsrc=size=320x240:rate=30 -t 2 -pix_fmt yuv420p v.mp4

ffmpeg -f lavfi -i "sine=frequency=440" -t 1 a.wav

timeout 25 ffmpeg -i v.mp4 -i a.wav -c:v copy -c:a aac -af apad old.mp4

```

2-second video in. Result:

```

exit = 124 (killed by timeout — it was not going to stop)

dur = 12,662.748 s

```

### The fix

Give the pad an explicit endpoint. Probe the video, feed the number in:

```bash

V=$(ffprobe -v error -show_entries format=duration -of csv=p=0 video.mp4)

ffmpeg -i video.mp4 -i vo.wav -c:v copy -c:a aac -af "apad=whole_dur=$V" out.mp4

```

Or pad the audio during assembly and mux with **no** `-af` at all — better if you want to assert

the voice track's length independently before it ever reaches the mux:

```bash

ffmpeg -i vo.wav -af "apad=whole_dur=$V" -c:a pcm_s16le vo_padded.wav

ffprobe -v error -show_entries format=duration -of csv=p=0 vo_padded.wav # assert this

ffmpeg -i video.mp4 -i vo_padded.wav -c:v copy -c:a aac out.mp4

```

Both land on exactly 2.000000 in the test case and exactly 55.500 on the real film.

### The actual lesson

`-shortest` and `apad` are the same bug class: **flags that silently decide where your output

ends.** One truncates, one runs away. I removed the first and left the second sitting in the same

line, because I was treating it as "the `-shortest` bug" instead of "the duration-deciding-flag

bug."

If you're fixing something like this, audit the whole command, not the flag you came for.

And assert the duration afterward as an equality check, not a glance — both failure modes produce

a file that exists, has both streams, and plays:

reddit.com
u/DHSeaDev — 7 days ago
▲ 16 r/ffmpeg

FFmpeg compiler

Is anyone aware of a source-to-source compiler whose target language is FFmpeg’s filtergraph syntax?

With Bioscoop, I am in a position to make certain claims and try to defend them as best as I can. That is why I am submitting a paper to a peer-reviewed journal. Still, I could be wrong and I would love you to challenge me on those claims.
The paper is available in the repo.

u/danielszm — 10 days ago
▲ 6 r/ffmpeg

Is my cutting method lossless?

Here’s what I did:

Step 1: Find keyframes

D:\>ffprobe -loglevel error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=print_section=0 input.webm | findstr "K"

0.000000,K__

1.502000,K__

4.638000,K__

9.510000,K__

[opus @ 0000027726e9c000] Error parsing Opus packet header.

Step 2: Cut at keyframes

ffmpeg -ss 1.502000 -i input.webm -c copy -to 9.510000 output.webm

Start time: 1.502000

End time: 9.510000

Step 3: Check the output video

D:\>ffprobe -loglevel error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=print_section=0 output.webm | findstr "K"

0.000000,K__

3.136000,K__

8.008000,K__

[opus @ 000002292742c000] Error parsing Opus packet header.

I think the output video is lossless because:

1.502000 - 1.502000 = 0.000000

4.638000 - 1.502000 = 3.136000

9.510000 - 1.502000 = 8.008000

The keyframes are simply shifted, so I believe the cut is lossless.

Is my cutting method lossless?

reddit.com
u/SeaGoldmine — 10 days ago
▲ 6 r/ffmpeg

help: -c:V not skipping mjpeg attachments

Hi! Seemingly basic question here so hopefully this is a good forum for it. I have an existing container that includes a video stream, audio, subtitles, and thumbnails in mjpeg format. I'm trying to reencode the video stream while keeping everything else, and to do this I am passing -map 0 -c copy -c:V libx265.

Per the man page, capital V "matches video streams which are not attached pictures, video thumbnails or cover arts." However when I run the command, ffmpeg tries to reencode the pictures anyway. Here's the relevant part of the output:

 Stream #0:4: Video: mjpeg (Progressive), yuvj420p(pc, bt470bg/unknown/unknown), 1013x1500 [SAR 1:1 DAR 1013:1500], 90k tbr, 90k tbn (attached pic)
   Metadata:
     filename        : cover.jpg
     mimetype        : image/jpeg
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 0, only the last option '-c:V libx265' will be used.
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 4, only the last option '-c:V libx265' will be used.
Stream mapping:
 Stream #0:0 -&gt; #0:0 (hevc (native) -&gt; hevc (libx265))
 Stream #0:1 -&gt; #0:1 (copy)
 Stream #0:2 -&gt; #0:2 (copy)
 Stream #0:3 -&gt; #0:3 (copy)
 Stream #0:4 -&gt; #0:4 (mjpeg (native) -&gt; hevc (libx265))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 13.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [error]: Picture width must be an integer multiple of the specified chroma subsampling
[libx265 @ 0x579d4cc5e400] Cannot open libx265 encoder.
[vost#0:4/libx265 @ 0x579d4cc5e000] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
Error while filtering: Invalid data found when processing input
[out#0/matroska @ 0x579d4bcd8340] Nothing was written into output file, because at least one of its streams received no packets.
frame=    0 fps=0.0 q=0.0 Lq=0.0 size=       0kB time=N/A bitrate=N/A speed=N/A     
Conversion failed!

So ffmpeg is classifying the thumbnail (stream 4) as a video, but recognizing it's an attached picture, but still applying -c:V libx265 to it. (Here, it's also then bailing out because it can't convert the picture, but even if the parameters lined up for it to succeed, that's not what I want anyway. It shouldn't even be trying to convert.) The above output is from v6.1.1, which is what's in Ubuntu LTS, but the behavior reproduces in the latest v9.0 compiled from source.

Now in this case I could just write a script to detect which video streams are present and exclude or drop the thumbnails. But this seems like such a simple issue, and one that capital V is explicitly available to solve, so I'd like to figure out why it isn't working. Am I holding it wrong? Or any other ideas?

reddit.com
u/andaphantie — 14 days ago
▲ 2 r/ffmpeg

HLS stream takes 3–4 seconds to start could the manifest TTFB be the bottleneck?

I’m looking into an HLS stream that takes around 3–4 seconds before playback starts.

The initial .m3u8 request has noticeably higher TTFB than I’d like, so I’m trying to figure out how much of the startup delay is coming from the manifest request itself.

I’m considering edge-caching the .m3u8 manifest to reduce the distance between the viewer and the initial request.

For those who have optimized HLS startup times, did caching the manifest at the edge make a noticeable difference for you? Or were other parts of the startup sequence usually a bigger factor?

reddit.com
u/Slow_Height3706 — 12 days ago