How can I stop ffmpeg from quitting when it reaches the end of a named pipe?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












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!










share|improve this question





















  • 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 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














up vote
0
down vote

favorite
1












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!










share|improve this question





















  • 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 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












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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
















  • 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 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















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










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.






share|improve this answer






















  • 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










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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 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















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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay