Comments (5)
Thanks a ton, I get it now :)
from ffmpeg-libav-tutorial.
// for each frame we take the Y plane (think of a huge "2d" array containing all the pixels)
// and the linesize (wrap - size in bytes of each picture line) if we use a byte per pixel then it's equals to width
// , width, height, and the file name
save_gray_frame(pFrame->data[0], pFrame->linesize[0], pFrame->width, pFrame->height, frame_filename);
// we must write the minimal header (providing resolution and magical string)
fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);
// and finally we just need to write to the file
// since we write line by line then what we do is just to use the ysize iteration
// (one increment for i, up to the frame height((yssize))
// FOR THAT matter, we use pointer arithmetics and
for (i = 0; i < ysize; i++)
// fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
// a pointer (updated/calculated each line) of size 1 but
// writes xsize items of data on file f
fwrite(buf + i * wrap, 1, xsize, f);
Anyway, to sum up, buf + i * wrap
it's just a way to move for the next line in number of bytes. Let's do a simple simulation here:
height=720
width=1280
for i = 0; i < height; i++
// for 0 we just point to the start of the buffer
buf(0x00000) + 0 * 1280 = 0
storing 1280 bytes
// for 1 we just move the pointer to the next line
buf(0x00000) + 1 * 1280 = 1280
....
links
- https://ffmpeg.org/doxygen/trunk/structAVFrame.html#aa52bfc6605f6a3059a0c3226cc0f6567
- https://ffmpeg.org/doxygen/trunk/structAVFrame.html#a1d0f65014a8d1bf78cec8cbed2304992
- https://en.wikipedia.org/wiki/Netpbm_format#PGM_example
- https://man7.org/linux/man-pages/man3/fwrite.3.html
from ffmpeg-libav-tutorial.
if you still have doubts, feel comfortable to ask.
from ffmpeg-libav-tutorial.
Does the data stream itself get multiplied?
No, think of buf
as an address to the memory where the data stream starts, then if you do buf + 1
what is effectively happening is you're now pointing to the start address + 1 byte
, then if you transpose that for any operation you are just moving where to start reading.
# an oversimplification of a memory
memory = []
memory[0x000] = 0xFF # random information on memory
memory[0x001] = 0x2B # random information on memory
# ....
memory[0xFC1] = 0x03 # the data stream starts here
memory[0xFC2] = 0x3A
memory[0xFC3] = 0x19
memory[0xFC4] = 0xFB
buff = 0xFC1
# when we do any arithmetic it changes the address
from ffmpeg-libav-tutorial.
Does the data stream itself get multiplied? I know that it doesn't, but why does that work? Thanks btw, I appreciate this a lot. I'm new to C++, this is the first library that I'm learning haha.
from ffmpeg-libav-tutorial.
Related Issues (20)
- Cannot build Docker image HOT 2
- How to work with rgb values instead of grayscale
- Fix no PTS and delay for realtime streaming
- Misleading tutorial example HOT 3
- Read mp4 DASH from server, decode 16 channel AAC and send to buffer
- A simple question unrelated to this nice tutorial HOT 2
- Unknown decoder 'libx264' HOT 2
- deleted
- 1Gbps means 1 billion bits HOT 1
- fatal error: libavcodec/avcodec.h: No such file or directory HOT 1
- "COM must not be in STA mode\n" HOT 3
- "Broken pipe" on av_interleaved_write_frame when used to stream HOT 2
- ffmpeg
- error in transcoding audio from mp3 to aac HOT 2
- some warnings in 0_hello_world.c
- There is not function named "av_mallocz_array" in the recent ffmpeg library
- avformat_close_input() vs avformat_free_context()
- Compiling on Windows with GCC HOT 1
- define pCodec
- Getting error when running. (Close to the end of the 0-hello-world) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ffmpeg-libav-tutorial.