recording .mp4 rsults in corrupt file at windows log-off

Issues involving a Windows version of FFmpeg. Do not post general usage questions here.

recording .mp4 rsults in corrupt file at windows log-off

Postby Michael » Fri Apr 19, 2013 8:21 am

Hello,

My first time here and my first question asked, so maybe I'm saying something that has been said before.

I'm happely using FFMPEG to record the windows desktop into a .mp4 video file. (using the nice screen-capturer from Roger Pack): (like: ffmpeg -f dshow -i video="Virtual-Camera" screen-capture.mp4 )

To start recording I'm using C# to run the FFMPEG program directly and am passing all the arguments required for recording.
To stop recording I'm sending the 'q' character and everything works well and recordings are perfect.

Recently I found that when shutting down or logging off Windows, the recording actually becomes corrupt.
My own c# program is catching the shut-down command and keeps running. But the bad thing already has happened: the FFMPEG process is already closed.
So I already tried to catch the shutdown, ASAP send the 'q' character to FFMPEG but to no avail.

P.S. Corruption also occurs when FFMPEG is running in a command-shell, and the command-shell is closed by mouse-pressing the 'X'.

Is there anything that can be done to fix the .mp4 corruption? Especially at windows shutdown/logoff?

---------
In my own c# software I'm catching the shutdown in a 'WndProc' override.


const int WM_CLOSE = 0x0010;
const int WM_QUERYENDSESSION = 0x0011;

protected override void WndProc(ref Message m)
{

// when closed by the user or minimized, show minimized in stead and hide the window.
// unless a force close in in initiated.
if (((m.Msg == WM_CLOSE) || (m.Msg == WM_QUERYENDSESSION))
{
if (m.Msg == WM_QUERYENDSESSION)
SystemShutdown = true;
CloseStuff(); // including clean FFMPEG recording stop.
}
else
base.WndProc(ref m);


}
Michael
 
Posts: 5
Joined: Thu Apr 18, 2013 8:45 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby rogerdpack » Fri Apr 19, 2013 2:53 pm

I've noticed the same thing...unsure of a work around presently (besides using a different container type) let me know if you find anything out...
rogerdpack
 
Posts: 1292
Joined: Fri Aug 05, 2011 9:56 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby Michael » Sun Apr 21, 2013 4:54 pm

Hello roger, (P.s. you know me from the FME support requests for your screen-capturer-recorder)

Indeed, another container format could be an option, but .mp4 is one of the few formats which are supported for HTM5 video.

The closest web based option would be to store in .FLV format and use flash for playback. Good thing about FLV is that the file container is quite resilient against file corruption, sadly not supported by Windows Media player.

My point is, when recordings are made this is a one-time event and can't be repeated. When FFPMEG is used for file-conversion, you can just try again. But if for instance FFMPEG was used to record an important meeting presentation or for video recordings of a funeral session it will be very painful.

So indeed for now I'll remove .MP4 and record WMV instead. Hopefully it can still be fixed in a future release, a user is doing nothing wrong when shutting down windows.

Best Regards,

Michael
Michael
 
Posts: 5
Joined: Thu Apr 18, 2013 8:45 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby tateu » Sun Apr 21, 2013 6:49 pm

If flv is more resilient, do you have access to transcode the file afterwards? Record to flv with h264 and then use something like:

ffmpeg -i capture.flv -c:v copy -c:a copy capture.mp4
tateu
 
Posts: 7
Joined: Sat Jul 09, 2011 9:47 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby rogerdpack » Mon Apr 22, 2013 7:56 pm

ideally ffmpeg would capture the "kill" request and shutdown gracefully, I suppose...

I also saw this: http://ffmpeg.org/trac/ffmpeg/ticket/1463 though haven't tried it...it's also not immediately clear if this "work for XP but not for windows 7" or not, too, could use some testing there...it may be missing some messages...
rogerdpack
 
Posts: 1292
Joined: Fri Aug 05, 2011 9:56 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby Michael » Tue Apr 23, 2013 3:00 pm

Thanks for the hints and tips!

P.S. I also tried WMV. The recording can still be played, but seeking in the recording isn't possible when shutting down windows during FFmpeg recording. It seems .mp4 isn't the only format which doesn't like skipping the 'finalization'.

Cheers, Michael.
Michael
 
Posts: 5
Joined: Thu Apr 18, 2013 8:45 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby rogerdpack » Thu Apr 25, 2013 6:03 am

mpeg might work
rogerdpack
 
Posts: 1292
Joined: Fri Aug 05, 2011 9:56 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby Michael » Fri Apr 26, 2013 9:40 am

I spend some time investigating if the Windows shut-down events can be stopped or halted.
Aprantly you can halt or cancel the windows shut-down by stalling the wndproc (see code exampl;e below).
Sadly this is no guarantee. I tried this a few times, sometimes this worked, but other times ffmpeg was already closed and the .mp4 file corrupt. Too bad, I though I was nearly there.

There is a console way of 'detecting' a windows logoff/shutdown/close event about to happen, referenced here:
http://msdn.microsoft.com/nl-nl/library ... 85%29.aspx

Example code for console applications here:
http://osdir.com/ml/windows.devel.dotne ... 00214.html

I hope this may help.

Best Regards, Michael

protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
SendFFMPEGstopCommand(); // sends 'q' to FFmpeg
Thread.sleep(5000); // allow 5 seconds before windows proceeds to close stuff. This works a few seconds then Windows proceeds anyway.
}

base.WndProc(ref m);
}

Edit: I know all examples are c# based, but think the c++ variants should be the same.
Michael
 
Posts: 5
Joined: Thu Apr 18, 2013 8:45 pm

Re: recording .mp4 rsults in corrupt file at windows log-off

Postby DJX » Fri Apr 26, 2013 12:43 pm

This may explain the behavior:

http://msdn.microsoft.com/en-US/library ... 21(v=vs.85).aspx

...Note that the system does not allow console applications or applications without a visible window to cancel shutdown. These applications are automatically terminated if they do not respond to WM_QUERYENDSESSION or WM_ENDSESSION within 5 seconds or if they return FALSE in response to WM_QUERYENDSESSION.
DJX
 
Posts: 24
Joined: Mon Aug 06, 2012 10:37 pm


Return to Usage Issues

Who is online

Users browsing this forum: Google [Bot] and 2 guests