C + FFmpeg + Raylib = High Quality Videos (YES! It IS that simple!)

Поділитися
Вставка
  • Опубліковано 29 жов 2024

КОМЕНТАРІ • 106

  • @raylibtech
    @raylibtech Рік тому +149

    Hey! Very nice session! Really enjoyable and educational! Thanks! 😄
    Some comments:
    - To get color from integer, raylib provides: `Color GetColor(unsigned int hexValue)`
    - In raylib all functions that allocate memory start with Load*() and have an Unload*() equivalent
    - Moving data from GPU memory to CPU memory (glReadPixels()) is always extremely slow >_<
    - I always build raylib with my projects, I usually adjust build parameters (the ones in config.h) despite with LTO it is not really needed...
    - Wave is for "audio frames" the same than Image for "pixels", "audio frames" and "pixels" have a number of channels and a size for each channel
    - raylib provides TextFormat() that works like sprintf(), returning a static string formated, very handy for things like DrawText(TextFormat("FPS: %i", GetFPS()), 10, 10, 20, GREEN);

    • @TsodingDaily
      @TsodingDaily  Рік тому +66

      Hey! Thank you for making raylib btw! I may look a bit grumpy on my sessions. But this is because I'm in a working mode. :D Raylib saved me a lot of time.

    • @raylibtech
      @raylibtech Рік тому +56

      @@TsodingDaily Hahaha... nah! Sessions are great! You are doing really interesting projects and very well explained! 😄

  • @heyyouhere
    @heyyouhere Рік тому +38

    Alexey, great work! Your recreational sessions are super inspiring. Thank you so much!

  • @TV4ELP
    @TV4ELP Рік тому +59

    There are two kinds of people "We cant malloc two times in a single frame" and then every game dev currently "haha memory goes brrrrr"

    • @soniablanche5672
      @soniablanche5672 9 місяців тому

      my 32 GB RAM don't care about malloc calls

    • @BlackneeedWasHere
      @BlackneeedWasHere 8 місяців тому

      My 64 GB RAM don’t care about malloc calls

    • @bhavyakukkar
      @bhavyakukkar 8 місяців тому +12

      My 8 GB RAM does :(

    • @dazai826
      @dazai826 4 місяці тому +1

      my 512kb nokia does care about the smallest memory optimizations ;(

  • @winstonstrongarm8929
    @winstonstrongarm8929 Рік тому +35

    I really agree with what you said about passion in this industry, I dropped out of uni and during the first year of my current job, I learned two languages and how to write big code bases using them, I learnt how to setup devops pipelines and implement IaC.
    Now it's become obvious that no one except me cares whether anything is done well or properly. They are killing off the two deploy clusters I set up because they don't want to learn Linux, so the full logging, tracing and metrics system I set up is being replaced with Windows Event Log xD.
    I know I need to leave and find a placee where I can be with passionate people, I'm just starting to worry whether I'm going to be as passionate as I was when I started in Grade 6😂

    • @anon_y_mousse
      @anon_y_mousse Рік тому +15

      I feel that pain of wondering whether anything you do makes a difference. You set up a system that works well, and they replace it with garbage because no one can be assed to learn how to use it, even with a full manual that took hours and hours of work to write. And it's usually with something Windows based too that doesn't even function half as well or have all the features and requires buying a subscription or a completely new piece of software each year. UGH!

    • @ecosta
      @ecosta Рік тому +8

      If you want real passion around you, go back to Uni and keep studying until you have seven different PhDs or something. Like Tsoding said, business kills passion. Back in College, I was surrounded by crazy passionate people talking crazy stuff like Tsoding does and I felt "normal" with my own crazy ideas. In my jobs, I feel depressed because I rarely can go above discussing class names. People nowadays get dazzled how I know Haskell or how I code using only VIM.
      My own passion stays alive with side-projects. It is now self-sustained. The joy of making my own dreams real is something a company will never provide me.

    • @anon_y_mousse
      @anon_y_mousse Рік тому +3

      @@ecosta I also code solely in Vim and it seems to boggle everyone I talk to. Seems like these days, nearly everyone uses the spyware known as VSCode. And you're so right about corporate coding. If you want passion, either avoid major corporations or do a lot of side projects.

    • @pyrus2814
      @pyrus2814 10 місяців тому

      @@ecosta Awful advice. University kills passion like nothing else.

    • @ecosta
      @ecosta 10 місяців тому +1

      @@pyrus2814 I guess it depends on Uni. Still better than trying to have fun in companies.

  • @winstonstrongarm8929
    @winstonstrongarm8929 Рік тому +27

    I would pay so much money to learn from someone as exceptional as you man

    • @vladinosky
      @vladinosky Рік тому +19

      Well isn't it amazing that he gives it all here for free!

    • @NathanHedglin
      @NathanHedglin Рік тому +1

      What do you want to learn ?

  • @russjr08
    @russjr08 Рік тому +17

    Huh, I always saw ffmpeg as some sort of blackbox utility that only the oldest of elders knew the magical sequences to cast its spell properly... But your explanation makes a lot of sense!
    Now I too can cast ffmpeg >:D

  • @ecosta
    @ecosta Рік тому +2

    Some time ago, when I wrote some code to generate frames and pipe them into FFMPEG, I thought: "meh, this is crazy". Now I feel so normal since there are clever people doing something similar... Thanks for the great content!

  • @the_original_dude
    @the_original_dude Рік тому +1

    5:27 you just have to dig
    I've got a job where I'm free to do things however I like (luckily, I didn't have to dig much). Having to solve real world problems is much more satisfying because you're fulfilling a purpose and have actual constraints and users

  • @adel8206
    @adel8206 Рік тому +6

    Great job as always!
    Would be awesome to see you take a shot at building a concurrent web server in C, or maybe sth like reimplementing Golang's 'net' or 'net/http' module in C

  • @batlin
    @batlin Рік тому +1

    Unexpected and enjoyable discussion about the passion-quenching effects of working in corporate programming jobs. Definitely been there and got burnt a few times.

  • @a445fa6sd
    @a445fa6sd Рік тому +9

    It doesn't have to be an array btw, the following works too:
    *(Color*)&(uint32_t){0xFFFF7FFF}
    *(uint32_t*)&(Color){.r=255, .g=127, .b=255, .a=255}
    You can kinda do that with anything, like here is how to print the current time with libc's time.h in a single line:
    printf("%s", ctime(&(time_t){time(NULL)}));
    coumpound literals are a c99 feature and they're great :)

    • @xhivo97
      @xhivo97 Рік тому +1

      Isn't that undefined behavior?

    • @a445fa6sd
      @a445fa6sd Рік тому +2

      ​@@xhivo97 I know the second one is UB, clang even warns with -Wcast-align as Color is 1 byte aligned and uint32_t is 4 bytes aligned. But I'm not sure about the first one, maybe ¯\_(ツ)_/¯
      I looked up the c99 standard to make sure and yeah, section 6.3.2.3.7 says:
      A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the pointed-to type, the behavior is undefined.
      The third one is good tho.

    • @rogo7330
      @rogo7330 Рік тому +1

      @@xhivo97 I think not, because it's like typing strings in quotes instead of allocating some static variable and filling it up byte by byte. The value is there, it just must be stored somewhere. My guess is it works just like string literals, storing value in data section.

    • @xhivo97
      @xhivo97 Рік тому

      I just looked it up and as far as I can tell, if the resulting pointer is correctly aligned it's OK to do otherwise it's undefined behavior. No idea how alignment works and how portable this is though so I would look into that and try to make sure it's going to work on all machines. @@rogo7330

    • @a445fa6sd
      @a445fa6sd Рік тому +1

      @@rogo7330 good thinking, I actually didn't know where struct literals were stored, so I just tested it with gcc and clang. Turns out compound literals are stored on the stack, right next to variables.
      Color color = {.r=255, .g=127, .b=255, .a=255};
      Color *color_p = (Color*)&(uint32_t){0xFFFF7FFF};
      printf("%p
      %p
      %p
      ", &color, color_p, (Color*)&(uint32_t){0xFFFF7FFF});
      // 00000077549DFE40 (we know color is stored on the stack, it's a variable)
      // 00000077549DFE34 (12 bytes down, 4 for the Color literal, 8 for color_ptr)
      // 00000077549DFE30 (4 bytes down for the Color literal)
      turns out I could just have read the standard, in section 6.5.2.5.6, it says:
      If the compound literal occurs outside the body of a function, the object has static storage duration; otherwise, it has automatic storage duration associated with the enclosing block.
      I tested the 'outside the body of a function' version of compound literals too:
      Color g_color = {.r=255, .g=127, .b=255, .a=255};
      Color *g_color_p = (Color*)&(uint32_t){0xFFFF7FFF};
      int main() { printf("%p
      %p
      ", &g_color, g_color_p); }
      // 00007FF765AB4000
      // 00007FF765AB4004
      they are right next to one another!
      damn I love c :)

  • @chomik3873
    @chomik3873 Рік тому +2

    I love the dabs at the very beginning

  • @Jack-sy6di
    @Jack-sy6di Рік тому +8

    The sample at 1:30 is obviously epic but it's frustrating to me that when the drums kick in you don't get a much bigger impact on the visualization. I guess that makes sense since (I'm guessing) drums are kind of like white noise, so adding in drums just gives you a slight increase to every frequency, rather than a dramatic increase to a few frequencies.

    • @TsodingDaily
      @TsodingDaily  Рік тому +11

      Yeah, it is generally very difficult to visualize chiptune in a meaningful way using FFT. Simply by the nature of chiptune. You need to do something interesting with the original notes the sound was generated from.

    • @dirrelito
      @dirrelito Рік тому +1

      Consider doing a wavelet transform instead. There should be one that project out sawtooth and square waves quite well.

  • @antonsimkin
    @antonsimkin Рік тому +7

    Did you know that Tsioding is #13 most viewed twitch programmist?

    • @fantastikam
      @fantastikam Рік тому +1

      no.

    • @bigmistqke
      @bigmistqke Рік тому

      i always thought he was super niche, but i see him popping up everywhere nowadays

  • @caio_c
    @caio_c Рік тому +6

    30:00 I would use an union to do that, it's far more clear what it's doing when you do:
    union {
    Color color;
    uint32_t abgr;
    } convert;
    convert.abgr = 0xFF181818;
    ClearBackground(convert.color);

    • @ElPikacupacabra
      @ElPikacupacabra Рік тому +6

      Indeed, this is casting done right. But I think C programmers love single line shortcuts. I still assign in conditional expressions just to avoid an extra line of code.😁

  • @kwyrky
    @kwyrky Рік тому +1

    Hi Alexey, I found this strange Icon on my phone with an X and opened it and it showed me something which looked like a retweet of you tweeting about musializer… My goto 3D Framework unfortunately does not have very good support for audio yet (not possible to access audio data while playing a Song) and I never had used Raylib before but I thought I would just have a look at the website. Next thing I know I made a Raylib hello world from C# project (since I am too lazy to learn C). I then started to port musializer to C#. Was not expecting it to work out but surprisingly it did after a day so that I am having fun with it playing random music and looking at the visualization. The render to video part is still missing though. Thanks for the cool project!

  • @chrise3402
    @chrise3402 Рік тому

    lolz "can your rust do that?" Thanks for the great videos as always :)

  • @skaruts
    @skaruts Рік тому +2

    27:06 damn! I had no idea you could do such a thing. I was thinking you'd have to delve into bit shifting to get all the components and build a color struct.

  • @fantastikam
    @fantastikam Рік тому +3

    Bro is so smart that codes videos with c

  • @ce5983
    @ce5983 Рік тому

    These vids keep me going 😊

  • @alack
    @alack Рік тому +1

    curious if it's possible to have the rendering not be bound by the music's playtime, so you could potentially render faster no matter how long the track is, since it's just simulated anyways.

  • @q_rsqrt5140
    @q_rsqrt5140 Рік тому +4

    Is Raylib more friendly for recreational programming then SDL or is it just latest fixation?

  • @Gaamaa-oz5ef2lf3n
    @Gaamaa-oz5ef2lf3n 2 місяці тому

    I love your way of swift coding in C++
    Can you please let me know how to render ffmpeg preview on custom window like PictureBox of Form with hwnd ?
    I need to capture on file and show preview on my application window instead of ffplay.
    By the way I wanted on the command line.

  • @dtomvan
    @dtomvan Рік тому +1

    Ooh if this were to work with alsa/pulseaudio, then I would use it as a wallpaper!

  • @Dan-Levi
    @Dan-Levi 2 місяці тому

    Hi and thanks for the great video, very entertaining and a cool little project. Maybe you could implement Hardware/GPU Encoding with the H264 NVIDIA NVENC (`-c:v h264_nvenc`) or for AMD (`-c:v h264_amf` ? ). This could significantly speed up the encoding process. Looking forward to more content like this! Great stuff 👍

  • @TeamUnpro
    @TeamUnpro Рік тому +1

    Dude, seriously, lets be friends.
    I code daily (lately tho brains been a pile of mashed potatoes lol), and atm I'm writing an AI system from the ground up without "traditional" methods (e.g weights / biases) or any guides as a part of a challenge; I need to write any required libs myself :)
    It's a lot of fun, and I encourage you to do something similar, you'd be surprised how much you might enjoy it =D

  • @BryanChance
    @BryanChance Рік тому

    Very cool!

  • @skope2055
    @skope2055 Рік тому

    Great video.

  • @TiejunGao
    @TiejunGao 6 місяців тому

    We can do DrawCircle(x, y, r, (Color){0xFF, 0x18, 0x18, 0x18}); Just split up the integer.

  • @RandomGeometryDashStuff
    @RandomGeometryDashStuff Рік тому +1

    01:09:02 same number of chars but isn't uint64 max 2**64-1?

  • @blackhaze3856
    @blackhaze3856 Рік тому

    Amazing your knowledge....

  • @00000masnnnnnnnnnnnnn
    @00000masnnnnnnnnnnnnn Рік тому +1

    Why the height of bars on left side is always smaller than the center and that of the right side? Its kinda looks right skewed. Can you fix that in your upcoming sessions pls?

    • @TsodingDaily
      @TsodingDaily  Рік тому +4

      There is nothing to fix here. This is how Chiptune looks like because it uses square waves that have this natural ramp due to a lot of harmonics.
      Here is how for example the beginning of the songs "Greetings" by PilotRedSun looks like i.imgur.com/q2DwJJB.png

  • @antonioe.2396
    @antonioe.2396 Рік тому +1

    I understand 10% of this shit I'll go and get better at C then come back

  • @pedrocunha4322
    @pedrocunha4322 Рік тому

    Just wondering have you ever tried to fix some type of compatibility issue in ffmpeg external libraries presented in vcpkg ? might be a silly question so dont judge to hard... ahhaha

  • @SourabhBhat
    @SourabhBhat Рік тому

    26:10 Aren't "union" in C designed for this purpose? Two data structures occupying the same memory? You can define union of Color and rgba, to make it clean!
    Or may be I am missing some dependency of olive.c.

  • @ce5983
    @ce5983 Рік тому

  • @AlguienMas555
    @AlguienMas555 Рік тому

    Passion

  • @danielschmitt5750
    @danielschmitt5750 Рік тому +3

    Can someone explain to me why we not just can cast uint32_t to Color if it is the same in memory anyway?

    • @desertfish74
      @desertfish74 Рік тому

      I am wondering the same thing

    • @anon_y_mousse
      @anon_y_mousse Рік тому +1

      Because it's a structured type.

    • @danielschmitt5750
      @danielschmitt5750 Рік тому

      ​@@anon_y_moussecan you provide a bit a more context please? To me it is not clear why this is a problem if they are both 4 consecutive bytes in memory.

    • @danielschmitt5750
      @danielschmitt5750 Рік тому +4

      Ok I think I kind of got it. You can't just cast them because to C those two are completely different types even if there representation in memory is the same. According to stack overflow the process tsoding used to convert the types is called type punning which is basically the reinterpretation of a block of memory as a different type. You can achieve the same by using a union. Using a union is a bit safer but both approaches may cause portability problems due to different endianess.

    • @anon_y_mousse
      @anon_y_mousse Рік тому

      @@danielschmitt5750 The endianness issue is why it's not portable, though in practice I've rarely encountered an actual big endian platform even using a lot of ARM processors. Ideally, you would put the conversion in a macro so you could control how it's done as per the platform you're compiling for, and the union method would be safer, but not nearly as convenient or pretty.

  • @RandomGeometryDashStuff
    @RandomGeometryDashStuff Рік тому

    01:11:25 how about let user edit ffmpeg arguments manually before starting rendering?

  • @dmitrysarana5859
    @dmitrysarana5859 Рік тому

    How would it look if reduce the radius to the peak? With this thought the second video :). Thank you.

  • @snewl5324
    @snewl5324 Рік тому

    twitter definitely seems like a company that views legacy code as immutable. though, i can see that being an adverse effect of high turnover that their new ceo certainly is not helping

  • @justinpeter5752
    @justinpeter5752 Рік тому

    You have to add coogle into your ide as a lsp/ copilot tool

  • @flleaf
    @flleaf Рік тому +3

    the word "zozi" looks like 2021

  • @mbotegichango5207
    @mbotegichango5207 Рік тому

    well, I think C11 also allows you to do this: void foo(int *x); foo(&(int){5});

  • @pavelkozhemjachenko3902
    @pavelkozhemjachenko3902 Рік тому

    zozin what desktop gui do u use? really interesting

  • @rogo7330
    @rogo7330 Рік тому

    30:37 I done something like that previously in my statusbar for dwm in config.h file (if you know, you know) for array of arrays of shorts. But when I looked at it once again I realised that it kills my braincells and got rid of it. Instead I completly rewrote config logic and put shorts into structures with growing array at the end.

  • @RandomGeometryDashStuff
    @RandomGeometryDashStuff Рік тому

    12:27 the real confusing part is in [output_file_options]: does flag configure video encoder or audio encoder or muxer?

    • @anon_y_mousse
      @anon_y_mousse Рік тому

      You can actually specify with most of the options. Like say you're selecting the audio codec, you can use -c:a "some codec" or you could use -acodec "some codec".

    • @RandomGeometryDashStuff
      @RandomGeometryDashStuff Рік тому

      @@anon_y_mousseyes for video it's `-option:v value`, for audio it's `-option:a value`, but there is *no* `-option:m value` for muxer

    • @anon_y_mousse
      @anon_y_mousse Рік тому

      @@RandomGeometryDashStuff I'd guess that's because of -map and the ability to select the stream you want affected with each setting.

    • @RandomGeometryDashStuff
      @RandomGeometryDashStuff Рік тому

      ​@@anon_y_mousseno, by muxer options I mean stuff like `-movflags +faststart` in mov/mp4/tgp/psp/tg2/ipod/ismv/f4v muxer
      it's unclear does `-movflags +faststart` belong to video encoder or audio encoder or muxer if you don't know the parameter

    • @anon_y_mousse
      @anon_y_mousse Рік тому +1

      @@RandomGeometryDashStuff Since it affects the output, that's where it belongs. Although, as far as I'm aware it's position independent on the command line.

  • @jordixboy
    @jordixboy Рік тому

    Hey man, do you actually work for a company? How do you have so much time

  • @avidiaa
    @avidiaa Рік тому

    Can you make a file system...in rust?

  • @vbachris
    @vbachris Рік тому

    1:11:19 I was like, how does that string function know where the print data is? so when he builds "Oh, I need the buffer" LOL

  • @gge6021
    @gge6021 Рік тому

    mental dmg indeed.

  • @GegoXaren
    @GegoXaren Рік тому +1

    n + 1 :th.

  • @lionelmartinez6810
    @lionelmartinez6810 Рік тому

    me recuerda a manim de 3blue1brown

  • @cold_fruit
    @cold_fruit 10 місяців тому +1

    regarding your comments about the lack of passionate and competent people blowing up in our face - it's already happening. Look around you at the software people use on a daily basis. Every year it gets slower, less stable, and more buggy. Poor performance and poor usability are normalized, while the industry sits on its laurels, oblivious to the damage being done to the software ecosystem.

  • @Myexpectationsarerealistic
    @Myexpectationsarerealistic 5 днів тому

    Duh

  • @sudoalex
    @sudoalex Рік тому +1

    First

  • @soggamer6974
    @soggamer6974 Рік тому +1

    Third

  • @tanzeelahmed9871
    @tanzeelahmed9871 Рік тому

    Second

  • @iampointless
    @iampointless Рік тому

    Get a job ❤

    • @vantadaga
      @vantadaga Рік тому +11

      He has one, its called being a content creator

    • @yeahhhhhhhhhhhhhhhhhhhhhhhhhh
      @yeahhhhhhhhhhhhhhhhhhhhhhhhhh Рік тому

      Do you have any idea how much a job in software engineering makes? Looks like you're the one who needs to get a job.

    • @nofeah89
      @nofeah89 Рік тому +5

      He's doing his job quite well sir.

  • @joshuastories
    @joshuastories Рік тому

    Awesome 🎉