webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

VP8 Recorded file.ivf has incorrect duration and playback speed

Open Demuzx opened this issue 5 years ago • 10 comments

VP8 Recorded file.ivf has incorrect duration and playback speed. Any video player shows 6 sec reord length, but plays more in fact.

How can i fix video record speed and duration?

Demuzx avatar May 31 '19 08:05 Demuzx

Hey @Demuzx

Is it still incorrect after calling Close on the file like here https://github.com/pion/webrtc/blob/master/examples/save-to-disk/main.go#L115 ?

We also have this PR, but I haven't had time to work on it yet https://github.com/pion/webrtc/pull/680

We can't use the wall clock (since packets might be coming faster then playback speed) but I haven't dug in yet.

Sean-Der avatar May 31 '19 08:05 Sean-Der

Is it still incorrect after calling Close on the file like here https://github.com/pion/webrtc/blob/master/examples/save-to-disk/main.go#L115 ?

Yes, it is still incorrect, even i close file. And the playback speed of the recorded file from the camera and the recorded file of the screen is differ in speed

Demuzx avatar May 31 '19 08:05 Demuzx

Hey @Demuzx

Is it still incorrect after calling Close on the file like here https://github.com/pion/webrtc/blob/master/examples/save-to-disk/main.go#L115 ?

We also have this PR, but I haven't had time to work on it yet #680

We can't use the wall clock (since packets might be coming faster then playback speed) but I haven't dug in yet.

Actually the PR is not considering variable rate nor faster than playback speed. The correct way would be to have the framerate from other endpoint at some point (begin or end of stream), but for live stream it is working in an acceptable way.

It is also broken on fixating the width and height.

raphaelpereira avatar Jun 04 '19 00:06 raphaelpereira

Is it still incorrect after calling Close on the file like here https://github.com/pion/webrtc/blob/master/examples/save-to-disk/main.go#L115 ?

Yes, it is still incorrect, even i close file. And the playback speed of the recorded file from the camera and the recorded file of the screen is differ in speed

The thing is that framerate is fixed and probably different than your camera.

raphaelpereira avatar Jun 04 '19 00:06 raphaelpereira

Hey @Demuzx

Is it still incorrect after calling Close on the file like here https://github.com/pion/webrtc/blob/master/examples/save-to-disk/main.go#L115 ?

We also have this PR, but I haven't had time to work on it yet #680

We can't use the wall clock (since packets might be coming faster then playback speed) but I haven't dug in yet.

Is there any way to define incoming stream frame rate that we receive from the client and paste this value to ivfWriter headers dynamically? Can you rewrite "NewWriter()" function to something like: ivfWriter.NewWriter(config), where config has more advanced configuration than currently available?

func (i *IVFWriter) writeHeader() error {
	header := make([]byte, 32)
	copy(header[0:], []byte("DKIF"))                // DKIF
	binary.LittleEndian.PutUint16(header[4:], 0)    // Version
	binary.LittleEndian.PutUint16(header[6:], 32)   // Header Size
	copy(header[8:], []byte("VP80"))                // FOURCC
	binary.LittleEndian.PutUint16(header[12:], 640) // Version
	binary.LittleEndian.PutUint16(header[14:], 480) // Header Size
	binary.LittleEndian.PutUint32(header[16:], 30)  // Framerate numerator
	binary.LittleEndian.PutUint32(header[20:], 1)   // Framerate Denominator
	binary.LittleEndian.PutUint32(header[24:], 60) // Frame count, will be updated on first Close() call
	binary.LittleEndian.PutUint32(header[28:], 0)   // Unused

	_, err := i.stream.Write(header)
	return err
}

Demuzx avatar Jun 04 '19 05:06 Demuzx

@Demuzx

Is there any way to define incoming stream frame rate that we receive from the client and paste this value to ivfWriter headers dynamically? Can you rewrite "NewWriter()" function to something like: ivfWriter.NewWriter(config), where config has more advanced configuration than currently available?

func (i *IVFWriter) writeHeader() error {
	header := make([]byte, 32)
	copy(header[0:], []byte("DKIF"))                // DKIF
	binary.LittleEndian.PutUint16(header[4:], 0)    // Version
	binary.LittleEndian.PutUint16(header[6:], 32)   // Header Size
	copy(header[8:], []byte("VP80"))                // FOURCC
	binary.LittleEndian.PutUint16(header[12:], 640) // Version
	binary.LittleEndian.PutUint16(header[14:], 480) // Header Size
	binary.LittleEndian.PutUint32(header[16:], 30)  // Framerate numerator
	binary.LittleEndian.PutUint32(header[20:], 1)   // Framerate Denominator
	binary.LittleEndian.PutUint32(header[24:], 60) // Frame count, will be updated on first Close() call
	binary.LittleEndian.PutUint32(header[28:], 0)   // Unused

	_, err := i.stream.Write(header)
	return err
}

I don't know if the RFC mentions stream metadata transportation. If that is the case it would be good to get this information directly from WebRTC protocol.

I see no reason why this method should be static. I think it is that way only for lack of time to make the modification. A PR would be much appreciated.

raphaelpereira avatar Jun 04 '19 12:06 raphaelpereira

Sorry I can't be more help guys :( I need to get TURN + DTL-PSK done.

Right after I can dig in though! If you want to jump on Slack or open PRs I will try my best to help.

Sean-Der avatar Jun 04 '19 21:06 Sean-Der

Any update on it?

guilhermehubner avatar Oct 21 '19 13:10 guilhermehubner

Any update on it?

programmingman avatar Oct 29 '19 09:10 programmingman

If you are having issues with ivf playback #680 has seemingly fixed the issue or at least made it a workable solution. It sounds like the PR is not the correct way of doing it however based on @raphaelpereira description...

danj565 avatar Oct 15 '20 20:10 danj565