Michael Rampe
Forum Replies Created
-
Michael Rampe
June 17, 2010 at 8:36 am in reply to: Can ffmpeg copy frames into different container?Hi Ben,
DISCLAIMER: I do not now and have not ever been employed by any of the companies listed.
I don’t really know if this will be helpful or not but I thought I would list a few things anyway.
Here are some things to look for after a first thought on this, you should be able to find most of them for free on the web but may have to register with some sites to get access to them. Sorry for not providing links but I do not have them handy and we all have google. This list is by no means thorough or complete, just a few good places to start.
[Ben Southall] “how a stream of raw images is taken”
“A Guide to Standard and High-Definition Digital Video Measurements” by Tektronix is very good. Also, look into the history of camera pickup types (tube–>CCD–>CMOS–>???) In regards to the mathematics of digital video systems, anything by Charles Poynton is good, especially in regards to chroma sub-sampling. (and his “A Tutorial on Magic Numbers for High Definition Electronic Production” is great to understand why certain numbers have to be used for video over others.)[Ben Southall] “compressed”
The “DV_Compression_Primer” by Adobe is slightly inaccurately named as it covers other compression methods than DV but good for a novice. “The Digital Fact Book” by Quantel is very comprehensive and explains most concepts related to Digital Video in relatively simple language. Tektronix also have produced a glossary which is incredibly thorough but harder to read for a novice.“The Engineer’s Guide to Compression” and “The Engineer’s Guide to Motion Compensation” by Snell & Wilcox are very detailed. (“The Engineer’s guide to Decoding & Encoding”, also by Snell & Wilcox, is excellent for a historical perspective on analogue encoding which is still important for a full understanding of why digital is the way it is.) Look for other articles/whitepapers from Snell & Wilcox as they are excellent, including “Mpeg Encoding Basics” & “Mpeg Video” are a must.
[Ben Southall] “put together inside a container”
For Quicktime movies (and thus the very closely related mp4 spec) look for the “Quicktime File Format Specification” by Apple (QTFF.pdf) Also worth looking into transport streams and possibly the MXF format. Not too sure about sources for AVI/WMV or others….[Ben Southall] “and eventually turned into a video”
This is simply the reverse of the rest of the process;-)Companies to look for:
Quantel
Snell&Wilcox
Grass Valley
Thomson
Tektronix
(basically high end broadcast equipment manufacturers)And finally, look the the standards creators. IEEE, SMPTE, MPEG etc. Most papers and standards usually come with a hefty fee and may not be what you are after anyway but these are the main gatekeepers in this area;-)
Helpful? maybe. maybe not. This is a BIG topic!!!
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
Michael Rampe
June 16, 2010 at 12:01 am in reply to: Can ffmpeg copy frames into different container?[Ben Southall] “May I ask you where you learnt all of this stuff?”
Well not from any school that teaches this stuff or a single comprehensive website (I don’t think either of these exist). Basically, using video for a number of years, reading spec files (QTFF.pdf is good), reading manuals, scanning the web and most importantly trying out things;-)
[Ben Southall] “I was looking for some tutorials about, basically, how audio and video files work, but haven’t come across any.”
Anything specific?
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
I hadn’t heard about this named piping technique but it looks interesting.
After a quick look, this seems both complicated and well documented but I will give you a quick rundown.
Basically:
#FFmpeg –> named pipe (fifo) –> x264
FFmpeg decodes the video stream to raw data and passes it to a named pipe.
x264 inputs this named pipe and exports raw data.I am assuming (possibly incorrectly) that you then have to pass this raw stream back to FFmpeg to put in a container, for example, mp4.
#FFmpeg –> named pipe –> x264 –> named pipe –> FFmpeg
Of course, you will probably want audio with your video as well and x264 is not an audio encoder;-) Best to split that whilst decompressing the original stream and map back in after the video has been encoded with x264.
#FFmpeg –> named pipe –> x264 –> named pipe –> FFmpeg
#FFmpeg————-> named pipe (audio)—————>/You can always just run the commands concatenated (one by one) instead if you are not too concerned by time.
https://forums.creativecow.net/readpost/291/70I will look into it further.
Good luck for now.
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
-
Michael Rampe
June 14, 2010 at 10:57 pm in reply to: Can ffmpeg copy frames into different container?Yes.
“-vcodec copy” and “-acodec copy” will pass the video/audio streams to the new container untouched.
Specify the container type in the output filename. ie. output.mp4 or output.avi
Do not expect all codec/container combinations to be valid.
For example: copying H.264 to transport streams (.ts) requires the use of a video bitstream filter, “-vbsf h264_mp4toannexb” to be valid.
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
After a bit of tinkering, I think I have got the result I was looking for. Open source bitrate graphing with frame type identification. The following two images are the results of one pass and two pass x264 encoding with FFmpeg. IPB frames are identified by colour. NOTE: As labelled, the y dimension is measured in Bytes per frame.
For context or interest, this is the test video that I have used for this experiment. (I created it with Blender, another great open source program;-)
I chose/created this video specifically for its inherently variable bitrate structure.
For the unix minded, how I did it?
Let me know if you get stuck;-)
# SOFTWARE NEEDED (all open source)
FFmpeg (>SVN-r23145), FFprobe FFprobe (>SVN-r92, currently being merged into FFmpeg as of time of posting) gnuplot (>4.2), grep, sed.# COMMAND LINE
./ffprobe -show_frames funnyhq.mp4 | grep ‘size\|coded_picture_number\|pict_type’ > raw.dat && paste -s -d ‘\t\t\n’ raw.dat > fixed.dat && sed -e ‘s/coded_picture_number=//g’ -e ‘s/size=//g’ -e ‘s/pict_type=//g’ -e ‘s/I/167116800/g’ -e ‘s/P/65280/g’ -e ‘s/B/255/g’ fixed.dat > column.dat && gnuplot plot.txt# GNUPLOT “plot.txt”
set title “1pass”
set xlabel “frame number\n\n./ffmpeg -i funny_bubbles.mov -vcodec libx264 -vpre hq -b 1500k funnyhq.mp4”
set ylabel “Bytes per frame”
set yrange [0:35000]
set ytics (35000, 30000, 25000, 20000, 15000, 10000, 5000)
set xrange [-10:850]
set lmargin 12
set rmargin 2
set grid
set pointsize 2
set label 1 “I frames”
set label 1 at graph .85, .96 tc lt 1
set label 2 “P frames”
set label 2 at graph .85, .92 tc lt 2
set label 3 “B frames”
set label 3 at graph .85, .88 tc lt 3
plot ‘column.dat’ using 2:3:1 notitle with i lc rgb variableNow, to work out how to write a sh script to make it easier.
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
[Rodney Baker] “(but I’m not a programmer so I’m not the right person to ask about that).”
Me either;-)
I did get some good results just then with:
./ffprobe -show_frames two_pass.mp4 | grep ‘size\|coded_picture_number’ > raw.dat && paste -s -d ‘\t\n’ raw.dat > fixed.dat && sed -e ‘s/coded_picture_number=//g’ -e ‘s/size=//g’ fixed.dat > column.dat && gnuplot plot11. FFprobe lists all frame details
2. grep strips all lines except size and picture number and writes to a file
3. paste combines lines two by two from previous file to new file
4. sed takes the new file and strips the unnecessary text and creates a data file
5. gnuplot plots the datafile to image output(the gnuplot “plot1” file contains:
set yrange [0:15000]
set ytics (15000, 10000, 5000)
set xrange [0:200]
set lmargin 9
set rmargin 2
plot ‘column.dat’ using 1:2 notitle with lines)Not very elegant but it works as a proof of concept.
Thanks for your nudges in the right directions.
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
Hi Rodney,
I managed to get gnuplot to show the data after creating the following datafile manually from the data in my previous post.
0 822.000
1 219.000
2 515.000
3 942.000
5 2292.000
4 3896.000
7 5546.000I have had a quick look into sed and awk. Looks tricky. I will keep investigating.
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
Did some digging and found out that:
AVC (H.264) uses a different quantizer scale (1-51) than most other codecs (1-31)
Try -qmin 51 -qmax 51
This should give you the absolute minimum for AVC/H.264/Mpeg4Layer10 video.
Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”
-
[Ben Southall] “I’m afraid that this made the bitrate even larger!?!?!?”
Good. This means these are overriding the -b setting. -qmin 1 -qmax 1 should produce the highest quality. (1 is highest, 31 is lowest) Now reduce them until you get the result you desire (or to see the lowest, set them to -qmin 31 -qmax -31) You can also use -qscale n to set an average but it will deviate during encoding.
From the FFmpeg documentation:
The parameter ‘q’ which is displayed while encoding is the current quantizer. The value 1 indicates that a very good quality could be achieved. The value 31 indicates the worst quality. If q=31 appears too often, it means that the encoder cannot compress enough to meet your bitrate. You must either increase the bitrate, decrease the frame rate or decrease the frame size.Michael
“half-way to world domination A.K.A. the belligerent blue bike shed”





