1 /*****************************************************************************
2 * muxers.c: h264 file i/o plugins
3 *****************************************************************************
4 * Copyright (C) 2003-2006 x264 project
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 *****************************************************************************/
21 #include "common/common.h"
30 #include <sys/types.h>
38 #include <gpac/isomedia.h>
41 static int64_t gcd( int64_t a, int64_t b )
59 /* raw 420 yuv file operation */
60 int open_file_yuv( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
62 yuv_input_t *h = malloc(sizeof(yuv_input_t));
63 h->width = p_param->i_width;
64 h->height = p_param->i_height;
67 if( !strcmp(psz_filename, "-") )
70 h->fh = fopen(psz_filename, "rb");
78 int get_frame_total_yuv( hnd_t handle )
80 yuv_input_t *h = handle;
81 int i_frame_total = 0;
83 if( !fseek( h->fh, 0, SEEK_END ) )
85 uint64_t i_size = ftell( h->fh );
86 fseek( h->fh, 0, SEEK_SET );
87 i_frame_total = (int)(i_size / ( h->width * h->height * 3 / 2 ));
93 int read_frame_yuv( x264_picture_t *p_pic, hnd_t handle, int i_frame )
95 yuv_input_t *h = handle;
97 if( i_frame != h->next_frame )
98 if( fseek( h->fh, (uint64_t)i_frame * h->width * h->height * 3 / 2, SEEK_SET ) )
101 if( fread( p_pic->img.plane[0], 1, h->width * h->height, h->fh ) <= 0
102 || fread( p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh ) <= 0
103 || fread( p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh ) <= 0 )
106 h->next_frame = i_frame+1;
111 int close_file_yuv(hnd_t handle)
113 yuv_input_t *h = handle;
121 /* YUV4MPEG2 raw 420 yuv file operation */
126 int seq_header_len, frame_header_len;
130 #define Y4M_MAGIC "YUV4MPEG2"
131 #define MAX_YUV4_HEADER 80
132 #define Y4M_FRAME_MAGIC "FRAME"
133 #define MAX_FRAME_HEADER 80
135 int open_file_y4m( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
139 char header[MAX_YUV4_HEADER+10];
140 char *tokstart, *tokend, *header_end;
141 y4m_input_t *h = malloc(sizeof(y4m_input_t));
145 if( !strcmp(psz_filename, "-") )
148 h->fh = fopen(psz_filename, "rb");
152 h->frame_header_len = strlen(Y4M_FRAME_MAGIC)+1;
155 for( i=0; i<MAX_YUV4_HEADER; i++ )
157 header[i] = fgetc(h->fh);
158 if( header[i] == '\n' )
160 /* Add a space after last option. Makes parsing "444" vs
161 "444alpha" easier. */
167 if( i == MAX_YUV4_HEADER || strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)) )
170 /* Scan properties */
171 header_end = &header[i+1]; /* Include space */
172 h->seq_header_len = i+1;
173 for( tokstart = &header[strlen(Y4M_MAGIC)+1]; tokstart < header_end; tokstart++ )
175 if(*tokstart==0x20) continue;
178 case 'W': /* Width. Required. */
179 h->width = p_param->i_width = strtol(tokstart, &tokend, 10);
182 case 'H': /* Height. Required. */
183 h->height = p_param->i_height = strtol(tokstart, &tokend, 10);
186 case 'C': /* Color space */
187 if( strncmp("420", tokstart, 3) )
189 fprintf(stderr, "Colorspace unhandled\n");
192 tokstart = strchr(tokstart, 0x20);
194 case 'I': /* Interlace type */
197 case 'p': interlaced = 0; break;
202 default: interlaced = 1;
203 fprintf(stderr, "Warning, this sequence might be interlaced\n");
206 case 'F': /* Frame rate - 0:0 if unknown */
207 if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
209 x264_reduce_fraction( &n, &d );
210 p_param->i_fps_num = n;
211 p_param->i_fps_den = d;
213 tokstart = strchr(tokstart, 0x20);
215 case 'A': /* Pixel aspect - 0:0 if unknown */
216 if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
218 x264_reduce_fraction( &n, &d );
219 p_param->vui.i_sar_width = n;
220 p_param->vui.i_sar_height = d;
222 tokstart = strchr(tokstart, 0x20);
224 case 'X': /* Vendor extensions */
225 if( !strncmp("YSCSS=",tokstart,6) )
227 /* Older nonstandard pixel format representation */
229 if( strncmp("420JPEG",tokstart,7) &&
230 strncmp("420MPEG2",tokstart,8) &&
231 strncmp("420PALDV",tokstart,8) )
233 fprintf(stderr, "Unsupported extended colorspace\n");
237 tokstart = strchr(tokstart, 0x20);
242 fprintf(stderr, "yuv4mpeg: %ix%i@%i/%ifps, %i:%i\n",
243 h->width, h->height, p_param->i_fps_num, p_param->i_fps_den,
244 p_param->vui.i_sar_width, p_param->vui.i_sar_height);
246 *p_handle = (hnd_t)h;
250 /* Most common case: frame_header = "FRAME" */
251 int get_frame_total_y4m( hnd_t handle )
253 y4m_input_t *h = handle;
254 int i_frame_total = 0;
255 uint64_t init_pos = ftell(h->fh);
257 if( !fseek( h->fh, 0, SEEK_END ) )
259 uint64_t i_size = ftell( h->fh );
260 fseek( h->fh, init_pos, SEEK_SET );
261 i_frame_total = (int)((i_size - h->seq_header_len) /
262 (3*(h->width*h->height)/2+h->frame_header_len));
265 return i_frame_total;
268 int read_frame_y4m( x264_picture_t *p_pic, hnd_t handle, int i_frame )
270 int slen = strlen(Y4M_FRAME_MAGIC);
273 y4m_input_t *h = handle;
275 if( i_frame != h->next_frame )
277 if (fseek(h->fh, (uint64_t)i_frame*(3*(h->width*h->height)/2+h->frame_header_len)
278 + h->seq_header_len, SEEK_SET))
282 /* Read frame header - without terminating '\n' */
283 if (fread(header, 1, slen, h->fh) != slen)
287 if (strncmp(header, Y4M_FRAME_MAGIC, slen))
289 fprintf(stderr, "Bad header magic (%08X <=> %s)\n",
290 *((uint32_t*)header), header);
294 /* Skip most of it */
295 while (i<MAX_FRAME_HEADER && fgetc(h->fh) != '\n')
297 if (i == MAX_FRAME_HEADER)
299 fprintf(stderr, "Bad frame header!\n");
302 h->frame_header_len = i+slen+1;
304 if( fread(p_pic->img.plane[0], 1, h->width*h->height, h->fh) <= 0
305 || fread(p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh) <= 0
306 || fread(p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh) <= 0)
309 h->next_frame = i_frame+1;
314 int close_file_y4m(hnd_t handle)
316 y4m_input_t *h = handle;
324 /* avs/avi input file support under cygwin */
332 int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
334 avis_input_t *h = malloc(sizeof(avis_input_t));
338 *p_handle = (hnd_t)h;
341 if( AVIStreamOpenFromFile( &h->p_avi, psz_filename, streamtypeVIDEO, 0, OF_READ, NULL ) )
347 if( AVIStreamInfo(h->p_avi, &info, sizeof(AVISTREAMINFO)) )
349 AVIStreamRelease(h->p_avi);
354 // check input format
355 if (info.fccHandler != MAKEFOURCC('Y', 'V', '1', '2'))
357 fprintf( stderr, "avis [error]: unsupported input format (%c%c%c%c)\n",
358 (char)(info.fccHandler & 0xff), (char)((info.fccHandler >> 8) & 0xff),
359 (char)((info.fccHandler >> 16) & 0xff), (char)((info.fccHandler >> 24)) );
361 AVIStreamRelease(h->p_avi);
368 p_param->i_width = info.rcFrame.right - info.rcFrame.left;
370 p_param->i_height = info.rcFrame.bottom - info.rcFrame.top;
371 i = gcd(info.dwRate, info.dwScale);
372 p_param->i_fps_den = info.dwScale / i;
373 p_param->i_fps_num = info.dwRate / i;
375 fprintf( stderr, "avis [info]: %dx%d @ %.2f fps (%d frames)\n",
376 p_param->i_width, p_param->i_height,
377 (double)p_param->i_fps_num / (double)p_param->i_fps_den,
378 (int)info.dwLength );
383 int get_frame_total_avis( hnd_t handle )
385 avis_input_t *h = handle;
388 if( AVIStreamInfo(h->p_avi, &info, sizeof(AVISTREAMINFO)) )
391 return info.dwLength;
394 int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame )
396 avis_input_t *h = handle;
398 p_pic->img.i_csp = X264_CSP_YV12;
400 if( AVIStreamRead(h->p_avi, i_frame, 1, p_pic->img.plane[0], h->width * h->height * 3 / 2, NULL, NULL ) )
406 int close_file_avis( hnd_t handle )
408 avis_input_t *h = handle;
409 AVIStreamRelease(h->p_avi);
419 int (*p_read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame );
420 int (*p_close_infile)( hnd_t handle );
426 struct thread_input_arg_t *next_args;
429 typedef struct thread_input_arg_t {
434 } thread_input_arg_t;
436 int open_file_thread( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
438 thread_input_t *h = malloc(sizeof(thread_input_t));
439 x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height );
440 h->p_read_frame = p_read_frame;
441 h->p_close_infile = p_close_infile;
442 h->p_handle = *p_handle;
444 h->next_args = malloc(sizeof(thread_input_arg_t));
446 h->next_args->status = 0;
447 h->frame_total = p_get_frame_total( h->p_handle );
449 *p_handle = (hnd_t)h;
453 int get_frame_total_thread( hnd_t handle )
455 thread_input_t *h = handle;
456 return h->frame_total;
459 void read_frame_thread_int( thread_input_arg_t *i )
461 i->status = i->h->p_read_frame( i->pic, i->h->p_handle, i->i_frame );
464 int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame )
466 thread_input_t *h = handle;
470 if( h->next_frame >= 0 )
472 x264_pthread_join( h->tid, &stuff );
473 ret |= h->next_args->status;
476 if( h->next_frame == i_frame )
478 XCHG( x264_picture_t, *p_pic, h->pic );
482 ret |= h->p_read_frame( p_pic, h->p_handle, i_frame );
485 if( !h->frame_total || i_frame+1 < h->frame_total )
488 h->next_args->i_frame = i_frame+1;
489 h->next_args->pic = &h->pic;
490 x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args );
498 int close_file_thread( hnd_t handle )
500 thread_input_t *h = handle;
501 h->p_close_infile( h->p_handle );
502 x264_picture_clean( &h->pic );
509 int open_file_bsf( char *psz_filename, hnd_t *p_handle )
511 if ((*p_handle = fopen(psz_filename, "w+b")) == NULL)
517 int set_param_bsf( hnd_t handle, x264_param_t *p_param )
522 int write_nalu_bsf( hnd_t handle, uint8_t *p_nalu, int i_size )
524 if (fwrite(p_nalu, i_size, 1, (FILE *)handle) > 0)
529 int set_eop_bsf( hnd_t handle, x264_picture_t *p_picture )
534 int close_file_bsf( hnd_t handle )
536 if ((handle == NULL) || (handle == stdout))
539 return fclose((FILE *)handle);
542 /* -- mp4 muxing support ------------------------------------------------- */
548 GF_AVCConfig *p_config;
549 GF_ISOSample *p_sample;
561 void recompute_bitrate_mp4(GF_ISOFile *p_file, int i_track)
563 u32 i, count, di, timescale, time_wnd, rate;
568 esd = gf_isom_get_esd(p_file, i_track, 1);
571 esd->decoderConfig->avgBitrate = 0;
572 esd->decoderConfig->maxBitrate = 0;
575 timescale = gf_isom_get_media_timescale(p_file, i_track);
576 count = gf_isom_get_sample_count(p_file, i_track);
577 for (i=0; i<count; i++) {
578 GF_ISOSample *samp = gf_isom_get_sample_info(p_file, i_track, i+1, &di, &offset);
580 if (samp->dataLength>esd->decoderConfig->bufferSizeDB) esd->decoderConfig->bufferSizeDB = samp->dataLength;
582 if (esd->decoderConfig->bufferSizeDB < samp->dataLength) esd->decoderConfig->bufferSizeDB = samp->dataLength;
583 esd->decoderConfig->avgBitrate += samp->dataLength;
584 rate += samp->dataLength;
585 if (samp->DTS > time_wnd + timescale) {
586 if (rate > esd->decoderConfig->maxBitrate) esd->decoderConfig->maxBitrate = rate;
587 time_wnd = samp->DTS;
591 gf_isom_sample_del(&samp);
594 br = (Double) (s64) gf_isom_get_media_duration(p_file, i_track);
596 esd->decoderConfig->avgBitrate = (u32) (esd->decoderConfig->avgBitrate / br);
598 esd->decoderConfig->avgBitrate *= 8;
599 esd->decoderConfig->maxBitrate *= 8;
601 gf_isom_change_mpeg4_description(p_file, i_track, 1, esd);
602 gf_odf_desc_del((GF_Descriptor *) esd);
606 int close_file_mp4( hnd_t handle )
608 mp4_t *p_mp4 = (mp4_t *)handle;
614 gf_odf_avc_cfg_del(p_mp4->p_config);
618 if (p_mp4->p_sample->data)
619 free(p_mp4->p_sample->data);
621 gf_isom_sample_del(&p_mp4->p_sample);
626 recompute_bitrate_mp4(p_mp4->p_file, p_mp4->i_track);
627 gf_isom_set_pl_indication(p_mp4->p_file, GF_ISOM_PL_VISUAL, 0x15);
628 gf_isom_set_storage_mode(p_mp4->p_file, GF_ISOM_STORE_FLAT);
629 gf_isom_close(p_mp4->p_file);
637 int open_file_mp4( char *psz_filename, hnd_t *p_handle )
643 if ((p_mp4 = (mp4_t *)malloc(sizeof(mp4_t))) == NULL)
646 memset(p_mp4, 0, sizeof(mp4_t));
647 p_mp4->p_file = gf_isom_open(psz_filename, GF_ISOM_OPEN_WRITE, NULL);
649 if ((p_mp4->p_sample = gf_isom_sample_new()) == NULL)
651 close_file_mp4( p_mp4 );
655 gf_isom_set_brand_info(p_mp4->p_file, GF_ISOM_BRAND_AVC1, 0);
663 int set_param_mp4( hnd_t handle, x264_param_t *p_param )
665 mp4_t *p_mp4 = (mp4_t *)handle;
667 p_mp4->i_track = gf_isom_new_track(p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
670 p_mp4->p_config = gf_odf_avc_cfg_new();
671 gf_isom_avc_config_new(p_mp4->p_file, p_mp4->i_track, p_mp4->p_config,
672 NULL, NULL, &p_mp4->i_descidx);
674 gf_isom_set_track_enabled(p_mp4->p_file, p_mp4->i_track, 1);
676 gf_isom_set_visual_info(p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx,
677 p_param->i_width, p_param->i_height);
679 p_mp4->p_sample->data = (char *)malloc(p_param->i_width * p_param->i_height * 3 / 2);
680 if (p_mp4->p_sample->data == NULL)
683 p_mp4->i_time_res = p_param->i_fps_num;
684 p_mp4->i_time_inc = p_param->i_fps_den;
685 p_mp4->i_init_delay = p_param->i_bframe ? (p_param->b_bframe_pyramid ? 2 : 1) : 0;
686 p_mp4->i_init_delay *= p_mp4->i_time_inc;
687 fprintf(stderr, "mp4 [info]: initial delay %d (scale %d)\n",
688 p_mp4->i_init_delay, p_mp4->i_time_res);
694 int write_nalu_mp4( hnd_t handle, uint8_t *p_nalu, int i_size )
696 mp4_t *p_mp4 = (mp4_t *)handle;
697 GF_AVCConfigSlot *p_slot;
698 uint8_t type = p_nalu[4] & 0x1f;
707 p_mp4->p_config->configurationVersion = 1;
708 p_mp4->p_config->AVCProfileIndication = p_nalu[5];
709 p_mp4->p_config->profile_compatibility = p_nalu[6];
710 p_mp4->p_config->AVCLevelIndication = p_nalu[7];
711 p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
712 p_slot->size = i_size - 4;
713 p_slot->data = (char *)malloc(p_slot->size);
714 memcpy(p_slot->data, p_nalu + 4, i_size - 4);
715 gf_list_add(p_mp4->p_config->sequenceParameterSets, p_slot);
725 p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
726 p_slot->size = i_size - 4;
727 p_slot->data = (char *)malloc(p_slot->size);
728 memcpy(p_slot->data, p_nalu + 4, i_size - 4);
729 gf_list_add(p_mp4->p_config->pictureParameterSets, p_slot);
733 gf_isom_avc_config_update(p_mp4->p_file, p_mp4->i_track, 1, p_mp4->p_config);
742 memcpy(p_mp4->p_sample->data + p_mp4->p_sample->dataLength, p_nalu, i_size);
743 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 0] = (psize >> 24) & 0xff;
744 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 1] = (psize >> 16) & 0xff;
745 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 2] = (psize >> 8) & 0xff;
746 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 3] = (psize >> 0) & 0xff;
747 p_mp4->p_sample->dataLength += i_size;
754 int set_eop_mp4( hnd_t handle, x264_picture_t *p_picture )
756 mp4_t *p_mp4 = (mp4_t *)handle;
757 uint64_t dts = (uint64_t)p_mp4->i_numframe * p_mp4->i_time_inc;
758 uint64_t pts = (uint64_t)p_picture->i_pts;
759 int32_t offset = p_mp4->i_init_delay + pts - dts;
761 p_mp4->p_sample->IsRAP = p_picture->i_type == X264_TYPE_IDR ? 1 : 0;
762 p_mp4->p_sample->DTS = dts;
763 p_mp4->p_sample->CTS_Offset = offset;
764 gf_isom_add_sample(p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_mp4->p_sample);
766 p_mp4->p_sample->dataLength = 0;
775 /* -- mkv muxing support ------------------------------------------------- */
781 int sps_len, pps_len;
783 int width, height, d_width, d_height;
785 int64_t frame_duration;
788 int b_header_written;
789 char b_writing_frame;
792 int write_header_mkv( mkv_t *p_mkv )
798 if( p_mkv->sps == NULL || p_mkv->pps == NULL ||
799 p_mkv->width == 0 || p_mkv->height == 0 ||
800 p_mkv->d_width == 0 || p_mkv->d_height == 0)
803 avcC_len = 5 + 1 + 2 + p_mkv->sps_len + 1 + 2 + p_mkv->pps_len;
804 avcC = malloc(avcC_len);
809 avcC[1] = p_mkv->sps[1];
810 avcC[2] = p_mkv->sps[2];
811 avcC[3] = p_mkv->sps[3];
812 avcC[4] = 0xff; // nalu size length is four bytes
813 avcC[5] = 0xe1; // one sps
815 avcC[6] = p_mkv->sps_len >> 8;
816 avcC[7] = p_mkv->sps_len;
818 memcpy(avcC+8, p_mkv->sps, p_mkv->sps_len);
820 avcC[8+p_mkv->sps_len] = 1; // one pps
821 avcC[9+p_mkv->sps_len] = p_mkv->pps_len >> 8;
822 avcC[10+p_mkv->sps_len] = p_mkv->pps_len;
824 memcpy( avcC+11+p_mkv->sps_len, p_mkv->pps, p_mkv->pps_len );
826 ret = mk_writeHeader( p_mkv->w, "x264", "V_MPEG4/ISO/AVC",
827 avcC, avcC_len, p_mkv->frame_duration, 50000,
828 p_mkv->width, p_mkv->height,
829 p_mkv->d_width, p_mkv->d_height );
833 p_mkv->b_header_written = 1;
838 int open_file_mkv( char *psz_filename, hnd_t *p_handle )
844 p_mkv = malloc(sizeof(*p_mkv));
848 memset(p_mkv, 0, sizeof(*p_mkv));
850 p_mkv->w = mk_createWriter(psz_filename);
851 if (p_mkv->w == NULL)
862 int set_param_mkv( hnd_t handle, x264_param_t *p_param )
864 mkv_t *p_mkv = handle;
867 if( p_param->i_fps_num > 0 )
869 p_mkv->frame_duration = (int64_t)p_param->i_fps_den *
870 (int64_t)1000000000 / p_param->i_fps_num;
871 p_mkv->fps_num = p_param->i_fps_num;
875 p_mkv->frame_duration = 0;
879 p_mkv->width = p_param->i_width;
880 p_mkv->height = p_param->i_height;
882 if( p_param->vui.i_sar_width && p_param->vui.i_sar_height )
884 dw = (int64_t)p_param->i_width * p_param->vui.i_sar_width;
885 dh = (int64_t)p_param->i_height * p_param->vui.i_sar_height;
889 dw = p_param->i_width;
890 dh = p_param->i_height;
893 if( dw > 0 && dh > 0 )
895 int64_t x = gcd( dw, dh );
900 p_mkv->d_width = (int)dw;
901 p_mkv->d_height = (int)dh;
906 int write_nalu_mkv( hnd_t handle, uint8_t *p_nalu, int i_size )
908 mkv_t *p_mkv = handle;
909 uint8_t type = p_nalu[4] & 0x1f;
919 p_mkv->sps = malloc(i_size - 4);
920 if (p_mkv->sps == NULL)
922 p_mkv->sps_len = i_size - 4;
923 memcpy(p_mkv->sps, p_nalu + 4, i_size - 4);
931 p_mkv->pps = malloc(i_size - 4);
932 if (p_mkv->pps == NULL)
934 p_mkv->pps_len = i_size - 4;
935 memcpy(p_mkv->pps, p_nalu + 4, i_size - 4);
943 if( !p_mkv->b_writing_frame )
945 if( mk_startFrame(p_mkv->w) < 0 )
947 p_mkv->b_writing_frame = 1;
950 dsize[0] = psize >> 24;
951 dsize[1] = psize >> 16;
952 dsize[2] = psize >> 8;
954 if( mk_addFrameData(p_mkv->w, dsize, 4) < 0 ||
955 mk_addFrameData(p_mkv->w, p_nalu + 4, i_size - 4) < 0 )
963 if( !p_mkv->b_header_written && p_mkv->pps && p_mkv->sps &&
964 write_header_mkv(p_mkv) < 0 )
970 int set_eop_mkv( hnd_t handle, x264_picture_t *p_picture )
972 mkv_t *p_mkv = handle;
973 int64_t i_stamp = (int64_t)(p_picture->i_pts * 1e9 / p_mkv->fps_num);
975 p_mkv->b_writing_frame = 0;
977 return mk_setFrameFlags( p_mkv->w, i_stamp,
978 p_picture->i_type == X264_TYPE_IDR );
981 int close_file_mkv( hnd_t handle )
983 mkv_t *p_mkv = handle;
991 ret = mk_close(p_mkv->w);