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 #define _LARGEFILE_SOURCE
22 #define _FILE_OFFSET_BITS 64
26 #include <sys/types.h>
28 #include "common/common.h"
43 #include <gpac/isomedia.h>
46 static int64_t gcd( int64_t a, int64_t b )
64 /* raw 420 yuv file operation */
65 int open_file_yuv( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
67 yuv_input_t *h = malloc(sizeof(yuv_input_t));
68 h->width = p_param->i_width;
69 h->height = p_param->i_height;
72 if( !strcmp(psz_filename, "-") )
75 h->fh = fopen(psz_filename, "rb");
83 int get_frame_total_yuv( hnd_t handle )
85 yuv_input_t *h = handle;
86 int i_frame_total = 0;
88 if( !fseek( h->fh, 0, SEEK_END ) )
90 uint64_t i_size = ftell( h->fh );
91 fseek( h->fh, 0, SEEK_SET );
92 i_frame_total = (int)(i_size / ( h->width * h->height * 3 / 2 ));
98 int read_frame_yuv( x264_picture_t *p_pic, hnd_t handle, int i_frame )
100 yuv_input_t *h = handle;
102 if( i_frame != h->next_frame )
103 if( fseek( h->fh, (uint64_t)i_frame * h->width * h->height * 3 / 2, SEEK_SET ) )
106 if( fread( p_pic->img.plane[0], 1, h->width * h->height, h->fh ) <= 0
107 || fread( p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh ) <= 0
108 || fread( p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh ) <= 0 )
111 h->next_frame = i_frame+1;
116 int close_file_yuv(hnd_t handle)
118 yuv_input_t *h = handle;
126 /* YUV4MPEG2 raw 420 yuv file operation */
131 int seq_header_len, frame_header_len;
135 #define Y4M_MAGIC "YUV4MPEG2"
136 #define MAX_YUV4_HEADER 80
137 #define Y4M_FRAME_MAGIC "FRAME"
138 #define MAX_FRAME_HEADER 80
140 int open_file_y4m( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
144 char header[MAX_YUV4_HEADER+10];
145 char *tokstart, *tokend, *header_end;
146 y4m_input_t *h = malloc(sizeof(y4m_input_t));
150 if( !strcmp(psz_filename, "-") )
153 h->fh = fopen(psz_filename, "rb");
157 h->frame_header_len = strlen(Y4M_FRAME_MAGIC)+1;
160 for( i=0; i<MAX_YUV4_HEADER; i++ )
162 header[i] = fgetc(h->fh);
163 if( header[i] == '\n' )
165 /* Add a space after last option. Makes parsing "444" vs
166 "444alpha" easier. */
172 if( i == MAX_YUV4_HEADER || strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)) )
175 /* Scan properties */
176 header_end = &header[i+1]; /* Include space */
177 h->seq_header_len = i+1;
178 for( tokstart = &header[strlen(Y4M_MAGIC)+1]; tokstart < header_end; tokstart++ )
180 if(*tokstart==0x20) continue;
183 case 'W': /* Width. Required. */
184 h->width = p_param->i_width = strtol(tokstart, &tokend, 10);
187 case 'H': /* Height. Required. */
188 h->height = p_param->i_height = strtol(tokstart, &tokend, 10);
191 case 'C': /* Color space */
192 if( strncmp("420", tokstart, 3) )
194 fprintf(stderr, "Colorspace unhandled\n");
197 tokstart = strchr(tokstart, 0x20);
199 case 'I': /* Interlace type */
202 case 'p': interlaced = 0; break;
207 default: interlaced = 1;
208 fprintf(stderr, "Warning, this sequence might be interlaced\n");
211 case 'F': /* Frame rate - 0:0 if unknown */
212 if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
214 x264_reduce_fraction( &n, &d );
215 p_param->i_fps_num = n;
216 p_param->i_fps_den = d;
218 tokstart = strchr(tokstart, 0x20);
220 case 'A': /* Pixel aspect - 0:0 if unknown */
221 if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
223 x264_reduce_fraction( &n, &d );
224 p_param->vui.i_sar_width = n;
225 p_param->vui.i_sar_height = d;
227 tokstart = strchr(tokstart, 0x20);
229 case 'X': /* Vendor extensions */
230 if( !strncmp("YSCSS=",tokstart,6) )
232 /* Older nonstandard pixel format representation */
234 if( strncmp("420JPEG",tokstart,7) &&
235 strncmp("420MPEG2",tokstart,8) &&
236 strncmp("420PALDV",tokstart,8) )
238 fprintf(stderr, "Unsupported extended colorspace\n");
242 tokstart = strchr(tokstart, 0x20);
247 fprintf(stderr, "yuv4mpeg: %ix%i@%i/%ifps, %i:%i\n",
248 h->width, h->height, p_param->i_fps_num, p_param->i_fps_den,
249 p_param->vui.i_sar_width, p_param->vui.i_sar_height);
251 *p_handle = (hnd_t)h;
255 /* Most common case: frame_header = "FRAME" */
256 int get_frame_total_y4m( hnd_t handle )
258 y4m_input_t *h = handle;
259 int i_frame_total = 0;
260 off_t init_pos = ftell(h->fh);
262 if( !fseek( h->fh, 0, SEEK_END ) )
264 uint64_t i_size = ftell( h->fh );
265 fseek( h->fh, init_pos, SEEK_SET );
266 i_frame_total = (int)((i_size - h->seq_header_len) /
267 (3*(h->width*h->height)/2+h->frame_header_len));
270 return i_frame_total;
273 int read_frame_y4m( x264_picture_t *p_pic, hnd_t handle, int i_frame )
275 int slen = strlen(Y4M_FRAME_MAGIC);
278 y4m_input_t *h = handle;
280 if( i_frame != h->next_frame )
282 if (fseek(h->fh, (uint64_t)i_frame*(3*(h->width*h->height)/2+h->frame_header_len)
283 + h->seq_header_len, SEEK_SET))
287 /* Read frame header - without terminating '\n' */
288 if (fread(header, 1, slen, h->fh) != slen)
292 if (strncmp(header, Y4M_FRAME_MAGIC, slen))
294 fprintf(stderr, "Bad header magic (%08X <=> %s)\n",
295 *((uint32_t*)header), header);
299 /* Skip most of it */
300 while (i<MAX_FRAME_HEADER && fgetc(h->fh) != '\n')
302 if (i == MAX_FRAME_HEADER)
304 fprintf(stderr, "Bad frame header!\n");
307 h->frame_header_len = i+slen+1;
309 if( fread(p_pic->img.plane[0], 1, h->width*h->height, h->fh) <= 0
310 || fread(p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh) <= 0
311 || fread(p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh) <= 0)
314 h->next_frame = i_frame+1;
319 int close_file_y4m(hnd_t handle)
321 y4m_input_t *h = handle;
329 /* avs/avi input file support under cygwin */
337 int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
339 avis_input_t *h = malloc(sizeof(avis_input_t));
343 *p_handle = (hnd_t)h;
346 if( AVIStreamOpenFromFile( &h->p_avi, psz_filename, streamtypeVIDEO, 0, OF_READ, NULL ) )
352 if( AVIStreamInfo(h->p_avi, &info, sizeof(AVISTREAMINFO)) )
354 AVIStreamRelease(h->p_avi);
359 // check input format
360 if (info.fccHandler != MAKEFOURCC('Y', 'V', '1', '2'))
362 fprintf( stderr, "avis [error]: unsupported input format (%c%c%c%c)\n",
363 (char)(info.fccHandler & 0xff), (char)((info.fccHandler >> 8) & 0xff),
364 (char)((info.fccHandler >> 16) & 0xff), (char)((info.fccHandler >> 24)) );
366 AVIStreamRelease(h->p_avi);
373 p_param->i_width = info.rcFrame.right - info.rcFrame.left;
375 p_param->i_height = info.rcFrame.bottom - info.rcFrame.top;
376 i = gcd(info.dwRate, info.dwScale);
377 p_param->i_fps_den = info.dwScale / i;
378 p_param->i_fps_num = info.dwRate / i;
380 fprintf( stderr, "avis [info]: %dx%d @ %.2f fps (%d frames)\n",
381 p_param->i_width, p_param->i_height,
382 (double)p_param->i_fps_num / (double)p_param->i_fps_den,
383 (int)info.dwLength );
388 int get_frame_total_avis( hnd_t handle )
390 avis_input_t *h = handle;
393 if( AVIStreamInfo(h->p_avi, &info, sizeof(AVISTREAMINFO)) )
396 return info.dwLength;
399 int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame )
401 avis_input_t *h = handle;
403 p_pic->img.i_csp = X264_CSP_YV12;
405 if( AVIStreamRead(h->p_avi, i_frame, 1, p_pic->img.plane[0], h->width * h->height * 3 / 2, NULL, NULL ) )
411 int close_file_avis( hnd_t handle )
413 avis_input_t *h = handle;
414 AVIStreamRelease(h->p_avi);
424 int (*p_read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame );
425 int (*p_close_infile)( hnd_t handle );
431 struct thread_input_arg_t *next_args;
434 typedef struct thread_input_arg_t {
439 } thread_input_arg_t;
441 int open_file_thread( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
443 thread_input_t *h = malloc(sizeof(thread_input_t));
444 x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height );
445 h->p_read_frame = p_read_frame;
446 h->p_close_infile = p_close_infile;
447 h->p_handle = *p_handle;
449 h->next_args = malloc(sizeof(thread_input_arg_t));
451 h->next_args->status = 0;
452 h->frame_total = p_get_frame_total( h->p_handle );
454 *p_handle = (hnd_t)h;
458 int get_frame_total_thread( hnd_t handle )
460 thread_input_t *h = handle;
461 return h->frame_total;
464 void read_frame_thread_int( thread_input_arg_t *i )
466 i->status = i->h->p_read_frame( i->pic, i->h->p_handle, i->i_frame );
469 int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame )
471 thread_input_t *h = handle;
475 if( h->next_frame >= 0 )
477 pthread_join( h->tid, &stuff );
478 ret |= h->next_args->status;
481 if( h->next_frame == i_frame )
483 XCHG( x264_picture_t, *p_pic, h->pic );
487 ret |= h->p_read_frame( p_pic, h->p_handle, i_frame );
490 if( !h->frame_total || i_frame+1 < h->frame_total )
493 h->next_args->i_frame = i_frame+1;
494 h->next_args->pic = &h->pic;
495 pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args );
503 int close_file_thread( hnd_t handle )
505 thread_input_t *h = handle;
506 h->p_close_infile( h->p_handle );
507 x264_picture_clean( &h->pic );
514 int open_file_bsf( char *psz_filename, hnd_t *p_handle )
516 if ((*p_handle = fopen(psz_filename, "w+b")) == NULL)
522 int set_param_bsf( hnd_t handle, x264_param_t *p_param )
527 int write_nalu_bsf( hnd_t handle, uint8_t *p_nalu, int i_size )
529 if (fwrite(p_nalu, i_size, 1, (FILE *)handle) > 0)
534 int set_eop_bsf( hnd_t handle, x264_picture_t *p_picture )
539 int close_file_bsf( hnd_t handle )
541 if ((handle == NULL) || (handle == stdout))
544 return fclose((FILE *)handle);
547 /* -- mp4 muxing support ------------------------------------------------- */
553 GF_AVCConfig *p_config;
554 GF_ISOSample *p_sample;
566 void recompute_bitrate_mp4(GF_ISOFile *p_file, int i_track)
568 u32 i, count, di, timescale, time_wnd, rate;
573 esd = gf_isom_get_esd(p_file, i_track, 1);
576 esd->decoderConfig->avgBitrate = 0;
577 esd->decoderConfig->maxBitrate = 0;
580 timescale = gf_isom_get_media_timescale(p_file, i_track);
581 count = gf_isom_get_sample_count(p_file, i_track);
582 for (i=0; i<count; i++) {
583 GF_ISOSample *samp = gf_isom_get_sample_info(p_file, i_track, i+1, &di, &offset);
585 if (samp->dataLength>esd->decoderConfig->bufferSizeDB) esd->decoderConfig->bufferSizeDB = samp->dataLength;
587 if (esd->decoderConfig->bufferSizeDB < samp->dataLength) esd->decoderConfig->bufferSizeDB = samp->dataLength;
588 esd->decoderConfig->avgBitrate += samp->dataLength;
589 rate += samp->dataLength;
590 if (samp->DTS > time_wnd + timescale) {
591 if (rate > esd->decoderConfig->maxBitrate) esd->decoderConfig->maxBitrate = rate;
592 time_wnd = samp->DTS;
596 gf_isom_sample_del(&samp);
599 br = (Double) (s64) gf_isom_get_media_duration(p_file, i_track);
601 esd->decoderConfig->avgBitrate = (u32) (esd->decoderConfig->avgBitrate / br);
603 esd->decoderConfig->avgBitrate *= 8;
604 esd->decoderConfig->maxBitrate *= 8;
606 gf_isom_change_mpeg4_description(p_file, i_track, 1, esd);
607 gf_odf_desc_del((GF_Descriptor *) esd);
611 int close_file_mp4( hnd_t handle )
613 mp4_t *p_mp4 = (mp4_t *)handle;
619 gf_odf_avc_cfg_del(p_mp4->p_config);
623 if (p_mp4->p_sample->data)
624 free(p_mp4->p_sample->data);
626 gf_isom_sample_del(&p_mp4->p_sample);
631 recompute_bitrate_mp4(p_mp4->p_file, p_mp4->i_track);
632 gf_isom_set_pl_indication(p_mp4->p_file, GF_ISOM_PL_VISUAL, 0x15);
633 gf_isom_set_storage_mode(p_mp4->p_file, GF_ISOM_STORE_FLAT);
634 gf_isom_close(p_mp4->p_file);
642 int open_file_mp4( char *psz_filename, hnd_t *p_handle )
648 if ((p_mp4 = (mp4_t *)malloc(sizeof(mp4_t))) == NULL)
651 memset(p_mp4, 0, sizeof(mp4_t));
652 p_mp4->p_file = gf_isom_open(psz_filename, GF_ISOM_OPEN_WRITE, NULL);
654 if ((p_mp4->p_sample = gf_isom_sample_new()) == NULL)
656 close_file_mp4( p_mp4 );
660 gf_isom_set_brand_info(p_mp4->p_file, GF_ISOM_BRAND_AVC1, 0);
668 int set_param_mp4( hnd_t handle, x264_param_t *p_param )
670 mp4_t *p_mp4 = (mp4_t *)handle;
672 p_mp4->i_track = gf_isom_new_track(p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
675 p_mp4->p_config = gf_odf_avc_cfg_new();
676 gf_isom_avc_config_new(p_mp4->p_file, p_mp4->i_track, p_mp4->p_config,
677 NULL, NULL, &p_mp4->i_descidx);
679 gf_isom_set_track_enabled(p_mp4->p_file, p_mp4->i_track, 1);
681 gf_isom_set_visual_info(p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx,
682 p_param->i_width, p_param->i_height);
684 p_mp4->p_sample->data = (char *)malloc(p_param->i_width * p_param->i_height * 3 / 2);
685 if (p_mp4->p_sample->data == NULL)
688 p_mp4->i_time_res = p_param->i_fps_num;
689 p_mp4->i_time_inc = p_param->i_fps_den;
690 p_mp4->i_init_delay = p_param->i_bframe ? (p_param->b_bframe_pyramid ? 2 : 1) : 0;
691 p_mp4->i_init_delay *= p_mp4->i_time_inc;
692 fprintf(stderr, "mp4 [info]: initial delay %d (scale %d)\n",
693 p_mp4->i_init_delay, p_mp4->i_time_res);
699 int write_nalu_mp4( hnd_t handle, uint8_t *p_nalu, int i_size )
701 mp4_t *p_mp4 = (mp4_t *)handle;
702 GF_AVCConfigSlot *p_slot;
703 uint8_t type = p_nalu[4] & 0x1f;
712 p_mp4->p_config->configurationVersion = 1;
713 p_mp4->p_config->AVCProfileIndication = p_nalu[5];
714 p_mp4->p_config->profile_compatibility = p_nalu[6];
715 p_mp4->p_config->AVCLevelIndication = p_nalu[7];
716 p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
717 p_slot->size = i_size - 4;
718 p_slot->data = (char *)malloc(p_slot->size);
719 memcpy(p_slot->data, p_nalu + 4, i_size - 4);
720 gf_list_add(p_mp4->p_config->sequenceParameterSets, p_slot);
730 p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
731 p_slot->size = i_size - 4;
732 p_slot->data = (char *)malloc(p_slot->size);
733 memcpy(p_slot->data, p_nalu + 4, i_size - 4);
734 gf_list_add(p_mp4->p_config->pictureParameterSets, p_slot);
738 gf_isom_avc_config_update(p_mp4->p_file, p_mp4->i_track, 1, p_mp4->p_config);
747 memcpy(p_mp4->p_sample->data + p_mp4->p_sample->dataLength, p_nalu, i_size);
748 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 0] = (psize >> 24) & 0xff;
749 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 1] = (psize >> 16) & 0xff;
750 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 2] = (psize >> 8) & 0xff;
751 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 3] = (psize >> 0) & 0xff;
752 p_mp4->p_sample->dataLength += i_size;
759 int set_eop_mp4( hnd_t handle, x264_picture_t *p_picture )
761 mp4_t *p_mp4 = (mp4_t *)handle;
762 uint64_t dts = (uint64_t)p_mp4->i_numframe * p_mp4->i_time_inc;
763 uint64_t pts = (uint64_t)p_picture->i_pts;
764 int32_t offset = p_mp4->i_init_delay + pts - dts;
766 p_mp4->p_sample->IsRAP = p_picture->i_type == X264_TYPE_IDR ? 1 : 0;
767 p_mp4->p_sample->DTS = dts;
768 p_mp4->p_sample->CTS_Offset = offset;
769 gf_isom_add_sample(p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_mp4->p_sample);
771 p_mp4->p_sample->dataLength = 0;
780 /* -- mkv muxing support ------------------------------------------------- */
786 int sps_len, pps_len;
788 int width, height, d_width, d_height;
790 int64_t frame_duration;
793 int b_header_written;
794 char b_writing_frame;
797 int write_header_mkv( mkv_t *p_mkv )
803 if( p_mkv->sps == NULL || p_mkv->pps == NULL ||
804 p_mkv->width == 0 || p_mkv->height == 0 ||
805 p_mkv->d_width == 0 || p_mkv->d_height == 0)
808 avcC_len = 5 + 1 + 2 + p_mkv->sps_len + 1 + 2 + p_mkv->pps_len;
809 avcC = malloc(avcC_len);
814 avcC[1] = p_mkv->sps[1];
815 avcC[2] = p_mkv->sps[2];
816 avcC[3] = p_mkv->sps[3];
817 avcC[4] = 0xff; // nalu size length is four bytes
818 avcC[5] = 0xe1; // one sps
820 avcC[6] = p_mkv->sps_len >> 8;
821 avcC[7] = p_mkv->sps_len;
823 memcpy(avcC+8, p_mkv->sps, p_mkv->sps_len);
825 avcC[8+p_mkv->sps_len] = 1; // one pps
826 avcC[9+p_mkv->sps_len] = p_mkv->pps_len >> 8;
827 avcC[10+p_mkv->sps_len] = p_mkv->pps_len;
829 memcpy( avcC+11+p_mkv->sps_len, p_mkv->pps, p_mkv->pps_len );
831 ret = mk_writeHeader( p_mkv->w, "x264", "V_MPEG4/ISO/AVC",
832 avcC, avcC_len, p_mkv->frame_duration, 50000,
833 p_mkv->width, p_mkv->height,
834 p_mkv->d_width, p_mkv->d_height );
838 p_mkv->b_header_written = 1;
843 int open_file_mkv( char *psz_filename, hnd_t *p_handle )
849 p_mkv = malloc(sizeof(*p_mkv));
853 memset(p_mkv, 0, sizeof(*p_mkv));
855 p_mkv->w = mk_createWriter(psz_filename);
856 if (p_mkv->w == NULL)
867 int set_param_mkv( hnd_t handle, x264_param_t *p_param )
869 mkv_t *p_mkv = handle;
872 if( p_param->i_fps_num > 0 )
874 p_mkv->frame_duration = (int64_t)p_param->i_fps_den *
875 (int64_t)1000000000 / p_param->i_fps_num;
876 p_mkv->fps_num = p_param->i_fps_num;
880 p_mkv->frame_duration = 0;
884 p_mkv->width = p_param->i_width;
885 p_mkv->height = p_param->i_height;
887 if( p_param->vui.i_sar_width && p_param->vui.i_sar_height )
889 dw = (int64_t)p_param->i_width * p_param->vui.i_sar_width;
890 dh = (int64_t)p_param->i_height * p_param->vui.i_sar_height;
894 dw = p_param->i_width;
895 dh = p_param->i_height;
898 if( dw > 0 && dh > 0 )
900 int64_t x = gcd( dw, dh );
905 p_mkv->d_width = (int)dw;
906 p_mkv->d_height = (int)dh;
911 int write_nalu_mkv( hnd_t handle, uint8_t *p_nalu, int i_size )
913 mkv_t *p_mkv = handle;
914 uint8_t type = p_nalu[4] & 0x1f;
924 p_mkv->sps = malloc(i_size - 4);
925 if (p_mkv->sps == NULL)
927 p_mkv->sps_len = i_size - 4;
928 memcpy(p_mkv->sps, p_nalu + 4, i_size - 4);
936 p_mkv->pps = malloc(i_size - 4);
937 if (p_mkv->pps == NULL)
939 p_mkv->pps_len = i_size - 4;
940 memcpy(p_mkv->pps, p_nalu + 4, i_size - 4);
948 if( !p_mkv->b_writing_frame )
950 if( mk_startFrame(p_mkv->w) < 0 )
952 p_mkv->b_writing_frame = 1;
955 dsize[0] = psize >> 24;
956 dsize[1] = psize >> 16;
957 dsize[2] = psize >> 8;
959 if( mk_addFrameData(p_mkv->w, dsize, 4) < 0 ||
960 mk_addFrameData(p_mkv->w, p_nalu + 4, i_size - 4) < 0 )
968 if( !p_mkv->b_header_written && p_mkv->pps && p_mkv->sps &&
969 write_header_mkv(p_mkv) < 0 )
975 int set_eop_mkv( hnd_t handle, x264_picture_t *p_picture )
977 mkv_t *p_mkv = handle;
978 int64_t i_stamp = (int64_t)(p_picture->i_pts * 1e9 / p_mkv->fps_num);
980 p_mkv->b_writing_frame = 0;
982 return mk_setFrameFlags( p_mkv->w, i_stamp,
983 p_picture->i_type == X264_TYPE_IDR );
986 int close_file_mkv( hnd_t handle )
988 mkv_t *p_mkv = handle;
996 ret = mk_close(p_mkv->w);