Live data from Hacker News

FFmpeg School of Assembly Language

github.com

131–140 of 226 posts

Re: FFmpeg School of Assembly Language

#131
I'll be honest, I didn't read through much. Ffmpeg gives me severe ptsd. My first task out of college was to write a procedurally generated video using ffmpeg, conform to dash, and get it under 150kb/s while being readable. Docs were unusable. Dash was only a few months old. And stackoverflow was devoid of help. I kid you not, the only way to get any insight was some sketchy IRC channel. (2016 btw, well past IRCs prime)

Re: FFmpeg School of Assembly Language

#132
post #42

I'm shocked there still isn't a hardware accelerator for video decoding.

Practically every computer device manufactured in the last 15 years has some sort of accelerator/specific instructions designed primarily for optimizing the decoding of video.

Re: FFmpeg School of Assembly Language

#133
post #131

I'll be honest, I didn't read through much. Ffmpeg gives me severe ptsd. My first task out of college was to write a procedurally generated video using ffmpeg, conform to dash, and get it under 150kb/s while being readable. Docs were unusable. Dash was only a few months old. And stackoverflow was devoid of help. I kid you not, the only way to get any insight was some sketchy IRC channel. (2016 btw, well past IRCs pri…

Not trying to be too negative but the memories your comment brought up in me, I need to rant about ffmpeg for a minute. ffmpeg is the worst documented major library I've ever used in my life. I integrated with it to render videos inside my 3D engine and boy do I shiver at any thought of having to work with it again.

The "documentation" is a collect of 15-20 year old source samples. The vast majority of them either won't compile anymore because the API has changed, or they use 2, 3, or 4 times deprecated functions that shouldn't be used anymore. The source examples also have almost no comments explaining anything. They have super dense, super complicated code, with no comments, but then there will be a line like "setRenderSpeed(3)" or whatever and it'll have a comment: "Sets render speed to 3", the absolute most useless comment ever. The source examples are also all written in 30 year old as C-Style of C code as you can get, incredibly horribly dense, with almost no organization, have to jump up and down all over the file to find the global variables being accessed, it's just gross and barely comprehensible.

They put a lot of effort into producing doxygen documentation for everything, but the doxygen documentation is nearly useless, it just lists the API with effectively zero documentation or explanation on the functions or parameters. There's so little explanation of how to do anything. On the website they have sections for each library, and for most libraries you get 2-3 sentences of explanation on what the library is for, and that's it. That's the extent the entire library is documented. They just drop an undocumented massive C API split across a dozen or so libraries on you and wish you luck.

The API has also gotten absolutely wrecked over the last 20 years or however long it's been around as it has evolved. Sometimes they straight up delete functions to deprecate them, sometimes they create a new version of a function as fuction2 and then as function3, and keep all of them around, sometimes they replace a function with a completely differently named function and keep them both around, and there's absolutely nothing written anywhere about what the "right" way to do anything is, what functions you should actually be using. So many times I went down rabbit holes reading some obscure 15 year old mailing list post trying to find anyone that had successfully done something I was trying to do. And again, the obscure message board posts and documentation that does exist is almost all deprecated at this point and shouldn't be used.

Then there's the custom build system, so if you need to build it custom to support or not support different features, you can't use any modern build system, it's all custom scripts that do weird things like hardcoded dumping build output into your home directory. Makes it difficult to integrate with a modern build system.

It has so much momentum, and so many users, but man, there has to be a massive opening for someone to replace ffmpeg with a modern programming language and a modern build system, built with GPU acceleration of stuff in mind from the beginning and not tacked on top 20 years later, and not using 30 year old c-style code, and an actually documented project.

Re: FFmpeg School of Assembly Language

#134

I am the author of these lessons. Ask me anything.

Hi, thanks for your work! I have a question, as someone who can just about read assembly but still do not intuitively understand how to write or decompose ideas to utilise assembly, do you have any suggestions to learn / improve this? As in, at what point would someone realise this thing can be sped up by using assembly? If one found a function that would be really performant in assembly how do you go about writing i…

This is one heck of a question.

I don't know assembly, but my advice would be to take the rote route by rewriting stuff in assembly.

Just like anything else, there's no quick path to the finish line (unless you're exceptionally gifted), so putting in time is always the best action to take.

Re: FFmpeg School of Assembly Language

#135

I am the author of these lessons. Ask me anything.

What's your perspective on variable-width SIMD instruction sets (like ARM SVE or the RISC-V V extension)? How does developer ergonomics and code performance compare to traditional SIMD? Are we approaching a world with fewer different SIMD instruction sets to program for?

Re: FFmpeg School of Assembly Language

#136
post #131

I'll be honest, I didn't read through much. Ffmpeg gives me severe ptsd. My first task out of college was to write a procedurally generated video using ffmpeg, conform to dash, and get it under 150kb/s while being readable. Docs were unusable. Dash was only a few months old. And stackoverflow was devoid of help. I kid you not, the only way to get any insight was some sketchy IRC channel. (2016 btw, well past IRCs pri…

Not trying to be too negative but the memories your comment brought up in me, I need to rant about ffmpeg for a minute. ffmpeg is the worst documented major library I've ever used in my life. I integrated with it to render videos inside my 3D engine and boy do I shiver at any thought of having to work with it again. The "documentation" is a collect of 15-20 year old source samples. The vast majority of them either wo…

Heres a few lines out of the 700 line shell script; ${FFMPEG_CMD} -y -i $SIL -i ${STEP1_Q} -i $SIL -i ${STEP1_Q} -i $SIL -i ${STEP1_Q} -i $SIL -i ${ATTN_Q} -i $SIL -i ${ALERT_Q} -i ${STEP2BOUT} -i $SIL -i ${EOM_Q} -i $SIL -i ${EOM_Q} -i $SIL -i ${EOM_Q} -i $LOW -i $LOW -filter_complex concat=n=19:v=0:a=1 ${STEP2OUT} 2>> ${LOG_FILE} ... ${FFMPEG_CMD} -y -i ${STEP3OUT} -vf drawtext="fontfile=${FONT_FILE}:textfile=${INCOMING_DIR}/${VIDEO_LANG}.txt:fontcolor=white:fontsize=36:y=h-h/3:x=w-120*t" -b:v 9000k -maxrate 9000k -minrate 9000k -bufsize 1890k -acodec copy ${STEP4OUT} 2>> ${LOG_FILE} ...${FFMPEG_CMD} -i ${STEP2OUT} -f lavfi -i color=c=red:s=640x480:d="${TOTAL_CRAWLTIME}" -vf "subtitles=${SUBTITLES_FILE}:force_style='Alignment=10,Outline=0,Fontsize=18', subtitles=${SLIDE_NUMBERS_FILE}:force_style='Alignment=2,Outline=0', drawtext=fontfile=${FONT_FILE}:fontsize=30:fontcolor=white:y=line_h:x=(w-text_w)/2:text='MESSAGE D’FOO ou foo', drawtext=fontfile=${FONT_FILE}:fontsize=20:fontcolor=white:y=(h-80):x=(w-text_w)/2:text='English message to follow.'" -b:v 9000k -maxrate 9000k -minrate 9000k -bufsize 1890k -acodec libmp3lame ${STEP4OUT} 2>> ${LOG_FILE} ${FFMPEG_CMD} -y -i ${STEP5OUT} -vcodec libx264 -x264opts keyint=60:min-keyint=30:ref=3:bframes=0 -profile:v Main -level 3.1 -s 576:432 -g 60 -r 29.970 -crf 22 -maxrate:v 300k -bufsize 600k -acodec aac -ab 32k -ar 22050 -ac 1 -vbsf h264_mp4toannexb ${OUTPUT_DIR}/${BASE_FILE_NAME}.ts 2>> ${LOG_FILE}

Re: FFmpeg School of Assembly Language

#137
post #136

Earlier quoted context omitted.

Not trying to be too negative but the memories your comment brought up in me, I need to rant about ffmpeg for a minute. ffmpeg is the worst documented major library I've ever used in my life. I integrated with it to render videos inside my 3D engine and boy do I shiver at any thought of having to work with it again. The "documentation" is a collect of 15-20 year old source samples. The vast majority of them either wo…

Heres a few lines out of the 700 line shell script; ${FFMPEG_CMD} -y -i $SIL -i ${STEP1_Q} -i $SIL -i ${STEP1_Q} -i $SIL -i ${STEP1_Q} -i $SIL -i ${ATTN_Q} -i $SIL -i ${ALERT_Q} -i ${STEP2BOUT} -i $SIL -i ${EOM_Q} -i $SIL -i ${EOM_Q} -i $SIL -i ${EOM_Q} -i $LOW -i $LOW -filter_complex concat=n=19:v=0:a=1 ${STEP2OUT} 2>> ${LOG_FILE} ... ${FFMPEG_CMD} -y -i ${STEP3OUT} -vf drawtext="fontfile=${FONT_FILE}:textfile=${INC…

might as well be assembly lol

Re: FFmpeg School of Assembly Language

#138
post #2

The only thing I don't like about this is the focus on x86 assembly, which is a sinking ship because RISC-V is coming to eat its lunch, FAST.

Doesn't RISC-V use vector stream processing instead of SIMD? That's a poor fit for ffmpeg.

I should say, I think it would be. I haven't actually tried it and know ARM has added it too, so it'd be interesting to see for sure.

Re: FFmpeg School of Assembly Language

#139
post #62

I personally don't think there's much value in writing assembly (vs using intrinsics), but it's been really helpful to read it. I have often used Compiler Explorer ( https://godbolt.org/ ) to look at the assembly generated and understand optimizations that compilers perform when optimizing for performance.

Your commented is directly contradicted by the article.

> To make multimedia processing fast. It’s very common to get a 10x or more speed improvement from writing assembly code, which is especially important when wanting to play videos in real time without stuttering.

Re: FFmpeg School of Assembly Language

#140
post #76

> Note that the “q” suffix refers to the size of the pointer *(*i.e in C it represents *sizeof(*src) == 8 on 64-bit systems, and x86asm is smart enough to use 32-bit on 32-bit systems) but the underlying load is 128-bit. I find that sentence confusing. I assume that i.e is supposed to be i.e., but What is *(* supposed to mean? Shouldn't that be just an open parenthesis? In what context would *sizeof(*src) be consider…

Wouldn't it return the size of the pointer? I would guess it's exclusively used to handle architecture differences

Strictly speaking, or maybe just the way I personally think of it, sizeof doesn't return anything. It's not a function, so it doesn't return at all. (At least, not at run time.)

Nitpicking aside, the result of sizeof(*src) would be the size of the object at which the pointer points. The type of that result is size_t. That's what makes this code from the lesson I quoted invalid:

*sizeof(*src)

That first asterisk tries to dereference the result of sizeof as though it were a pointer, but it's a size_t: an unsigned integer type. Not a pointer.

Post reply on HN