Live data from Hacker News

FFMPEG from Zero to Hero

ffmpegfromzerotohero.com

121–130 of 140 posts

Re: FFMPEG from Zero to Hero

#121
post #7

If this book does what it claims to do, it should probably cost more (pls raise the price after I buy it). I strongly believe that inside ffmpeg may be the secret to the cosmos, the universe and life itself

I just had to tangle with ffmpeg to stream some video from a spacecraft. I’m genuinely undecided as to which end of that problem was the more complicated one.

Please elaborate, is this a work or hobby project, which space craft?

Re: FFMPEG from Zero to Hero

#122

Earlier quoted context omitted.

Yeah, it is literally not possible to not seek to keyframe if you are stream copying. There are however, plenty of great software that can but at any frame and only re-encode the frames that are outside the whole GOP. Most of them are commercial though, I haven't find one that is free and good. ---- Also, seeking in FFMPEG in practice, is actually more complicated than the guide [1] you linked. Below is a note I keep…

>The best of the two worlds is to use input seeking for -ss and then output seeking for -to. Could you clarify what you mean with "use output seeking for -to"? From your Python script it seems that you're just using input seeking and then specifying the duration in seconds with `-t`, which is actually the same as using `-to` when doing input seeking. Also, input seeking should be inaccurate when doing stream copy, so…

I think I know where you're confused: from the guide it looks like there is only a difference where you put -ss; but in reality, where you put -t/-to matters too.

In my Python script, I did input seeking for -ss (start point) part, and then output seeking for -t part (end point). As you can see, the -ss part is before -i {inputfile}, and -t is after.

-ss 1:00 -i file -t 5

is NOT the same as

-ss 1:00 -t 5 -i file.

The latter has a bug that happens frequently when I'm trimming MPEG-TS files recorded from HDTV. It literally doesn't stop at the -t/-to timestamp for reason I don't know. And it only happens when stream copy.

Below is a quick showcase: t.ts is the source, and the filenames show how I generate them with FFMPEG (for example, ss_t_i means input seeking -ss first, then -i t.ts, then -t 1:00).

https://i.imgur.com/lLUSzEM.png

As you can see, if I use -t/-to before -i, it doesn't cut the file properly.

>Also, input seeking should be inaccurate when doing stream copy

Yeah, it's not frame accurate, can only cut at keyframes, but enough for my application. By the way the same inaccuracy exists for output seeking if you're doing stream copy.

Re: FFMPEG from Zero to Hero

#123

FFMPEG exposes a terrible API. Even something as simple as thumbnail extraction is overly complex and has a ton of pitfalls that you won't discover until a user uploads a weirdly encoded video.

how is it ffmpeg's fault for a goofy user suppled input?

It's ffmpeg's fault that the correct implementation is overly complex. You will think that your code is correct, but actually there is a flag somewhere you have to set, or you have to copy something from one buffer to another. Due to the drastically large input space of different codecs and settings for each codec and how corruption is handled can make it hard to test. Instead of there being a simple API, there are all sorts of things you just have to know you should do. The examples given by the ffmpeg project are not enough. It's a case of there being many unknown unknowns.

Re: FFMPEG from Zero to Hero

#124

FFMPEG exposes a terrible API. Even something as simple as thumbnail extraction is overly complex and has a ton of pitfalls that you won't discover until a user uploads a weirdly encoded video.

FFMPEG's API is perfect for what it aims to provide. Not every program is built for every use-case. It's trivial to create helper scripts to provide a simpler API for simple tasks, in fact this is probably how FFMPEG and ImageMagick are most often used; in image, video editing programs and servers.

FFMPEG's API is far from perfect. In order to work with a video in a memory buffer you literally have to write part of a virtual filesystem driver. That is not perfect API design. You should just let me pass in a memory buffer and length. I am not really bothered with how verbose it can be since it is rather low level. What I am bothered by are undocumented pitfalls in demuxing, decoding, and handling color spaces. Ideally their should be an API that handles taking care of all the pitfalls correctly or there should be documentation explaining the pitfalls and how to avoid them.

Re: FFMPEG from Zero to Hero

#125

Earlier quoted context omitted.

>The best of the two worlds is to use input seeking for -ss and then output seeking for -to. Could you clarify what you mean with "use output seeking for -to"? From your Python script it seems that you're just using input seeking and then specifying the duration in seconds with `-t`, which is actually the same as using `-to` when doing input seeking. Also, input seeking should be inaccurate when doing stream copy, so…

I think I know where you're confused: from the guide it looks like there is only a difference where you put -ss; but in reality, where you put -t/-to matters too. In my Python script, I did input seeking for -ss (start point) part, and then output seeking for -t part (end point). As you can see, the -ss part is before -i {inputfile}, and -t is after. -ss 1:00 -i file -t 5 is NOT the same as -ss 1:00 -t 5 -i file. The…

Edit: I just reported the bug to ffmpeg tracker: https://trac.ffmpeg.org/ticket/9141

Re: FFMPEG from Zero to Hero

#126
post #2

Might have come in handy while I was struggling to type out ffmpeg -i part0.mp4 -i part1.mp4 -filter_complex "[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v1]; [0:v] [0:a] [v1] [1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" out.mp4 to concatenate two videos with different sizes today. My relation with it is almost identical to my relation with any bash scripting m…

> I have to relearn it every time I want to engage with it

That's my relation with regex.

Re: FFMPEG from Zero to Hero

#127
post #126
post #2

Might have come in handy while I was struggling to type out ffmpeg -i part0.mp4 -i part1.mp4 -filter_complex "[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v1]; [0:v] [0:a] [v1] [1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" out.mp4 to concatenate two videos with different sizes today. My relation with it is almost identical to my relation with any bash scripting m…

> I have to relearn it every time I want to engage with it That's my relation with regex.

I’ve heard this a few times. I’m the opposite, I think I learned it once and never forgot it, it seems impossible. Do you understand regex in terms of a state machine? Draw it out. It’s a very simple language.

Re: FFMPEG from Zero to Hero

#128

Something weird (IMO) about ffmpeg is that it doesn't do hardware-accelerated encoding or decoding by default unless you compile it with support and pass it some extra command line flags. If you are using ffmpeg with hardware-accelerated codecs like H.264, remember to take the free 10x speed boost!

> If you are using ffmpeg with hardware-accelerated codecs like H.264, remember to take the free 10x speed boost!

The speed boost isn't free, hardware accelerated encoders often can't compress as well as software encoders.

A video codec isn't a fixed rule book that all the encoders follow to get the same result, it's more akin to CSS: there are a bunch of tools you can use but there's no one way to combine them to get a particular result. If you want to make a chess board with HTML and CSS, just think of how many ways there are to do it, it's similar when it comes to video encoding.

So different encoders have different results but why would a hardware encoder compress worse than a software encoder? The answer is simple: a hardware encoder needs to be implemented in hardware. That comes with a ton of constraints that CPU encoders don't have to deal with, such as physical space on silicon, power, heat, limited memory and so on and so forth. This means that the encoder has to make compromises that a software encoder doesn't.

So how big is the difference? It depends a bit how you measure it but Moscow State University has a ton [0] of data about different encoders and just last year, they evaluated a bunch of hardware encoders [1] and compared them to software. You can see in their results [2] that relative to x264 (software, which happens to be ffmpeg's default), NVENC (NVIDIA's encoder, present on their GPUs) took 21.3% more bytes to produce the same subjective result.

[0]: https://www.compression.ru/video/codec_comparison/index_en.h...

[1]: https://www.compression.ru/video/codec_comparison/hevc_2020/...

[2]: https://i.imgur.com/Smh4v3P.png

Re: FFMPEG from Zero to Hero

#129
post #7

Earlier quoted context omitted.

I just had to tangle with ffmpeg to stream some video from a spacecraft. I’m genuinely undecided as to which end of that problem was the more complicated one.

Please elaborate, is this a work or hobby project, which space craft?

I'm not OP, but I suspect it is weather sat imagery: you can use SDR to receive images captured by NOAAA weather satellites[1]

1. https://www.rtl-sdr.com/rtl-sdr-tutorial-receiving-noaa-weat...

Re: FFMPEG from Zero to Hero

#130
I'm really interested in learning how to fix bad files that have been recorded from a live RTP (or WebRTC) stream. These files tend to have gaps in their PTS or DTS, caused by UDP packet loss when the streaming took place.

There are a myriad of StackOverflow questions, mailing lists, forums... but never a well structured and comprehensive analysis of this topic. And FFmpeg itself, while being a feat of a software project, has such a lackluster and incomplete doc.

I'd like to see a discussion about recovering H.264 and VP8 timestamps, with minimal processing (i.e. not transcoding, if possible, otherwise of course it becomes an easy thing), which covered the whys and whens of using these FFmpeg options:

• -fflags +genpts

• -fflags +igndts

• -vsync

• -copyts

• -use_wallclock_as_timestamps

Does this book cover these options and the topic of timestamp reconstruction?

Post reply on HN