Log in

View Full Version : piping ffmpeg to neroAacEnc


Sirber
4th January 2011, 14:30
"C:\Users\Sirber\Documents\My Dropbox\prog\bencos\out\ffmpeg.exe" -ac 2 -vn -y -i "C:\Users\Sirber\Documents\My Dropbox\share\cindy\101028_famille02.mov" -f wav - | "C:\Users\Sirber\Documents\My Dropbox\prog\bencos\out\neroAacEnc.exe" -ignorelength -hev2 -br 32000 -if - -of "C:\Users\Sirber\AppData\Local\Temp/bencos/audio.mp4"

FFmpeg version SVN-r26188, Copyright (c) 2000-2011 the FFmpeg developers
built on Jan 2 2011 04:10:51 with gcc 4.4.2
configuration: --enable-gpl --enable-version3 --enable-libgsm --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libschroedinger --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-libvpx --disable-decoder=libvpx --arch=x86 --enable-runtime-cpudetect --enable-libxvid --enable-libx264 --enable-librtmp --extra-libs='-lrtmp -lpolarssl -lws2_32 -lwinmm' --target-os=mingw32 --enable-avisynth --enable-w32threads --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign-hack
libavutil 50.36. 0 / 50.36. 0
libavcore 0.16. 0 / 0.16. 0
libavcodec 52.101. 0 / 52.101. 0
libavformat 52.91. 0 / 52.91. 0
libavdevice 52. 2. 2 / 52. 2. 2
libavfilter 1.72. 0 / 1.72. 0
libswscale 0.12. 0 / 0.12. 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 018b90b0] max_analyze_duration reached

Seems stream 0 codec frame rate differs from container frame rate: 5994.00 (5994/1) -> 29.97 (2997/100)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Sirber\Documents\My Dropbox\share\cindy\101028_famille02.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2010-10-28 19:52:27
Duration: 00:07:54.98, start: 0.000000, bitrate: 1132 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 720x404 [PAR 1:1 DAR 180:101], 1023 kb/s, 29.97 fps, 29.97 tbr, 2997 tbn, 5994 tbc
Metadata:
creation_time : 2010-10-28 19:52:27
Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 103 kb/s
Metadata:
creation_time : 2010-10-28 19:52:27
Stream #0.2(eng): Data: tmcd / 0x64636D74
Metadata:
creation_time : 2010-10-28 19:52:27

Unable to find a suitable output format for '|'

When I run the cmdline in "cmd.exe" it works, but when I start it with TProcess it doesn't.

My TProcess:

oCli.CommandLine := sCmd;
oCli.Priority := ppIdle;
oCli.CurrentDirectory := sTemp;
oCli.Options := [poUsePipes, poStderrToOutPut];
{$IFDEF WIN32}oCli.Options := oCli.Options + [poNoConsole];{$ENDIF}
//oCli.ShowWindow := swoHide;
oCli.Execute();

Sirber
4th January 2011, 14:34
TProcess is NOT a shell, it doesn't handle redirection via pipe operator, nor <, >, 2> etc. The best way is to call sh (or whatever your shell is) and pipe those string to the process (use the Input property) then read the output (using Output property). This sure is OS, actually shell, specific. You may want to put the platform dependent codes in conditional compilation blocks.

http://forum.lazarus.freepascal.org/index.php?topic=9770.0

I'll think of another way..

Sirber
4th January 2011, 14:42
launching a batch file (.bat or .cmd) from TProcess pops 2 consoles and fails to pipe..

LoRd_MuldeR
4th January 2011, 14:56
I assume your TProcess internally uses CreateProcess(), which indeed doesn't "support" the pipe operator. In this situation you have two ways for creating a pipe:

(1) Use a command-line like this:
cmd.exe /c ""C:\path\ffmpeg.exe" -ac 2 -vn -y -i "C:\path\101028_famille02.mov" -f wav - | "C:\path\neroAacEnc.exe" -ignorelength -hev2 -br 32000 -if - -of "C:\path/audio.mp4""

(2) Create two separate processes with CreateProcess() (http://msdn.microsoft.com/en-us/library/ms682425(v=vs.85).aspx) and connect their STDOUT/STDIN with a Pipe (http://msdn.microsoft.com/en-us/library/aa365152(v=vs.85).aspx). See STARTUPINFO (http://msdn.microsoft.com/en-us/library/ms686331(v=vs.85).aspx) for details. I don't know if your TProcess wrapper does allow this...


[EDIT]

Actually there's another method that doesn't require using "low-level" OS functions directly and thus works in a "cross-platform" way (probably more similar to your TProcess):
Use the Qt Framework to build your application (which is a good idea anyway ^^) and then simply create your processes via QProcess objects.

This should be exactly what you are looking for:
http://doc.qt.nokia.com/latest/qprocess.html#setStandardOutputProcess

Selur
4th January 2011, 20:15
you also might want to add
-v -10
to your ffmpeg,.. (as far as I remember that was on of the caveats I ran into when piping from ffmpeg to neroaac)
also if you want to use QT some crude examples are in the sx264 source code.

Cu Selur

Sirber
4th January 2011, 20:26
Thanks for the help!

I'm placing this "code update" on ice until further notice since it's taking too much code change for the little encoding time saved. :(

LoRd_MuldeR
4th January 2011, 22:22
Actually the solution with using 'cmd.exe' to create pipe should do the job with minimal code change...

Sirber
4th January 2011, 22:25
I tryed it: cmd.exe /C "<path to>/encodeaudio.bat"
and it did the same thing (two console popups). I didn't try the full cmdline.
I already reverted the code to when I was using 2 pass (extraction then encoding). :(

I'll keep it in mind when I retry it. Thanks!

LoRd_MuldeR
4th January 2011, 22:27
I tryed it: cmd.exe /C "<path to>/encodeaudio.bat"
and it did the same thing (two console popups). I didn't try the full cmdline.
I already reverted the code to when I was using 2 pass (extraction then encoding). :(

I'll keep it in mind when I retry it. Thanks!

Well, I don't know how your Batch file looks, but you shouldn't need to use a batch file.

Just try like this:

cmd.exe /c ""c:\path\program1.exe" <args> | "c:\path\program2.exe" <args>"

Sirber
4th January 2011, 22:29
I tryed to tprocess a batch file before trying "cmd.exe /c", on the batch file. :)