[Fixed] fopen needs "b" flag for MinGW build

Archive of historical bug reports.
Please use the GitHub link above to report issues.
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
Post Reply
golgol7777
Posts: 12
Joined: Thu Jun 04, 2009 1:20 pm

[Fixed] fopen needs "b" flag for MinGW build

Post by golgol7777 »

-Version: CLI svn r2494
-Platform & OS: Windows XP Pro SP3
-Source: VOB (ripped from a DVD), but the problem also occurs when I transcode directly from DVD or ISO
-Settings: -e x264 -q 0.6 --vfr -E faac -B 128 -6 stereo -R 48 -D 1.0 -X 480 -Y 270 --crop 60:60:8:8 --custom-anamorphic --pixel-aspect 1:1
-Reproducibility: Yes

Hi

I compiled CLI (svn r2494) as MinGW binary, and tried to encode some DVD source with it.
Encoding finished normally (no crash or error) but encoded video was very jerky when it's playbacked.
I watched the activity log and found there are a lot of warnings like below:
[03:32:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 48048, next 51051, dur 3003)
which does not appear when I use Cygwin build of CLI with the same source and setting.

Here is the console output.

Code: Select all

[03:32:33] hb_init: checking cpu count
[03:32:33] hb_init: starting libhb thread
HandBrake svn2494 (2009060701) - MinGW i686 - http://handbrake.fr
2 CPUs detected
[03:32:33] hb_scan: path=D:\Source\VTS_01_1.VOB, title_index=1
[03:32:33] scan: trying to open with libdvdread
libdvdread: Encrypted DVD support unavailable.
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
ERROR: dvd: ifoOpen failed
Input #0, mpeg, from 'D:\Source\VTS_01_1.VOB':
  Duration: 00:05:45.24, start: 0.018011, bitrate: 8866 kb/s
    Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x480 [PAR 8:9 DAR 4:3], 9800 kb/s, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0xa0]: Audio: pcm_s16be, 48000 Hz, stereo, s16, 1536 kb/s
[03:32:34] scan: decoding previews for title 1
[03:32:34] scan: 10 previews, 720x480, 29.970 fps, autocrop = 60/56/2/0, aspect 4:3, PAR 8:9
[03:32:34] scan: title (0) job->width:640, job->height:368
[03:32:34] libhb: scan thread found 1 valid title(s)
+ title 1:
  + vts 0, ttn 0, cells 0->0 (0 blocks)
  + duration: 00:05:45
  + size: 720x480, pixel aspect: 8/9, display aspect: 1.33, 29.970 fps
  + autocrop: 60/56/2/0
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:05:45
  + audio tracks:
    + 1, Unknown (PCM_S16)
  + subtitle tracks:
[03:32:34] 1 job(s) to process
[03:32:34] starting job
[03:32:34] job configuration:
[03:32:34]  * source
[03:32:34]    + D:\Source\VTS_01_1.VOB
[03:32:34]    + title 1, chapter(s) 1 to 1
[03:32:34]    + container: mpeg
[03:32:34]    + data rate: 8866 kbps
[03:32:34]  * destination
[03:32:34]    + Fail.mp4
[03:32:34]    + container: MPEG-4 (.mp4 and .m4v)
[03:32:34]  * video track
[03:32:34]    + decoder: mpeg2video
[03:32:34]      + bitrate 9800 kbps
[03:32:34]    + frame rate: same as source (around 29.970 fps)
[03:32:34]    + custom anamorphic
[03:32:34]      + modulus: 2
[03:32:34]      + storage dimensions: 720 * 480 -> 480 * 270, crop 60/60/8/8
[03:32:34]      + pixel aspect ratio: 1 / 1
[03:32:34]      + display dimensions: 480 * 270
[03:32:34]    + filters
[03:32:34]      + Detelecine (pullup) (default settings)
[03:32:34]      + Decomb (default settings)
[03:32:34]    + encoder: x264
[03:32:34]      + quality: 0.60
[03:32:34]  * audio track 0
[03:32:34]    + decoder: Unknown (PCM_S16) (track 1, id 1)
[03:32:34]    + mixdown: Stereo
[03:32:34]    + dynamic range compression: 1.000000
[03:32:34]    + encoder: faac
[03:32:34]      + bitrate: 128 kbps, samplerate: 48000 Hz
libdvdread: Encrypted DVD support unavailable.
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
ERROR: dvd: ifoOpen failed
[03:32:34] reader: first SCR 1621
[03:32:34] yadif thread started for segment 0
[03:32:34] yadif thread started for segment 1
[03:32:34] decomb thread started for segment 0
[03:32:34] decomb thread started for segment 1
[03:32:34] encx264: keyint-min: 30, keyint-max: 300
[03:32:34] encx264: encoding with stored aspect 1/1
[03:32:34] encx264: Encoding at constant RF 20.399999
x264 [warning]: width or height not divisible by 16 (480x270), compression will suffer.
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
x264 [info]: profile Main, level 2.1
[03:32:35] sync: expecting 10376 video frames
[03:32:35] sync: first pts is 3003
[03:32:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 48048, next 51051, dur 3003)
[03:32:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 90090, next 93093, dur 3003)
[03:32:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 135135, next 138138, dur 3003)

[many similar warnings...]

[03:36:33] reader: end of chapter 1 (media 1) reached at media chapter 2
[03:36:33] reader: done. 1 scr changes
[03:36:33] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30258228, next 30261231, dur 3003)
[03:36:33] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30303273, next 30306276, dur 3003)
[03:36:33] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30348318, next 30351321, dur 3003)
[03:36:34] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30393363, next 30396366, dur 3003)
[03:36:34] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30438408, next 30441411, dur 3003)
[03:36:34] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30483453, next 30486456, dur 3003)
[03:36:34] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30528498, next 30531501, dur 3003)
[03:36:34] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30573543, next 30576546, dur 3003)
[03:36:34] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30618588, next 30621591, dur 3003)
[03:36:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30663633, next 30666636, dur 3003)
[03:36:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30708678, next 30711681, dur 3003)
[03:36:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30753723, next 30756726, dur 3003)
[03:36:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30798768, next 30801771, dur 3003)
[03:36:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30843813, next 30846816, dur 3003)
[03:36:35] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30888858, next 30891861, dur 3003)
[03:36:36] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30933903, next 30936906, dur 3003)
[03:36:36] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 30978948, next 30981951, dur 3003)
[03:36:36] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 31023993, next 31026996, dur 3003)
[03:36:36] sync: video time didn't advance - dropped 1 frames (delta 0 ms, current 31051020, next 31054023, dur 3003)
[03:36:36] sync: got 9561 frames, 10376 expected
[03:36:36] work: average encoding speed for job is 39.481987 fps
[03:36:36] mux: track 0, 9501 frames, 46929737 bytes, 1088.19 kbps, fifo 16
[03:36:36] mux: track 1, 16144 frames, 5370280 bytes, 124.52 kbps, fifo 512
[03:36:36] mpeg2video-decoder done: 10342 frames, 0 decoder errors, 0 drops
[03:36:36] render: lost time: 195195 (59 frames)
[03:36:36] render: gained time: 195195 (232 frames) (0 not accounted for)
[03:36:36] render: average dropped frame duration: 3308
x264 [info]: slice I:224   Avg QP:20.27  size: 13267  PSNR Mean Y:45.25 U:50.49 V:49.98 Avg:46.07 Global:43.03
x264 [info]: slice P:9277  Avg QP:23.86  size:  4738  PSNR Mean Y:40.16 U:45.44 V:46.08 Avg:41.21 Global:38.52
x264 [info]: mb I  I16..4: 27.8%  0.0% 72.2%
x264 [info]: mb P  I16..4:  2.7%  0.0% 11.1%  P16..4: 35.9% 15.5% 11.1%  0.0%  0.0%    skip:23.5%
x264 [info]: coded y,uvDC,uvAC intra:70.6% 73.0% 50.0% inter:32.5% 32.4% 6.0%
x264 [info]: SSIM Mean Y:0.9731206
x264 [info]: PSNR Mean Y:40.276 U:45.556 V:46.171 Avg:41.322 Global:38.585 kb/s:1184.26
[03:36:36] pcm_s16be-decoder done: 0 frames, 0 decoder errors, 0 drops
[03:36:36] decomb: yadif deinterlaced 2404 | blend deinterlaced 1328 | unfiltered 5769 | total 9501
[03:36:37] libhb: work result = 0

Rip done!
HandBrake has exited.
I also noticed ffmpeg decoder is used for VOB on mingw binary whereas, if I remember correctly, mpeg2dec is used on cygwin binary.
(Sorry, I have uninstalled cygwin from my PC temporarily so I can't confirm this right now).
So I suspect file format is wrongly detected on mingw binary and modify libhb/stream.c as below.

Code: Select all

Index: libhb/stream.c
===================================================================
--- libhb/stream.c      (revision 2494)
+++ libhb/stream.c      (working copy)
@@ -470,7 +470,7 @@
  **********************************************************************/
 hb_stream_t * hb_stream_open( char *path, hb_title_t *title )
 {
-    FILE *f = fopen( path, "r" );
+    FILE *f = fopen( path, "rb" );
     if ( f == NULL )
     {
         hb_log( "hb_stream_open: open %s failed", path );
This patch fixes the problem (warnings also disappears) and encoded video seems to be OK.
I also see some more fopen without 'b' flag in source codes but I change only one as above
because I'm not sure they should also be chaneged.


There are some minor (or trivial) issues when I compile the CLI.

1)
If subversion output is localized (I use Japanese localized version of Ubuntu for build environment),
output of 'svn info' has different format from expected in configure.py.
This results in invalid version string for CLI like "Unofficial svn0 (2009060799)".
On Windows GUI (On Mac or Linux GUI also?), this version string is used for update check,
so I suggest to set env like 'export LC_ALL=C' in configure.

2)
When CLI is build for mingw host, gcc warns about implicit declareratioins of
pthread_win32_(process|thread)_(attach|dettach)_np();.
pthread.h should be included in test/test.c inside first #ifdef PTW32_STATIC_LIB and #endif


Thanks in advance and forgive my English.
KonaBlend
Novice
Posts: 72
Joined: Tue Nov 04, 2008 2:35 am

Re: fopen needs "b" flag for MinGW build

Post by KonaBlend »

Thanks. See changeset 2495.
golgol7777
Posts: 12
Joined: Thu Jun 04, 2009 1:20 pm

Re: fopen needs "b" flag for MinGW build

Post by golgol7777 »

KonaBlend wrote:Thanks. See changeset 2495.
I checked out a new revision and confirm it.
Thanks for quick reply and fix!
Post Reply