You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	correctly compute frame flags with closed gop
Originally committed as revision 19304 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
		| @@ -69,6 +69,7 @@ typedef struct { | |||||||
|     int interlaced;       ///< wether picture is interlaced |     int interlaced;       ///< wether picture is interlaced | ||||||
|     int temporal_reordering; |     int temporal_reordering; | ||||||
|     AVRational aspect_ratio; ///< display aspect ratio |     AVRational aspect_ratio; ///< display aspect ratio | ||||||
|  |     int closed_gop;          ///< gop is closed, used in mpeg-2 frame parsing | ||||||
| } MXFStreamContext; | } MXFStreamContext; | ||||||
|  |  | ||||||
| typedef struct { | typedef struct { | ||||||
| @@ -1111,8 +1112,8 @@ static void mxf_write_index_table_segment(AVFormatContext *s) | |||||||
|         put_be32(pb, mxf->edit_units_count);  // num of entries |         put_be32(pb, mxf->edit_units_count);  // num of entries | ||||||
|         put_be32(pb, 11+mxf->slice_count*4);  // size of one entry |         put_be32(pb, 11+mxf->slice_count*4);  // size of one entry | ||||||
|         for (i = 0; i < mxf->edit_units_count; i++) { |         for (i = 0; i < mxf->edit_units_count; i++) { | ||||||
|             if (temporal_reordering) { |  | ||||||
|             int temporal_offset = 0; |             int temporal_offset = 0; | ||||||
|  |             if (temporal_reordering) { | ||||||
|                 for (j = i+1; j < mxf->edit_units_count; j++) { |                 for (j = i+1; j < mxf->edit_units_count; j++) { | ||||||
|                     temporal_offset++; |                     temporal_offset++; | ||||||
|                     if (mxf->index_entries[j].flags & 0x10) { // backward prediction |                     if (mxf->index_entries[j].flags & 0x10) { // backward prediction | ||||||
| @@ -1126,15 +1127,17 @@ static void mxf_write_index_table_segment(AVFormatContext *s) | |||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|             put_byte(pb, temporal_offset); |             put_byte(pb, temporal_offset); | ||||||
|             } else |  | ||||||
|                 put_byte(pb, 0); |  | ||||||
|             if (!(mxf->index_entries[i].flags & 0x33)) { // I frame |             if (!(mxf->index_entries[i].flags & 0x33)) { // I frame | ||||||
|  |                 if (mxf->index_entries[i].flags & 0x40 && // seq header | ||||||
|  |                     (!temporal_reordering || !temporal_offset)) | ||||||
|  |                     mxf->index_entries[i].flags |= 0x80; // random access | ||||||
|                 mxf->last_key_index = key_index; |                 mxf->last_key_index = key_index; | ||||||
|                 key_index = i; |                 key_index = i; | ||||||
|             } |             } | ||||||
|             if (mxf->index_entries[i].flags & 0x10 && // backward prediction |             if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction | ||||||
|                 !(mxf->index_entries[key_index].flags & 0x80)) { // open gop |  | ||||||
|                 put_byte(pb, mxf->last_key_index - i); |                 put_byte(pb, mxf->last_key_index - i); | ||||||
|             } else { |             } else { | ||||||
|                 put_byte(pb, key_index - i); // key frame offset |                 put_byte(pb, key_index - i); // key frame offset | ||||||
| @@ -1315,8 +1318,11 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt | |||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|         } else if (c == 0x1b8) { // gop |         } else if (c == 0x1b8) { // gop | ||||||
|             if (pkt->data[i+4]>>6 & 0x01) // closed |             if (pkt->data[i+4]>>6 & 0x01) { // closed | ||||||
|  |                 sc->closed_gop = 1; | ||||||
|  |                 if (*flags & 0x40) // sequence header present | ||||||
|                     *flags |= 0x80; // random access |                     *flags |= 0x80; // random access | ||||||
|  |             } | ||||||
|             if (!mxf->header_written) { |             if (!mxf->header_written) { | ||||||
|                 unsigned hours   =  (pkt->data[i+1]>>2) & 0x1f; |                 unsigned hours   =  (pkt->data[i+1]>>2) & 0x1f; | ||||||
|                 unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4); |                 unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4); | ||||||
| @@ -1347,7 +1353,11 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt | |||||||
|             if (pict_type == 2) { // P frame |             if (pict_type == 2) { // P frame | ||||||
|                 *flags |= 0x22; |                 *flags |= 0x22; | ||||||
|                 st->codec->gop_size = 1; |                 st->codec->gop_size = 1; | ||||||
|  |                 sc->closed_gop = 0; // reset closed gop, don't matter anymore | ||||||
|             } else if (pict_type == 3) { // B frame |             } else if (pict_type == 3) { // B frame | ||||||
|  |                 if (sc->closed_gop) | ||||||
|  |                     *flags |= 0x13; // only backward prediction | ||||||
|  |                 else | ||||||
|                     *flags |= 0x33; |                     *flags |= 0x33; | ||||||
|                 sc->temporal_reordering = -1; |                 sc->temporal_reordering = -1; | ||||||
|             } else if (!pict_type) { |             } else if (!pict_type) { | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ bc5e914594523f7c48f9e044c9a9c0b6 *./tests/data/b-lavf.avi | |||||||
| bfdec98337e6a9d89dc648d1e65a41db *./tests/data/b-lavf.mpg | bfdec98337e6a9d89dc648d1e65a41db *./tests/data/b-lavf.mpg | ||||||
| 378880 ./tests/data/b-lavf.mpg | 378880 ./tests/data/b-lavf.mpg | ||||||
| ./tests/data/b-lavf.mpg CRC=0xaf760568 | ./tests/data/b-lavf.mpg CRC=0xaf760568 | ||||||
| 259a87c8d22aab76665047ecdbfa9267 *./tests/data/b-lavf.mxf | 36ea24816444a40fa47b866a409a79b0 *./tests/data/b-lavf.mxf | ||||||
| 535097 ./tests/data/b-lavf.mxf | 535097 ./tests/data/b-lavf.mxf | ||||||
| ./tests/data/b-lavf.mxf CRC=0xd7ff387d | ./tests/data/b-lavf.mxf CRC=0xd7ff387d | ||||||
| 0a7cc51de3da754ce36dffeeda290c45 *./tests/data/b-lavf.mxf_d10 | 0a7cc51de3da754ce36dffeeda290c45 *./tests/data/b-lavf.mxf_d10 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user