Sorry for repeating posts about the same problem, however, it is very
important for me.
I am kind of missing some basics about MPEG2 video and will be happy if
someone can explain me this or point to the tutorial/explanation.

My goal is to cut some fragments from a video clip and save them to another
shorter video clip. 
As I've written earlier, suppose this: |==*****======********==| is the
initial video clip, spread in time.

I must obtain the shorter video clip, containing only (*) frames, (=) frames
must be discarded. 

I have some success with this, but when the clip is played, in the place,
where two different (*) fragments meet, some "transition" effects occur with
squares of invalid data.

These effects occur because a movie player meets some B-frames, which don't
have corresponding P or I frame (it was discarded as falling in (=) area)
and builds corresponding picture basing on wrong data. 

I must get rid of these effect, so that the clip was played smoothly.

Overall, my strategy is the following.
1. av_read_frame(input, &pkt); av_free_packet(&pkt) until the I-frame is
met.
  Then save that I-frame and go to point 2 below

2. av_read_frame(input, &pkt) ; av_write_frame(output,&pkt) ;
av_free_packet(&pkt) until the end of the fragment is met. 
 Then av_read_frame(input, &pkt) ; av_write_frame(output,&pkt) ;
av_free_packet(&pkt) until the I-frame is met. 
Save that I-frame (and free packet, of course).

3. av_seek_frame to the beginning of the next fragment and go to point 1
above.

What is wrong in that algorithm?

When processing the second fragment I correct timestamps of the read frames
so that avoid big gaps in timestamps in the resulting video. They are
correct, and basing on them solely, a movie player should play everything as
I suppose. 
However, that's not the case.
If I load the resulting video in the avidemux program ( http://avidemux.org/
) and have it show frames step by step, it appears that two B-frames which
follow the first I-frame in the second fragment (as av_read_frame gives
them) are displayed before that I-frame.

-- 
View this message in context: 
http://www.nabble.com/Again%2C-about-cutting-video-fragments-and-saving-them-to-MPEG2-file.-tp18650093p18650093.html
Sent from the libav-users mailing list archive at Nabble.com.

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to