How can I stop ffmpeg from quitting when it reaches the end of a named pipe?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm using a program which continuously writes MPEG-TS video data to a file while it's running. I'm expecting it to run continuously for many days.
I want to use ffmpeg to transcode this video data live. So that the .mts file doesn't grow continuously until I run out of hard drive space, I'm trying to get the first program to write to a named pipe and for ffmpeg
to read from that pipe.
I tried doing ffmpeg -i /tmp/test.mts -c:v libx264 test.mp4
but it seems that ffmpeg quits once it reaches the end of the pipe, instead of waiting for new data. For example if I start the program, wait 30 seconds and then run ffmpeg, I'll only get ~50 seconds of video out. (30 seconds + the time it takes ffmpeg to catch up)
I have managed to get it working by doing ffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
but this feels kind of hacky to me, using stdin to do this. Is there a way I can directly provide the named pipe as an input to ffmpeg and have it wait for new data once it reaches the end of the current data?
Thanks!
ffmpeg fifo
add a comment |
up vote
0
down vote
favorite
I'm using a program which continuously writes MPEG-TS video data to a file while it's running. I'm expecting it to run continuously for many days.
I want to use ffmpeg to transcode this video data live. So that the .mts file doesn't grow continuously until I run out of hard drive space, I'm trying to get the first program to write to a named pipe and for ffmpeg
to read from that pipe.
I tried doing ffmpeg -i /tmp/test.mts -c:v libx264 test.mp4
but it seems that ffmpeg quits once it reaches the end of the pipe, instead of waiting for new data. For example if I start the program, wait 30 seconds and then run ffmpeg, I'll only get ~50 seconds of video out. (30 seconds + the time it takes ffmpeg to catch up)
I have managed to get it working by doing ffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
but this feels kind of hacky to me, using stdin to do this. Is there a way I can directly provide the named pipe as an input to ffmpeg and have it wait for new data once it reaches the end of the current data?
Thanks!
ffmpeg fifo
Why does it feel hacky to put a standerd input into a standerd input field?
– Michael Prokopec
Nov 22 at 7:20
1
I don't understand howffmpeg -i pipe:0 < fifo.mts
is different in this regard fromffmpeg -i fifo.mts
; both will receive an EOF and exit here when the (last handle to the) writing end offifo.mts
is closed.
– mosvy
Nov 22 at 8:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using a program which continuously writes MPEG-TS video data to a file while it's running. I'm expecting it to run continuously for many days.
I want to use ffmpeg to transcode this video data live. So that the .mts file doesn't grow continuously until I run out of hard drive space, I'm trying to get the first program to write to a named pipe and for ffmpeg
to read from that pipe.
I tried doing ffmpeg -i /tmp/test.mts -c:v libx264 test.mp4
but it seems that ffmpeg quits once it reaches the end of the pipe, instead of waiting for new data. For example if I start the program, wait 30 seconds and then run ffmpeg, I'll only get ~50 seconds of video out. (30 seconds + the time it takes ffmpeg to catch up)
I have managed to get it working by doing ffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
but this feels kind of hacky to me, using stdin to do this. Is there a way I can directly provide the named pipe as an input to ffmpeg and have it wait for new data once it reaches the end of the current data?
Thanks!
ffmpeg fifo
I'm using a program which continuously writes MPEG-TS video data to a file while it's running. I'm expecting it to run continuously for many days.
I want to use ffmpeg to transcode this video data live. So that the .mts file doesn't grow continuously until I run out of hard drive space, I'm trying to get the first program to write to a named pipe and for ffmpeg
to read from that pipe.
I tried doing ffmpeg -i /tmp/test.mts -c:v libx264 test.mp4
but it seems that ffmpeg quits once it reaches the end of the pipe, instead of waiting for new data. For example if I start the program, wait 30 seconds and then run ffmpeg, I'll only get ~50 seconds of video out. (30 seconds + the time it takes ffmpeg to catch up)
I have managed to get it working by doing ffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
but this feels kind of hacky to me, using stdin to do this. Is there a way I can directly provide the named pipe as an input to ffmpeg and have it wait for new data once it reaches the end of the current data?
Thanks!
ffmpeg fifo
ffmpeg fifo
asked Nov 22 at 5:06
Joshua Walsh
1957
1957
Why does it feel hacky to put a standerd input into a standerd input field?
– Michael Prokopec
Nov 22 at 7:20
1
I don't understand howffmpeg -i pipe:0 < fifo.mts
is different in this regard fromffmpeg -i fifo.mts
; both will receive an EOF and exit here when the (last handle to the) writing end offifo.mts
is closed.
– mosvy
Nov 22 at 8:47
add a comment |
Why does it feel hacky to put a standerd input into a standerd input field?
– Michael Prokopec
Nov 22 at 7:20
1
I don't understand howffmpeg -i pipe:0 < fifo.mts
is different in this regard fromffmpeg -i fifo.mts
; both will receive an EOF and exit here when the (last handle to the) writing end offifo.mts
is closed.
– mosvy
Nov 22 at 8:47
Why does it feel hacky to put a standerd input into a standerd input field?
– Michael Prokopec
Nov 22 at 7:20
Why does it feel hacky to put a standerd input into a standerd input field?
– Michael Prokopec
Nov 22 at 7:20
1
1
I don't understand how
ffmpeg -i pipe:0 < fifo.mts
is different in this regard from ffmpeg -i fifo.mts
; both will receive an EOF and exit here when the (last handle to the) writing end of fifo.mts
is closed.– mosvy
Nov 22 at 8:47
I don't understand how
ffmpeg -i pipe:0 < fifo.mts
is different in this regard from ffmpeg -i fifo.mts
; both will receive an EOF and exit here when the (last handle to the) writing end of fifo.mts
is closed.– mosvy
Nov 22 at 8:47
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Simply open that fifo for writing (and keep it open) from another place, too. Example:
In a window:
mkfifo /tmp/test.mts
exec 7<>/tmp/test.mts
ffmpeg -i /tmp/test.mts out.mp4
In another window:
cat ... >/tmp/test.mts
cat ... >/tmp/test.mts
The idea is that a reader won't receive an EOF from a pipe until all processes which had it open for writing have closed it:
$ mkfifo /tmp/fifo
$ cat /tmp/fifo &
[1] 26437
$ exec 7>/tmp/fifo
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ exec 7>&-
$
[1]+ Done cat /tmp/fifo
Without the exec 7>/tmp/fifo
which keeps an open handle to the writing end of /tmp/fifo
, the cat
would've terminated after the first echo
.
The weird thing is, the process that's writing to the fifo doesn't end if I do theffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.
– Joshua Walsh
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Simply open that fifo for writing (and keep it open) from another place, too. Example:
In a window:
mkfifo /tmp/test.mts
exec 7<>/tmp/test.mts
ffmpeg -i /tmp/test.mts out.mp4
In another window:
cat ... >/tmp/test.mts
cat ... >/tmp/test.mts
The idea is that a reader won't receive an EOF from a pipe until all processes which had it open for writing have closed it:
$ mkfifo /tmp/fifo
$ cat /tmp/fifo &
[1] 26437
$ exec 7>/tmp/fifo
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ exec 7>&-
$
[1]+ Done cat /tmp/fifo
Without the exec 7>/tmp/fifo
which keeps an open handle to the writing end of /tmp/fifo
, the cat
would've terminated after the first echo
.
The weird thing is, the process that's writing to the fifo doesn't end if I do theffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.
– Joshua Walsh
2 days ago
add a comment |
up vote
2
down vote
accepted
Simply open that fifo for writing (and keep it open) from another place, too. Example:
In a window:
mkfifo /tmp/test.mts
exec 7<>/tmp/test.mts
ffmpeg -i /tmp/test.mts out.mp4
In another window:
cat ... >/tmp/test.mts
cat ... >/tmp/test.mts
The idea is that a reader won't receive an EOF from a pipe until all processes which had it open for writing have closed it:
$ mkfifo /tmp/fifo
$ cat /tmp/fifo &
[1] 26437
$ exec 7>/tmp/fifo
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ exec 7>&-
$
[1]+ Done cat /tmp/fifo
Without the exec 7>/tmp/fifo
which keeps an open handle to the writing end of /tmp/fifo
, the cat
would've terminated after the first echo
.
The weird thing is, the process that's writing to the fifo doesn't end if I do theffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.
– Joshua Walsh
2 days ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Simply open that fifo for writing (and keep it open) from another place, too. Example:
In a window:
mkfifo /tmp/test.mts
exec 7<>/tmp/test.mts
ffmpeg -i /tmp/test.mts out.mp4
In another window:
cat ... >/tmp/test.mts
cat ... >/tmp/test.mts
The idea is that a reader won't receive an EOF from a pipe until all processes which had it open for writing have closed it:
$ mkfifo /tmp/fifo
$ cat /tmp/fifo &
[1] 26437
$ exec 7>/tmp/fifo
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ exec 7>&-
$
[1]+ Done cat /tmp/fifo
Without the exec 7>/tmp/fifo
which keeps an open handle to the writing end of /tmp/fifo
, the cat
would've terminated after the first echo
.
Simply open that fifo for writing (and keep it open) from another place, too. Example:
In a window:
mkfifo /tmp/test.mts
exec 7<>/tmp/test.mts
ffmpeg -i /tmp/test.mts out.mp4
In another window:
cat ... >/tmp/test.mts
cat ... >/tmp/test.mts
The idea is that a reader won't receive an EOF from a pipe until all processes which had it open for writing have closed it:
$ mkfifo /tmp/fifo
$ cat /tmp/fifo &
[1] 26437
$ exec 7>/tmp/fifo
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ echo yes >/tmp/fifo
yes
$ exec 7>&-
$
[1]+ Done cat /tmp/fifo
Without the exec 7>/tmp/fifo
which keeps an open handle to the writing end of /tmp/fifo
, the cat
would've terminated after the first echo
.
edited Nov 22 at 8:47
answered Nov 22 at 8:06
mosvy
4,831322
4,831322
The weird thing is, the process that's writing to the fifo doesn't end if I do theffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.
– Joshua Walsh
2 days ago
add a comment |
The weird thing is, the process that's writing to the fifo doesn't end if I do theffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.
– Joshua Walsh
2 days ago
The weird thing is, the process that's writing to the fifo doesn't end if I do the
ffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.– Joshua Walsh
2 days ago
The weird thing is, the process that's writing to the fifo doesn't end if I do the
ffmpeg -i pipe:0 -c:v libx264 test.mp4 < /tmp/test.mts
thing. From tests I've done, the process writing to the fifo exits as soon as ffmpeg exits.– Joshua Walsh
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483359%2fhow-can-i-stop-ffmpeg-from-quitting-when-it-reaches-the-end-of-a-named-pipe%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why does it feel hacky to put a standerd input into a standerd input field?
– Michael Prokopec
Nov 22 at 7:20
1
I don't understand how
ffmpeg -i pipe:0 < fifo.mts
is different in this regard fromffmpeg -i fifo.mts
; both will receive an EOF and exit here when the (last handle to the) writing end offifo.mts
is closed.– mosvy
Nov 22 at 8:47