View Full Version : Can I determine the reference frame while I encoding images into a video
r01922112
23rd February 2014, 08:35
Hello, everyone.
I recently needed to encode some images into a video. Can I determine which image is a I-frame during the process of encoding images into a video or determine which image is its reference frame while encoding P-frame?
The first method come to my mind is to use ffmpeg to implement.The reason is that it seems be easy for beginners. In ffmpeg I use libx264 as encoding library. I have used google to search some introductions about using libx264 in ffmpeg.
Until now I just found the parameter related about this is "ref" which can determine the number of reference frame.
But I can't find any parameter about what I wanted. Can anyone help me about this? Thank you very much!
BTW.If I violate rules in Doom9's Forum.Please tell me.Thamks.
Warperus
26th February 2014, 12:07
Can I determine which image is a I-frame
yes
determine which image is its reference frame while encoding P-frame?
no
As far as I remember (no 3D involved), x264 works with one video stream at once, so every frame has its unique number. They start from 0 with increment by 1 per frame.
Knowing frame numbers you can use --qpfile option.
For example:
x264 --preset slow --profile high --tune film --crf 18 -o blablabla.h264 my_input.mp4 --qpfile my_input.qp
If my_input.qp contains this:
10 I
11 P
12 P
You'll be pretty sure frame 10 will be I-frame, while 11 frame will be P-frame and 12 frame will be P-frame.
What reference frames will be used in P frames is out of direct control, but if you force I-frame it will start new GoP and if you use closed GoP, there will be no other reference frame here for P-frames.
sneaker_ger
26th February 2014, 12:13
They start from 1 with increment by 1 per frame.
Careful, many video encoding softwares start counting at 0. This also applies to x264's qpfile.
raffriff42
26th February 2014, 14:47
I recently needed to encode some images into a video.Are you talking about an image sequence (http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence), or are you talking about mixed still images and video (http://trac.ffmpeg.org/wiki/FilteringGuide)?
Can I determine which image is a I-frameWhy would you want to do this? Let the codec determine I-frames automatically (https://en.wikipedia.org/wiki/Video_compression_picture_types#Intra_coded_frames.2Fslices_.28I.E2.80.91frames.2Fslices_or_Key_frames.29), no?
r01922112
2nd March 2014, 05:25
Thanks guys helped me and answered me actively.I appreciate it.
Can I determine which image is a I-frame yes
Thanks! I got it.
determine which image is its reference frame while encoding P-frame?no
Thanks.Can you tell me any other tool which can use parameter to do this without tracing code?
What reference frames will be used in P frames is out of direct control, but if you force I-frame it will start new GoP and if you use closed GoP, there will be no other reference frame here for P-frames.
I am not sure what you mean in this paragraph.Can you give me more detailed explanation ? Thanks a lot
Are you talking about an image sequence, or are you talking about mixed still images and video?
In my experiment,I just test only images.
BTW I still have one question.Can ffmpeg has a mode which the frame just refer the previous frame? ex: 2 refer 1, 3 refer 2,4 refer 3.If I set parameter profile "basic" ,ffmpeg will follow the above the way to choose reference frame.
Warperus
4th March 2014, 12:46
Can you tell me any other tool which can use parameter to do this without tracing code?
I don't know of any tool that allows such low-level control of encoding.
Can you give me more detailed explanation ?
I frame starts new GoP (http://en.wikipedia.org/wiki/Group_of_pictures).
For closed GoP every P-frame should refer for inter-frame prediction (http://en.wikipedia.org/wiki/Inter-frame) to i-frame or I-frame within GoP. It is also possible that P frame will use reference to itself. This restriction is not enforced for open-gop encoding (--open-gop parameter for x264), there P-frame can use reference frames from wider range of frames.
Asmodian
7th March 2014, 03:12
Can't a P-frame reference previous P frames in the same (closed) GoP as well, not only I or i-frames?
foxyshadis
8th March 2014, 08:42
Thanks.Can you tell me any other tool which can use parameter to do this without tracing code?
You'll have to modify your encoder of choice to get it to print out the utilized reference frames as you encode. (Printing the full reference list each frame might be possible, but not every frame in the DPB is necessarily used.) Otherwise, tools like Mainconcept StreamEye will show you every reference of each frame, as well as the individual references used by each macroblock.
BTW I still have one question.Can ffmpeg has a mode which the frame just refer the previous frame? ex: 2 refer 1, 3 refer 2,4 refer 3.If I set parameter profile "basic" ,ffmpeg will follow the above the way to choose reference frame.
Use only a single reference frame (--ref 1) with no B-frames.
pandy
14th March 2014, 15:31
Until now I just found the parameter related about this is "ref" which can determine the number of reference frame.
But I can't find any parameter about what I wanted. Can anyone help me about this? Thank you very much!
BTW.If I violate rules in Doom9's Forum.Please tell me.Thamks.
Take log file from first pass and modify it before 2 pass - this sound most logical and reasonable to me - then you can force encoder to set type and reference as you wish - i see justification for this - for example synthetic streams to test particular feature on decoder (such as trick modes, zapping speed etc)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.