I'm doing the following:
- I use FFMPEG into a Delphi XE2 program to convert any file that I receive into a mp4 file.
- I also use qr-faststart to move the atom to the begin of the file after converting.
The problem is after the conversion of some files (not always) the qr-faststart give the following error:
- "encountered non-QT top-level atom (is this a QuickTime file?)"
- "last atom in the file vas not a moov atom"
The command line for FFMPEG is : -i "sourceFile" -sameq "destinationFile"
The command line for qt-faststart is "sourceFile" "destFile"
Here is the full code of both function:
function TfrmMain.ConvertFile(aVideoFile: String; var aNewFile: String): Boolean;
var SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
ExecuteFile, ParamString, StartInString: string;
tmpVideoFile : String;
logCommand : String;
begin
logMain.WriteFeedBackMessage(Format('enter ConvertFile %S ...', [aVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
Result := False;
StartInString := edConverterPath.Text;
tmpVideoFile := ExtractFileName(aVideoFile);
aNewFile := ChangeFileExt(tmpVideoFile, '.mp4');
if tmpVideoFile = aNewFile then begin
logMain.WriteFeedBackMessage('the file is already converted ...', '', EVENTLOG_INFORMATION_TYPE, False);
if OptimizeFastStart(aVideoFile) then begin
Result := True;
end;
Exit;
end;
aNewFile := ExtractFilePath(aVideoFile) + aNewFile;
if FileExists(aNewFile) then begin
DeleteFile(aNewFile);
end;
logCommand := '';
if ckLog.Checked then begin
logCommand := ' -loglevel verbose -report';
end;
ParamString := '-i "' + aVideoFile + '" -sameq "' + aNewFile + '" ' + logCommand;
logMain.WriteFeedBackMessage(Format('ParamString %S', [ParamString]), '', EVENTLOG_INFORMATION_TYPE, False);
ExecuteFile := IncludeTrailingBackslash(StartInString) + 'ffmpeg.exe';
if FileExists(ExecuteFile) then begin
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
with SEInfo do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(ExecuteFile) ;
//ParamString can contain the application parameters.
lpParameters := PChar(ParamString) ;
// StartInString specifies the name of the working directory. If ommited, the current directory is used.
lpDirectory := PChar(StartInString) ;
nShow := SW_SHOWNORMAL;
end;
if ShellExecuteEx(@SEInfo) then begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
end;
if FileExists(aNewFile) then begin
logMain.WriteFeedBackMessage(Format('Converting Video %S succesfull!', [aVideoFile]), Format('File %S was created.', [aNewFile]), EVENTLOG_INFORMATION_TYPE, True, False, False);
if OptimizeFastStart(aNewFile) then begin
Result := True;
end;
end;
end else begin
logMain.WriteFeedBackMessage(Format('File %S does not exist on the server!', [ExecuteFile]), 'The converter cannot be located on the disk!' + #13#10 + ExecuteFile, EVENTLOG_ERROR_TYPE, True, False, False);
end;
end;
the fast start is here
function TfrmMain.OptimizeFastStart(aVideoFile: String): Boolean;
var SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
ExecuteFile, ParamString, StartInString: string;
strVideoFile : String;
newVideoFile : String;
startCommand : String;
begin
// you need fast start utility
logMain.WriteFeedBackMessage(Format('enter OptimizeFastStart %S ...', [aVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
Result := False;
StartInString := edConverterPath.Text;
strVideoFile := ExtractFileName(aVideoFile);
newVideoFile := 'TMP_' + strVideoFile;
if strVideoFile = aVideoFile then begin
strVideoFile := StartInString + strVideoFile;
newVideoFile := StartInString + newVideoFile;
end;
if not FileExists(strVideoFile) then begin
logMain.WriteFeedBackMessage(Format('file %S dont exist...', [strVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
Exit;
end;
if FileExists(newVideoFile) then begin
DeleteFile(newVideoFile);
end;
ParamString := Format('"%S" "%S"', [strVideoFile, newVideoFile]);
ExecuteFile := IncludeTrailingBackslash(StartInString) + 'qt-faststart.exe';
if FileExists(ExecuteFile) then begin
logMain.WriteFeedBackMessage(Format('source %S destination %S', [strVideoFile, newVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(ExecuteFile) ;
lpParameters := PChar(ParamString);
lpDirectory := PChar(StartInString);
nShow := SW_SHOWNORMAL;
end;
if ShellExecuteEx(@SEInfo) then begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
end;
logMain.WriteFeedBackMessage(Format('after file executed...', [strVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
sleep(500);
Application.ProcessMessages;
if FileExists(newVideoFile) then begin
DeleteFile(strVideoFile);
Application.ProcessMessages;
sleep(500);
Application.ProcessMessages;
logMain.WriteFeedBackMessage(Format('before rename file...', [strVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
if RenameFile(newVideoFile, strVideoFile) then begin
logMain.WriteFeedBackMessage(Format('rename file OK...', [strVideoFile]), '', EVENTLOG_INFORMATION_TYPE, False);
Result := True;
logMain.WriteFeedBackMessage(Format('Processing Video %S for WEB succesfull!', [strVideoFile]), '', EVENTLOG_INFORMATION_TYPE, True);
end;
end else begin
logMain.WriteFeedBackMessage(Format('file %S does not exist!...', [newVideoFile]), '', EVENTLOG_INFORMATION_TYPE, True);
end;
end else begin
logMain.WriteFeedBackMessage('Cannot find the qt-faststart.exe converter on the disk!', ExecuteFile, EVENTLOG_ERROR_TYPE, True);
end;
end;
Can anyone advice me how to fix this problem.
Remove -sameq option, It does not mean same quality. Also, what version of FFMpeg do you have? If you do not have the latest, update. That should fix your problem. Can you post your complete command line output?