Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#911 closed defect (worksforme)

ffplay can't handle timecodes of WMV2 video correctly

Reported by: zhushisongzhu Owned by:
Priority: important Component: undetermined
Version: git-master Keywords: asf wmv2 seeking
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

When using ffplay to play WMV2 video and using -ss seconds parameter to set starting play time, but ffplay can't position the specified time to start playing. For example, when I use 'ffplay -ss 9' command to play the video, ffplay always starts playing from the begining and does't play it from 9s.

[root@sbis-gw-fa8-0-0 ~]# ffmpeg -i hzvideo.wmv
ffmpeg version N-34849-g07c7ffc, Copyright (c) 2000-2011 the FFmpeg developers

built on Jan 4 2012 23:02:43 with gcc 4.4.4 20100726 (Red Hat 4.4.4-13)
configuration: --prefix=/usr
libavutil 51. 24. 1 / 51. 24. 1
libavcodec 53. 33. 0 / 53. 33. 0
libavformat 53. 20. 0 / 53. 20. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 48. 1 / 2. 48. 1
libswscale 2. 1. 0 / 2. 1. 0

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 25.00 (25/1)
Input #0, asf, from 'hzvideo.wmv':

Metadata:

WM/Writer : 搀瘀搀砀
WMFSDKVersion : 10.00.00.4072
WMFSDKNeeded : 0.0.0.0000
IsVBR : 0

Duration: 00:00:37.99, start: 0.000000, bitrate: 755 kb/s

Stream #0:0(chi): Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 704x576, 700 kb/s, 25 tbr, 1k tbn, 1k tbc

[root@sbis-gw-fa8-0-0 ~]# ffplay -ss 9 hzvideo.wmv
ffplay version N-34849-g07c7ffc, Copyright (c) 2003-2011 the FFmpeg developers

built on Jan 4 2012 23:02:43 with gcc 4.4.4 20100726 (Red Hat 4.4.4-13)
configuration: --prefix=/usr
libavutil 51. 24. 1 / 51. 24. 1
libavcodec 53. 33. 0 / 53. 33. 0
libavformat 53. 20. 0 / 53. 20. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 48. 1 / 2. 48. 1
libswscale 2. 1. 0 / 2. 1. 0

Input #0, asf, from 'hzvideo.wmv':

Metadata:

WM/Writer : 搀瘀搀砀
WMFSDKVersion : 10.00.00.4072
WMFSDKNeeded : 0.0.0.0000
IsVBR : 0

Duration: 00:00:37.99, start: 0.000000, bitrate: 755 kb/s

Stream #0:0(chi): Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 704x576, 700 kb/s, 25 tbr, 1k tbn, 1k tbc

1.08 A-V: 0.000 fd= 0 aq= 0KB vq= 29KB sq= 0B f=0/0 0/0

[root@sbis-gw-fa8-0-0 ~]#

Attachments (1)

hzvideo.wmv (1.9 MB) - added by zhushisongzhu 5 years ago.
This is wmv sample file which ffplay can't handle the timecodes correctly

Download all attachments as: .zip

Change History (11)

Changed 5 years ago by zhushisongzhu

This is wmv sample file which ffplay can't handle the timecodes correctly

comment:1 follow-up: Changed 5 years ago by cehoyos

  • Keywords asf wmv2 seeking added; WMV2 timecodes ffplay removed
  • Resolution set to worksforme
  • Status changed from new to closed

The video contains two keyframes, one at the beginning, one after ten seconds. Both keyframes can be reached by seeking with both ffplay and ffmpeg (and mplayer -demuxer lavf).

Please reopen if you believe that the current behaviour can be improved.

comment:2 Changed 5 years ago by zhushisongzhu

Last edited 5 years ago by zhushisongzhu (previous) (diff)

comment:3 in reply to: ↑ 1 Changed 5 years ago by zhushisongzhu

Replying to cehoyos:

The video contains two keyframes, one at the beginning, one after ten seconds. Both keyframes can be reached by seeking with both ffplay and ffmpeg (and mplayer -demuxer lavf).

Please reopen if you believe that the current behaviour can be improved.

Do you test ffplay the video? You can see the following line:

1.08 A-V: 0.000 fd= 0 aq= 0KB vq= 29KB sq= 0B f=0/0 0/0

I use 'ffplay -ss 9', so 1.08 is wrong, it should be larger than 9. FFplay can't handle seeking correctly. I use Windows Media player to test the video, the player can handle time progess bar smoothly and correctly. I test it using VLC 1.1.13 and VLC 1.3.0-git, VLC can't control time progress bar correcty. I try to play the video using MPlayer, MPlayer has the same problem. I don't know the meaning of what you quoted 'both keyframes can be reached by seeking', I just know ffplay can't reach the position following what I set it should be.
If you want to repeat the problem, please ffplay it and try to control the seeking and see what you have observed yourself.

comment:4 Changed 5 years ago by cehoyos

Let me try it differently:
For most videos, media players can only seek to keyframes ("I-frames"), they cannot seek to non-keyframes (all other frames), if they seem to allow to seek to non-keyframes, they do it by seeking further back and not displaying the frames in-between (this can be different for H264, but your sample is WMV2). The behaviour of not showing some frames can lead to a kind of freeze while the user is waiting for the frame with the specified timestamp, this is typically not intended behaviour and ffplay does not support this.

Your sample contains two such I-frames (keyframes), one at the beginning, one after ten seconds, you can find out yourself with mplayer hzvideo.wmv -lavdopts skipframe=nonkey
ffplay -ss 1 until -ss 9 seeks to the last keyframe that comes before the specified timestamp, that is the first frame for your sample, ffplay -ss 10 and above seeks to the second keyframe of the video.

Is that more understandable?

comment:5 follow-up: Changed 5 years ago by zhushisongzhu

I see that we can just seek from one keyframe to another keyframe and we can't seek between two keyframes. But why can windows media player can control time progress bar smoothly and correctly?
I play the video using your suggested command: mplayer hzvideo.wmv -lavdopts skipframe=nonkey,
The video output is frozen. The following is the output(I don't know the meaning):
[root@sbis-gw-fa8-0-0 ~]# mplayer hzvideo.wmv -lavdopts skipframe=nonkey
MPlayer SVN-r34540-snapshot-4.4.4 (C) 2000-2012 MPlayer Team

Playing hzvideo.wmv.
libavformat version 53.29.100 (internal)
ASF file format detected.
[asfheader] Video stream found, -vid 1
VIDEO: [WMV2] 704x576 24bpp 1000.000 fps 700.0 kbps (85.4 kbyte/s)
Load subtitles in ./
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 53.55.100 (internal)
Selected video codec: [ffwmv2] vfm: ffmpeg (FFmpeg WMV2/WMV8)
==========================================================================
Audio: no sound
Starting playback...
Movie-Aspect is undefined - no prescaling applied.
VO: [xv] 704x576 => 704x576 Planar YV12
V: 7.7 69/ 69 8% 0% 0.0% 0 0

Exiting... (Quit)
[root@sbis-gw-fa8-0-0 ~]#

comment:6 in reply to: ↑ 5 Changed 5 years ago by cehoyos

Replying to zhushisongzhu:

I see that we can just seek from one keyframe to another keyframe and we can't seek between two keyframes.

But why can windows media player can control time progress bar smoothly and correctly?

I do not understand the question.

I play the video using your suggested command: mplayer hzvideo.wmv -lavdopts skipframe=nonkey
The video output is frozen.

I only suggested this command line (that forces MPlayer to skip all non-key frames) to allow you to reproduce the fact that the sample only contains two keyframes: The output is not frozen, the first keyframe is shown for ten seconds, the second keyframe is shown for the remaining playback time.

I was able to test your sample with WMP on older hardware (2GHz Athlon): If I seek to "09:17:26" on the counter in the right upper corner, seeking (back and forth) is very fast, if I try to seek to "09:17:24" seeking takes much longer, indicating I was right when I wrote above that WMP also has to seek back to the beginning, it has to decode all frames between the last keyframe and the specified seeking position to create the allusion of random seeking.

comment:7 Changed 5 years ago by zhushisongzhu

I know what you mean. But I am confused that why H.264 videos don't have such problem. There are many non-key frames between two key frames in h.264 video. I feel both wmv and h.264 have the same mechanism intuitively. Why playing wmv is so different with h.264?

Last edited 5 years ago by zhushisongzhu (previous) (diff)

comment:8 follow-up: Changed 5 years ago by cehoyos

  • H264 streams can be valid without keyframes (even without an initial keyframe).
  • If a media player seeks exactly to a keyframe in H264, it is not guaranteed that there will be no corruption when playing the stream beginning from the found keyframe. (Non-keyframes after a keyframe in H264 may reference frames earlier than the last keyframe.)

Both is not true for WMV, so assuming that seeking in H264 is significantly different from seeking in WMV is safe.
(Note that much older versions of FFmpeg seek fine in your sample, but failed completely seeking in H264 which was only fixed a short time ago.)

comment:9 in reply to: ↑ 8 Changed 5 years ago by zhushisongzhu

Replying to cehoyos:

  • H264 streams can be valid without keyframes (even without an initial keyframe).
  • If a media player seeks exactly to a keyframe in H264, it is not guaranteed that there will be no corruption when playing the stream beginning from the found keyframe. (Non-keyframes after a keyframe in H264 may reference frames earlier than the last keyframe.)

Both is not true for WMV, so assuming that seeking in H264 is significantly different from seeking in WMV is safe.
(Note that much older versions of FFmpeg seek fine in your sample, but failed completely seeking in H264 which was only fixed a short time ago.)

Thanks for your comments. If having time, I'll spend some time to understand more details about WMV and H264.

comment:10 Changed 5 years ago by zhushisongzhu

hzvideo.wmv is 20s long. But using mplayer to play it. Mplayer stopped at 24.9(shown on the left V: 24.9). I want to ask what's the meaning of 24.9?

[root@bogon shared]# mplayer hzvideo.wmv
MPlayer SVN-r34573-4.4.4 (C) 2000-2012 MPlayer Team

Playing hzvideo.wmv.
libavformat version 53.29.100 (internal)
ASF file format detected.
[asfheader] Video stream found, -vid 1
VIDEO: [WMV2] 704x576 24bpp 1000.000 fps 700.0 kbps (85.4 kbyte/s)
Load subtitles in ./
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 53.55.105 (internal)
Selected video codec: [ffwmv2] vfm: ffmpeg (FFmpeg WMV2/WMV8)
==========================================================================
Audio: no sound
Starting playback...
Movie-Aspect is undefined - no prescaling applied.
VO: [xv] 704x576 => 704x576 Planar YV12
V: 24.9 499/499 7% 0% 0.0% 0 0

Exiting... (End of file)

Note: See TracTickets for help on using tickets.