FFMPEG output to append to a text file without overwriting the content

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

FFMPEG output to append to a text file without overwriting the content

Sana Tafleen
Hello,

I am sending a UDP stream to the destination and saving the contents of the
FFMPEG output to a text file. I run the ffmpeg command in a loop as follows,


while :
do
      echo `ffmpeg -hide_banner -f v4l2 -i /dev/video0 -c:v libx264 -f
mpegts tcp://ip:port -c:v libx264 /path/to/.mp4 2> out.txt -y`
done



When I disconnect the cable connected the destination, the above ffmpeg
process stops and a new one starts oevrwriting the content of the output
that has been saved. And when I reconnect the cable, a new ffmpeg process
starts and its output is what is displayed in the out.txt file.

I need the output of each ffmpeg process that runs to an output file. Can
anyone please suggest me a way to do it?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMPEG output to append to a text file without overwriting the content

robertlazarski
On Mon, Jun 4, 2018 at 6:06 PM, Sana Tafleen <[hidden email]> wrote:

> Hello,
>
> I am sending a UDP stream to the destination and saving the contents of the
> FFMPEG output to a text file. I run the ffmpeg command in a loop as
> follows,
>
>
> while :
> do
>       echo `ffmpeg -hide_banner -f v4l2 -i /dev/video0 -c:v libx264 -f
> mpegts tcp://ip:port -c:v libx264 /path/to/.mp4 2> out.txt -y`
> done
>
>
>
> When I disconnect the cable connected the destination, the above ffmpeg
> process stops and a new one starts oevrwriting the content of the output
> that has been saved. And when I reconnect the cable, a new ffmpeg process
> starts and its output is what is displayed in the out.txt file.
>
> I need the output of each ffmpeg process that runs to an output file. Can
> anyone please suggest me a way to do it?
>

This part of the command, '2> out.txt ' says (a) redirect stderr and not
stdout, to out.txt. And (b) overwrite the previous contents.

You can append instead of overwrite by using '2>> out.txt ' .

I would not expect ffmpeg to create a new process in that loop but I have
no experience with mpegts. I would try -stdin since I have seen unexpected
behavior without it in loops.

A long shot would be using nohup, if its a hangup of some sort. I would try
that if I was still stuck. Then strace on the command to see why it was
creating the extra process.

Kind regards,
Robert



> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMPEG output to append to a text file without overwriting the content

robertlazarski
On Mon, Jun 4, 2018 at 6:36 PM, robertlazarski <[hidden email]>
wrote:

>
>
> On Mon, Jun 4, 2018 at 6:06 PM, Sana Tafleen <[hidden email]>
> wrote:
>
> I would not expect ffmpeg to create a new process in that loop but I have
> no experience with mpegts. I would try -stdin since I have seen unexpected
> behavior without it in loops.
>
>
Meant to say -nostdin .
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMPEG output to append to a text file without overwriting the content

Sana Tafleen
In reply to this post by robertlazarski
What I am trying to achieve here is to get the number of I,P and B frames
at the end of streaming. When the disconnection happens, the ffmpeg process
at the sender stops at the terminal and when I connect it back, it starts
sending the frames. Doing this, the number of frames at the receiver is
higher than the number of frames at the sender. I am guessing it is
because, when the ffmpeg stops, it kills the previous process and starts a
new process trying to gain connection with the destination. When it gets
the connection, a new process starts and that output is sent to 'out.txt',
overwriting the output of the previous ffmpeg process. Which is why the
frame count at sender is lesser than that at the receiver. I hope this
makes any sense. Any help here would be appreciated.


Regards,
Sana Tafleen

On Mon, Jun 4, 2018 at 7:36 PM, robertlazarski <[hidden email]>
wrote:

> On Mon, Jun 4, 2018 at 6:06 PM, Sana Tafleen <[hidden email]>
> wrote:
>
> > Hello,
> >
> > I am sending a UDP stream to the destination and saving the contents of
> the
> > FFMPEG output to a text file. I run the ffmpeg command in a loop as
> > follows,
> >
> >
> > while :
> > do
> >       echo `ffmpeg -hide_banner -f v4l2 -i /dev/video0 -c:v libx264 -f
> > mpegts tcp://ip:port -c:v libx264 /path/to/.mp4 2> out.txt -y`
> > done
> >
> >
> >
> > When I disconnect the cable connected the destination, the above ffmpeg
> > process stops and a new one starts oevrwriting the content of the output
> > that has been saved. And when I reconnect the cable, a new ffmpeg process
> > starts and its output is what is displayed in the out.txt file.
> >
> > I need the output of each ffmpeg process that runs to an output file. Can
> > anyone please suggest me a way to do it?
> >
>
> This part of the command, '2> out.txt ' says (a) redirect stderr and not
> stdout, to out.txt. And (b) overwrite the previous contents.
>
> You can append instead of overwrite by using '2>> out.txt ' .
>
> I would not expect ffmpeg to create a new process in that loop but I have
> no experience with mpegts. I would try -stdin since I have seen unexpected
> behavior without it in loops.
>
> A long shot would be using nohup, if its a hangup of some sort. I would try
> that if I was still stuck. Then strace on the command to see why it was
> creating the extra process.
>
> Kind regards,
> Robert
>
>
>
> > _______________________________________________
> > ffmpeg-user mailing list
> > [hidden email]
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >
> > To unsubscribe, visit link above, or email
> > [hidden email] with subject "unsubscribe".
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMPEG output to append to a text file without overwriting the content

DopeLabs
you can always just timestamp each text file so it writes a new file on each iteration of ffmpeg running

out.mp4 2> $(date +%Y-%m-%d_%H-%M-%S).txt



> On Jun 4, 2018, at 5:48 57PM, Sana Tafleen <[hidden email]> wrote:
>
> What I am trying to achieve here is to get the number of I,P and B frames
> at the end of streaming. When the disconnection happens, the ffmpeg process
> at the sender stops at the terminal and when I connect it back, it starts
> sending the frames. Doing this, the number of frames at the receiver is
> higher than the number of frames at the sender. I am guessing it is
> because, when the ffmpeg stops, it kills the previous process and starts a
> new process trying to gain connection with the destination. When it gets
> the connection, a new process starts and that output is sent to 'out.txt',
> overwriting the output of the previous ffmpeg process. Which is why the
> frame count at sender is lesser than that at the receiver. I hope this
> makes any sense. Any help here would be appreciated.
>
>
> Regards,
> Sana Tafleen
>
> On Mon, Jun 4, 2018 at 7:36 PM, robertlazarski <[hidden email]>
> wrote:
>
>> On Mon, Jun 4, 2018 at 6:06 PM, Sana Tafleen <[hidden email]>
>> wrote:
>>
>>> Hello,
>>>
>>> I am sending a UDP stream to the destination and saving the contents of
>> the
>>> FFMPEG output to a text file. I run the ffmpeg command in a loop as
>>> follows,
>>>
>>>
>>> while :
>>> do
>>>      echo `ffmpeg -hide_banner -f v4l2 -i /dev/video0 -c:v libx264 -f
>>> mpegts tcp://ip:port -c:v libx264 /path/to/.mp4 2> out.txt -y`
>>> done
>>>
>>>
>>>
>>> When I disconnect the cable connected the destination, the above ffmpeg
>>> process stops and a new one starts oevrwriting the content of the output
>>> that has been saved. And when I reconnect the cable, a new ffmpeg process
>>> starts and its output is what is displayed in the out.txt file.
>>>
>>> I need the output of each ffmpeg process that runs to an output file. Can
>>> anyone please suggest me a way to do it?
>>>
>>
>> This part of the command, '2> out.txt ' says (a) redirect stderr and not
>> stdout, to out.txt. And (b) overwrite the previous contents.
>>
>> You can append instead of overwrite by using '2>> out.txt ' .
>>
>> I would not expect ffmpeg to create a new process in that loop but I have
>> no experience with mpegts. I would try -stdin since I have seen unexpected
>> behavior without it in loops.
>>
>> A long shot would be using nohup, if its a hangup of some sort. I would try
>> that if I was still stuck. Then strace on the command to see why it was
>> creating the extra process.
>>
>> Kind regards,
>> Robert
>>
>>
>>
>>> _______________________________________________
>>> ffmpeg-user mailing list
>>> [hidden email]
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>>
>>> To unsubscribe, visit link above, or email
>>> [hidden email] with subject "unsubscribe".
>> _______________________________________________
>> ffmpeg-user mailing list
>> [hidden email]
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
>> To unsubscribe, visit link above, or email
>> [hidden email] with subject "unsubscribe".
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMPEG output to append to a text file without overwriting the content

Sana Tafleen
In reply to this post by robertlazarski
I understand now that there is no new ffmpeg process starting. But I do
have one doubt, is there any possibility that the P or B frames may be
converted to one another during encoding process? Because I find the same
total number of frames at both ends, but the number of P  and B frames
differ.


Regards,
Sana Tafleen

On Mon, Jun 4, 2018 at 7:38 PM, robertlazarski <[hidden email]>
wrote:

> On Mon, Jun 4, 2018 at 6:36 PM, robertlazarski <[hidden email]>
> wrote:
>
> >
> >
> > On Mon, Jun 4, 2018 at 6:06 PM, Sana Tafleen <[hidden email]>
> > wrote:
> >
> > I would not expect ffmpeg to create a new process in that loop but I have
> > no experience with mpegts. I would try -stdin since I have seen
> unexpected
> > behavior without it in loops.
> >
> >
> Meant to say -nostdin .
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".