I am relatively new to ffmpeg but I am a a very experienced software engineer (mainly real-time embedded). I am investigating to see if the ffmpeg framework can be used for a media converter project I am working on. The product will be sort of a proxy server which will transcode media requests in order to control bandwidth. It will sit between various clients (not ours) such as browsers and media servers (also not ours). I think ffmpeg can do this but I am not sure exactly how to get started. It seems that in order to this as part of an application I would need to duplicate much of the code in ffmpeg and ffserver (the application code not the libraries). I do not like this approach. I was hoping I could just use ffmpeg directly such that it can transcode the media as it streams through the system. If anyone could provide some insight it would be greatly appreciated. Thanks, Bob
On Fri, Feb 26, 2010 at 3:28 PM, <robertk54 at aol.com> wrote:
I am relatively new to ffmpeg but I am a a very experienced software engineer (mainly real-time embedded). I am investigating to see if the ffmpeg framework can be used for a media converter project I am working on. The product will be sort of a proxy server which will transcode media requests in order to control bandwidth. It will sit between various clients (not ours) such as browsers and media servers (also not ours). I think ffmpeg can do this but I am not sure exactly how to get started. It seems that in order to this as part of an application I would need to duplicate much of the code in ffmpeg and ffserver (the application code not the libraries). I do not like this approach. I was hoping I could just use ffmpeg directly such that it can transcode the media as it streams through the system. If anyone could provide some insight it would be greatly appreciated.
If ffmpeg is just suppose to transcode a media transport stream (e.g., mpeg2 or m2ts) you can use ffmpeg directly by piping in the stream and outputting to another pipe. You can use stdin and stdout by using "-" instead of a file name for input and output destinations. You can also use a FIFO (e.g., mkfifo video.m2ts) and stream in and out of ffmpeg that way. Any application code can open up the IO stream and "feed to"/"consume from" ffmpeg using pipes or a FIFO). Hope that gets you thinking in the right direction. I also hope I am understanding your situation correctly, that you want to run a media stream through ffmpeg and pull out the transcoded stream in real-time to go "further down the chain" as your project sees fit. Jarred
Thanks, Bob
_______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Thanks Jarred, this is a big help and I believe this is the right direction. And yes, I do want to run the media stream through ffmpeg in real-time. I looked into using pipes but this opens up more questions. I am familiar with linux and pipes but I am far from expert. Took a look at a few examples and seems there are two options, pipe and popen. If I use popen and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I would then write the bytes to the handle. However, I am confused as to what command to use for the read pipe. If I use pipe to create a pipe which is written to and read from, how do I connect this to ffmpeg? Hope I am not diverging too far from the main purpose of this mail list. Thanks, Bob -----Original Message----- From: Jarred Nicholls <jarred.nicholls at gmail.com> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu> Sent: Fri, Feb 26, 2010 3:37 pm Subject: Re: [FFmpeg-user] Need some advice On Fri, Feb 26, 2010 at 3:28 PM, <robertk54 at aol.com> wrote:>> I am relatively new to ffmpeg but I am a a very experienced software> engineer (mainly real-time embedded). I am investigating to see if the> ffmpeg framework can be used for a media converter project I am working on.> The product will be sort of a proxy server which will transcode media> requests in order to control bandwidth. It will sit between various clients> (not ours) such as browsers and media servers (also not ours). I think> ffmpeg can do this but I am not sure exactly how to get started. It seems> that in order to this as part of an application I would need to duplicate> much of the code in ffmpeg and ffserver (the application code not the> libraries). I do not like this approach. I was hoping I could just use> ffmpeg directly such that it can transcode the media as it streams through> the system. If anyone could provide some insight it would be greatly> appreciated.>If ffmpeg is just suppose to transcode a media transport stream (e.g., mpeg2or m2ts) you can use ffmpeg directly by piping in the stream and outputtingto another pipe. You can use stdin and stdout by using "-" instead of afile name for input and output destinations. You can also use a FIFO (e.g.,mkfifo video.m2ts) and stream in and out of ffmpeg that way. Anyapplication code can open up the IO stream and "feed to"/"consume from"ffmpeg using pipes or a FIFO).Hope that gets you thinking in the right direction. I also hope I amunderstanding your situation correctly, that you want to run a media streamthrough ffmpeg and pull out the transcoded stream in real-time to go"further down the chain" as your project sees fit.Jarred>>>> Thanks,> Bob>> _______________________________________________> ffmpeg-user mailing list> ffmpeg-user at mplayerhq.hu> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>_______________________________________________ffmpeg-user mailing listffmpeg-user at mplayerhq.huhttps://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:
Thanks Jarred, this is a big help and I believe this is the right direction. And yes, I do want to run the media stream through ffmpeg in real-time.
I looked into using pipes but this opens up more questions. I am familiar with linux and pipes but I am far from expert. Took a look at a few examples and seems there are two options, pipe and popen. If I use popen and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I would then write the bytes to the handle. However, I am confused as to what command to use for the read pipe. If I use pipe to create a pipe which is written to and read from, how do I connect this to ffmpeg? Hope I am not diverging too far from the main purpose of this mail list.
You're on the right track. What I would do is use "popen" to run the FFmpeg command, and read the stdout from ffmpeg to get the result encoding (remember to use a "-" as the output filename for ffmpeg, instead of an actual filename). For input, I would create a FIFO, i.e., "mkfifo video.m2ts". You would in turn specify "-i video.m2ts" as the input file for FFmpeg. Then, you can open up the FIFO *for writing* in your code and get a file pointer just as if you were opening up any other file on the file system. When you start writing data (your input video stream) to the FIFO, FFmpeg will get that data and start processing it as it retrieves it. When you are done writing all your video stream data (if ever), you can write an EOF and close the file pointer, which FFmpeg will see and thus will finish the encoding process. *In parallel to writing to the FIFO*, you can be capturing the stdout of FFmpeg using the pipe file pointer you received from the "popen" command and doing whatever you want with that data. For example, in pseudo-C code: *// Create FIFO* *system("mkfifo video.m2ts");* * * *// run ffmpeg and get a pipe file pointer to read from* *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec libmp3lame -ab 128k -ac 2 -", "r");* * * *// open the FIFO for writing* *FILE* in = fopen("video.m2ts", "w");* * * *// New async thread/loop to write incoming video stream to FIFO* *{* * // some binary/video data "data"* * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), in);* *}* * * *// New async thread/loop to read output video stream from FFmpeg* *{* * // some allocated memory buffer "buffer"* * fread(buffer, sizeof(char), buffer_size, out);* * * * // do something with video data* *}* * * Hope that helps and makes sense. The important thing is the order...the FIFO should be opened for reading and "read from" prior to opened for writing and "written to", which is why you want to run ffmpeg prior to opening the FIFO for writing...just kind of how a FIFO works. I don't know if that's universally true but in the past for me it's been the case, otherwise ffmpeg would just hang. Jarred
Thanks, Bob
-----Original Message----- From: Jarred Nicholls <jarred.nicholls at gmail.com> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu> Sent: Fri, Feb 26, 2010 3:37 pm Subject: Re: [FFmpeg-user] Need some advice
On Fri, Feb 26, 2010 at 3:28 PM, <robertk54 at aol.com> wrote:>> I am relatively new to ffmpeg but I am a a very experienced software> engineer (mainly real-time embedded). I am investigating to see if the> ffmpeg framework can be used for a media converter project I am working on.> The product will be sort of a proxy server which will transcode media> requests in order to control bandwidth. It will sit between various clients> (not ours) such as browsers and media servers (also not ours). I think> ffmpeg can do this but I am not sure exactly how to get started. It seems> that in order to this as part of an application I would need to duplicate> much of the code in ffmpeg and ffserver (the application code not the> libraries). I do not like this approach. I was hoping I could just use> ffmpeg directly such that it can transcode the media as it streams through> the system. If anyone could provide some insight it would be greatly> appreciated.>If ffmpeg is just suppose to transcode a media transport stream (e.g., mpeg2or m2ts) you can use ffmpeg directly by piping in the stream and outputtingto another pipe. You can use stdin and stdout by using "-" instead of afile name for input and output destinations. You can also use a FIFO (e.g.,mkfifo video.m2ts) and stream in and out of ffmpeg that way. Anyapplication code can open up the IO stream and "feed to"/"consume from"ffmpeg using pipes or a FIFO).Hope that gets you thinking in the right direction. I also hope I amunderstanding your situation correctly, that you want to run a media streamthrough ffmpeg and pull out the transcoded stream in real-time to go"further down the chain" as your project sees fit.Jarred>>>> Thanks,> Bob>> _______________________________________________> ffmpeg-user mailing list> ffmpeg-user at mplayerhq.hu> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>_______________________________________________ffmpeg-user mailing listffmpeg-user at mplayerhq.huhttps://lists .mplayerhq.hu/mailman/listinfo/ffmpeg-user
_______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls <jarred.nicholls at gmail.com
wrote:
On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:
Thanks Jarred, this is a big help and I believe this is the right direction. And yes, I do want to run the media stream through ffmpeg in real-time.
I looked into using pipes but this opens up more questions. I am familiar with linux and pipes but I am far from expert. Took a look at a few examples and seems there are two options, pipe and popen. If I use popen and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I would then write the bytes to the handle. However, I am confused as to what command to use for the read pipe. If I use pipe to create a pipe which is written to and read from, how do I connect this to ffmpeg? Hope I am not diverging too far from the main purpose of this mail list.
You're on the right track. What I would do is use "popen" to run the FFmpeg command, and read the stdout from ffmpeg to get the result encoding (remember to use a "-" as the output filename for ffmpeg, instead of an actual filename). For input, I would create a FIFO, i.e., "mkfifo video.m2ts". You would in turn specify "-i video.m2ts" as the input file for FFmpeg. Then, you can open up the FIFO *for writing* in your code and get a file pointer just as if you were opening up any other file on the file system. When you start writing data (your input video stream) to the FIFO, FFmpeg will get that data and start processing it as it retrieves it. When you are done writing all your video stream data (if ever), you can write an EOF and close the file pointer, which FFmpeg will see and thus will finish the encoding process. *In parallel to writing to the FIFO*, you can be capturing the stdout of FFmpeg using the pipe file pointer you received from the "popen" command and doing whatever you want with that data.
For example, in pseudo-C code:
*// Create FIFO* *system("mkfifo video.m2ts");* * * *// run ffmpeg and get a pipe file pointer to read from* *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec libmp3lame -ab 128k -ac 2 -", "r");* * * *// open the FIFO for writing* *FILE* in = fopen("video.m2ts", "w");* * * *// New async thread/loop to write incoming video stream to FIFO* *{* * // some binary/video data "data"* * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), in);* *}* * * *// New async thread/loop to read output video stream from FFmpeg* *{* * // some allocated memory buffer "buffer"* * fread(buffer, sizeof(char), buffer_size, out);* * * * // do something with video data* *}* * * Hope that helps and makes sense. The important thing is the order...the FIFO should be opened for reading and "read from" prior to opened for writing and "written to", which is why you want to run ffmpeg prior to opening the FIFO for writing...just kind of how a FIFO works. I don't know if that's universally true but in the past for me it's been the case, otherwise ffmpeg would just hang.
Jarred
I thought I'd also mention that, while this technique can work for "finite" video files of all types, this technique will really only work best for "transport stream" types (input & output) like m2ts or other elementary streams when doing real-time/constant encoding. I.e., if you take two m2ts files and just concat them together, that's perfectly legit and they'll play sequentially as a whole video, no problem. Those are the types of streams you want to be working with, if you weren't already aware/considering this. Jarred
Thanks, Bob
-----Original Message----- From: Jarred Nicholls <jarred.nicholls at gmail.com> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu> Sent: Fri, Feb 26, 2010 3:37 pm Subject: Re: [FFmpeg-user] Need some advice
On Fri, Feb 26, 2010 at 3:28 PM, <robertk54 at aol.com> wrote:>> I am relatively new to ffmpeg but I am a a very experienced software> engineer (mainly real-time embedded). I am investigating to see if the> ffmpeg framework can be used for a media converter project I am working on.> The product will be sort of a proxy server which will transcode media> requests in order to control bandwidth. It will sit between various clients> (not ours) such as browsers and media servers (also not ours). I think> ffmpeg can do this but I am not sure exactly how to get started. It seems> that in order to this as part of an application I would need to duplicate> much of the code in ffmpeg and ffserver (the application code not the> libraries). I do not like this approach. I was hoping I could just use> ffmpeg directly such that it can transcode the media as it streams through> the system. If anyone could provide some insight it would be greatly> appreciated.>If ffmpeg is just suppose to transcode a media transport stream (e.g., mpeg2or m2ts) you can use ffmpeg directly by piping in the stream and outputtingto another pipe. You can use stdin and stdout by using "-" instead of afile name for input and output destinations. You can also use a FIFO (e.g.,mkfifo video.m2ts) and stream in and out of ffmpeg that way. Anyapplication code can open up the IO stream and "feed to"/"consume from"ffmpeg using pipes or a FIFO).Hope that gets you thinking in the right direction. I also hope I amunderstanding your situation correctly, that you want to run a media streamthrough ffmpeg and pull out the transcoded stream in real-time to go"further down the chain" as your project sees fit.Jarred>>>> Thanks,> Bob>> _______________________________________________> ffmpeg-user mailing list> ffmpeg-user at mplayerhq.hu> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>_______________________________________________ffmpeg-user mailing listffmpeg-user at mplayerhq.huhttps://lists .mplayerhq.hu/mailman/listinfo/ffmpeg-user
_______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Ah, now this makes total sense. Thanks again Jarred, this was a great help. One more question. Is there a way to add an image or text overlay as part of the ffmpeg command which is passed to popen for transcoding the video? This would be a fixed image or text overlay for all transcodes. -----Original Message----- From: Jarred Nicholls <jarred.nicholls at gmail.com> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu> Sent: Sun, Feb 28, 2010 10:20 pm Subject: Re: [FFmpeg-user] Need some advice On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls <jarred.nicholls at gmail.com> wrote:> On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:>>> Thanks Jarred, this is a big help and I believe this is the right>> direction. And yes, I do want to run the media stream through ffmpeg in>> real-time.>>>>>> I looked into using pipes but this opens up more questions. I am familiar>> with linux and pipes but I am far from expert. Took a look at a few>> examples and seems there are two options, pipe and popen. If I use popen>> and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I>> would then write the bytes to the handle. However, I am confused as to what>> command to use for the read pipe. If I use pipe to create a pipe which is>> written to and read from, how do I connect this to ffmpeg? Hope I am not>> diverging too far from the main purpose of this mail list.>>>> You're on the right track. What I would do is use "popen" to run the> FFmpeg command, and read the stdout from ffmpeg to get the result encoding> (remember to use a "-" as the output filename for ffmpeg, instead of an> actual filename). For input, I would create a FIFO, i.e., "mkfifo> video.m2ts". You would in turn specify "-i video.m2ts" as the input file> for FFmpeg. Then, you can open up the FIFO *for writing* in your code and> get a file pointer just as if you were opening up any other file on the file> system. When you start writing data (your input video stream) to the FIFO,> FFmpeg will get that data and start processing it as it retrieves it. When> you are done writing all your video stream data (if ever), you can write an> EOF and close the file pointer, which FFmpeg will see and thus will finish> the encoding process. *In parallel to writing to the FIFO*, you can be> capturing the stdout of FFmpeg using the pipe file pointer you received from> the "popen" command and doing whatever you want with that data.>> For example, in pseudo-C code:>> *// Create FIFO*> *system("mkfifo video.m2ts");*> *> *> *// run ffmpeg and get a pipe file pointer to read from*> *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec> libmp3lame -ab 128k -ac 2 -", "r");*> *> *> *// open the FIFO for writing*> *FILE* in = fopen("video.m2ts", "w");*> *> *> *// New async thread/loop to write incoming video stream to FIFO*> *{*> * // some binary/video data "data"*> * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), in);*> *}*> *> *> *// New async thread/loop to read output video stream from FFmpeg*> *{*> * // some allocated memory buffer "buffer"*> * fread(buffer, sizeof(char), buffer_size, out);*> *> *> * // do something with video data*> *}*> *> *> Hope that helps and makes sense. The important thing is the order...the> FIFO should be opened for reading and "read from" prior to opened for> writing and "written to", which is why you want to run ffmpeg prior to> opening the FIFO for writing...just kind of how a FIFO works. I don't know> if that's universally true but in the past for me it's been the case,> otherwise ffmpeg would just hang.>> Jarred>I thought I'd also mention that, while this technique can work for "finite"video files of all types, this technique will really only work best for"transport stream" types (input & output) like m2ts or other elementarystreams when doing real-time/constant encoding. I.e., if you take two m2tsfiles and just concat them together, that's perfectly legit and they'll playsequentially as a whole video, no problem. Those are the types of streamsyou want to be working with, if you weren't already aware/considering this.Jarred>>>>>>>> Thanks,>> Bob>>>>>>>>>> -----Original Message----->> From: Jarred Nicholls <jarred.nicholls at gmail.com>>> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu>>> Sent: Fri, Feb 26, 2010 3:37 pm>> Subject: Re: [FFmpeg-user] Need some advice>>>>>> On Fri, Feb 26, 2010 at 3:28 PM, <robertk54 at aol.com> wrote:>> I am>> relatively new to ffmpeg but I am a a very experienced software> engineer>> (mainly real-time embedded). I am investigating to see if the> ffmpeg>> framework can be used for a media converter project I am working on.> The>> product will be sort of a proxy server which will transcode media> requests>> in order to control bandwidth. It will sit between various clients> (not>> ours) such as browsers and media servers (also not ours). I think> ffmpeg>> can do this but I am not sure exactly how to get started. It seems> that in>> order to this as part of an application I would need to duplicate> much of>> the code in ffmpeg and ffserver (the application code not the> libraries).>> I do not like this approach. I was hoping I could just use> ffmpeg>> directly such that it can transcode the media as it streams through> the>> system. If anyone could provide some insight it would be greatly>>> appreciated.>If ffmpeg is just suppose to>> transcode a media transport stream (e.g., mpeg2or m2ts) you can use>> ffmpeg directly by piping in the stream and outputtingto another pipe. You>> can use stdin and stdout by using "-" instead of afile name for input and>> output destinations. You can also use a FIFO (e.g.,mkfifo video.m2ts) and>> stream in and out of ffmpeg that way. Anyapplication code can open up the>> IO stream and "feed to"/"consume from"ffmpeg using pipes or a FIFO).Hope>> that gets you thinking in the right direction. I also hope I>> amunderstanding your situation correctly, that you want to run a media>> streamthrough ffmpeg and pull out the transcoded stream in real-time to>> go"further down the chain" as your project sees fit.Jarred>>>> Thanks,>>> Bob>> _______________________________________________> ffmpeg-user mailing>> list> ffmpeg-user at mplayerhq.hu>>> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>_______________________________________________ffmpeg-user>> mailing listffmpeg-user at mplayerhq.huhttps://lists>> .mplayerhq.hu/mailman/listinfo/ffmpeg-user>>>>>> _______________________________________________>> ffmpeg-user mailing list>> ffmpeg-user at mplayerhq.hu>> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>>>>_______________________________________________ffmpeg-user mailing listffmpeg-user at mplayerhq.huhttps://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Mon, Mar 1, 2010 at 9:28 AM, <robertk54 at aol.com> wrote:
Ah, now this makes total sense. Thanks again Jarred, this was a great help.
Great! Glad to help.
One more question. Is there a way to add an image or text overlay as part of the ffmpeg command which is passed to popen for transcoding the video? This would be a fixed image or text overlay for all transcodes.
First I just want to say that on this mailing list, you are suppose to reply inline. "Top" posting is highly discouraged for several reasons, some technical and some not. The list moderators would appreciate it. Yes, you can use the "overlay" filter from the Summer of Code repository, which can be used with the "-vfilters" ffmpeg option. Go here: http://wiki.multimedia.cx/index.php?title=Libavfilter At the very top of the page is the SVN URL, checkout the repository and follow the README instructions to pull in the FFmpeg trunk and patch it. You will then have to compile and install FFmpeg with your normal configuration options, but also being sure to include "--enable-avfilter --enable-avfilter-lavf". There are docs in that same libavfilter repository about how to use the overlay filter, and this question was just answered I think 2-3 times in the last week on this mailing list, so do a Google search as well if needed :-) Jarred
-----Original Message----- From: Jarred Nicholls <jarred.nicholls at gmail.com> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu> Sent: Sun, Feb 28, 2010 10:20 pm Subject: Re: [FFmpeg-user] Need some advice
On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls < jarred.nicholls at gmail.com> wrote:> On Sun, Feb 28, 2010 at 4:05 PM, < robertk54 at aol.com> wrote:>>> Thanks Jarred, this is a big help and I believe this is the right>> direction. And yes, I do want to run the media stream through ffmpeg in>> real-time.>>>>>> I looked into using pipes but this opens up more questions. I am familiar>> with linux and pipes but I am far from expert. Took a look at a few>> examples and seems there are two options, pipe and popen. If I use popen>> and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I>> would then write the bytes to the handle. However, I am confused as to what>> command to use for the read pipe. If I use pipe to create a pipe which is>> written to and read from, how do I connect this to ffmpeg? Hope I am not>> diverging too far from the main purpose of this mail list.>>>> You're on the right track. What I would do is use "popen" to run the> FFmpeg command, and read the stdout from ffmpeg to get the result encoding> (remember to use a "-" as the output filename for ffmpeg, instead of an> actual filename). For input, I would create a FIFO, i.e., "mkfifo> video.m2ts". You would in turn specify "-i video.m2ts" as the input file> for FFmpeg. Then, you can open up the FIFO *for writing* in your code and> get a file pointer just as if you were opening up any other file on the file> system. When you start writing data (your input video stream) to the FIFO,> FFmpeg will get that data and start processing it as it retrieves it. When> you are done writing all your video stream data (if ever), you can write an> EOF and close the file pointer, which FFmpeg will see and thus will finish> the encoding process. *In parallel to writing to the FIFO*, you can be> capturing the stdout of FFmpeg using the pipe file pointer you received from> the "popen" command and doing whatever you want with that data.>> For example, in pseudo-C code:>> * // Create FIFO*> *system("mkfifo video.m2ts");*> *> *> *// run ffmpeg and get a pipe file pointer to read from*> *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec> libmp3lame -ab 128k -ac 2 -", "r");*> *> *> *// open the FIFO for writing*> *FILE* in = fopen("video.m2ts", "w");*> *> *> *// New async thread/loop to write incoming video stream to FIFO*> *{*> * // some binary/video data "data"*> * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), in);*> *}*> *> *> *// New async thread/loop to read output video stream from FFmpeg*> *{*> * // some allocated memory buffer "buffer"*> * fread(buffer, sizeof(char), buffer_size, out);*> *> *> * // do something with video data*> *}*> *> *> Hope that helps and makes sense. The important thing is the order...the> FIFO should be opened for reading and "read from" prior to opened for> writing and "written to", which is why you want to run ffmpeg prior to> opening the FIFO for writing...just kind of how a FIFO works. I don't know> if that's universally true but in the past for me it's been the case,> otherwise ffmpeg would just hang.>> Jarred>I thought I'd also mention that, while this technique can work for "finite"video files of all types, this technique will really only work best for"transport stream" types (input & output) like m2ts or other elementarystreams when doing real-time/constant encoding. I.e., if you take two m2tsfiles and just concat them together, that's perfectly legit and they'll playsequentially as a whole video, no problem. Those are the types of streamsyou want to be working with, if you weren't already aware/considering this.Jarred>>>>>>>> Thanks,>> Bob>>>>>>>>>> -----Original Message----->> From: Jarred Nicholls <jarred.nicholls at gmail.com>>> To: FFmpeg user questions and RTFMs <ffmpeg-user at mplayerhq.hu>>> Sent: Fri, Feb 26, 2010 3:37 pm>> Subject: Re: [FFmpeg-user] Need some advice>>>>>> On Fri, Feb 26, 2010 at 3:28 PM, <robertk54 at aol.com> wrote:>> I am>> relatively new to ffmpeg but I am a a very experienced software> engineer>> (mainly real-time embedded). I am investigating to see if the> ffmpeg>> framework can be used for a media converter project I am working on.> The>> product will be sort of a proxy server which will transcode media> requests>> in order to control bandwidth. It will sit between various clients> (not>> ours) such as browsers and media servers (also not ours). I think> ffmpeg>> can do this but I am not sure exactly how to get started. It seems> that in>> order to this as part of an application I would need to duplicate> much of>> the code in ffmpeg and ffserver (the application code not the> libraries).>> I do not like this approach. I was hoping I could just use> ffmpeg>> directly such that it can transcode the media as it streams through> the>> system. If anyone could provide some insight it would be greatly>>> appreciated.>If ffmpeg is just suppose to>> transcode a media trans port stream (e.g., mpeg2or m2ts) you can use>> ffmpeg directly by piping in the stream and outputtingto another pipe. You>> can use stdin and stdout by using "-" instead of afile name for input and>> output destinations. You can also use a FIFO (e.g.,mkfifo video.m2ts) and>> stream in and out of ffmpeg that way. Anyapplication code can open up the>> IO stream and "feed to"/"consume from"ffmpeg using pipes or a FIFO).Hope>> that gets you thinking in the right direction. I also hope I>> amunderstanding your situation correctly, that you want to run a media>> streamthrough ffmpeg and pull out the transcoded stream in real-time to>> go"further down the chain" as your project sees fit.Jarred>>>> Thanks,>>> Bob>> _______________________________________________> ffmpeg-user mailing>> list> ffmpeg-user at mplayerhq.hu>>> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>_______________________________________________ffmpeg-user>> mailing listffmpeg-user at mplayerhq.huhttps://li sts>> .mplayerhq.hu/mailman/listinfo/ffmpeg-user>>>>>> _______________________________________________>> ffmpeg-user mailing list>> ffmpeg-user at mplayerhq.hu>> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user>>>>_______________________________________________ffmpeg-user mailing listffmpeg-user at mplayerhq.huhttps:// lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
_______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Hello, is there any place to download ffmpeg already compiled static for mipsel ? thanks
On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls <jarred.nicholls at gmail.com>> wrote:>>> On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:>>>>> Thanks Jarred, this is a big help and I believe this is the right>>> direction. And yes, I do want to run the media stream through ffmpeg in>>> real-time.>>>>>>>>> I looked into using pipes but this opens up more questions. I am familiar>>> with linux and pipes but I am far from expert. Took a look at a few>>> examples and seems there are two options, pipe and popen. If I use popen>>> and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I>>> would then write the bytes to the handle. However, I am confused as to what>>> command to use for the read pipe. If I use pipe to create a pipe which is>>> written to and read from, how do I connect this to ffmpeg? Hope I am not>>> diverging too far from the main purpose of this mail list.>>>>>>> You're on the right track. What I would do is use "popen" to run the>> FFmpeg command, and read the stdout from ffmpeg to get the result encoding>> (remember to use a "-" as the output filename for ffmpeg, instead of an>> actual filename). For input, I would create a FIFO, i.e., "mkfifo>> video.m2ts". You would in turn specify "-i video.m2ts" as the input file>> for FFmpeg. Then, you can open up the FIFO *for writing* in your code and>> get a file pointer just as if you were opening up any other file on the file>> system. When you start writing data (your input video stream) to the FIFO,>> FFmpeg will get that data and start processing it as it retrieves it. When>> you are done writing all your video stream data (if ever), you can write an>> EOF and close the file pointer, which FFmpeg will see and thus will finish>> the encoding process. *In parallel to writing to the FIFO*, you can be>> capturing the stdout of FFmpeg using the pipe file pointer you received from>> the "popen" command and doing whatever you want with that data.>>>> For example, in pseudo-C code:>>>> *// Create FIFO*>> *system("mkfifo video.m2ts");*>> *>> *>> *// run ffmpeg and get a pipe file pointer to read from*>> *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec>> libmp3lame -ab 128k -ac 2 -", "r");*>> *>> *>> *// open the FIFO for writing*>> *FILE* in = fopen("video.m2ts", "w");*>> *>> *>> *// New async thread/loop to write incoming video stream to FIFO*>> *{*>> * // some binary/video data "data"*>> * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), in);*>> *}*>> *>> *>> *// New async thread/loop to read output video stream from FFmpeg*>> *{*>> * // some allocated memory buffer "buffer"*>> * fread(buffer, sizeof(char), buffer_size, out);*>> *>> *>> * // do something with video data*>> *}*>> *>> *>> Hope that helps and makes sense. The important thing is the order...the>> FIFO should be opened for reading and "read from" prior to opened for>> writing and "written to", which is why you want to run ffmpeg prior to>> opening the FIFO for writing...just kind of how a FIFO works. I don't know>> if that's universally true but in the past for me it's been the case,>> otherwise ffmpeg would just hang.>>>> Jarred>> Well, I implemented my code based on the pseudo code provided by Jarred. I believe the code is generally correct but I am stuck. The code hangs at the call to fopen which opens the FIFO for writing. I assume this is because there is some issue with the popen call and the ffmpeg command such that the FIFO is not properly opened for reading prior to the open for writing. Unfortunately, I have tried a number of iterations and can't find the right solution. I am able to manually call ffmpeg using the same command line options to convert an existing file.My code . . .<<* m_strContentPath is set to "/mnt/tmpfs/" though I have tried other paths as well as "".* m_bFFmpegReady is initially false* m_strContainerType is set from the inbound media container type, in this case it's "flv"* I tried both methods for making the FIFO, both properly create the named pipe file.void HttpRequest::SendContentToFFmpeg(void* a_pvData, size_t a_iSize, size_t a_iNumMembers){ string l_strFunction = string(__FUNCTION__) + string("() "); LOG4CXX_DEBUG(logger, l_strFunction + "Enter"); string l_strSystemCommand; // First time through, create the FIFO and open in the proper order (read then write) if (!m_bFFmpegReady) { m_strInpContentFileName = m_strContentPath + "content-" + m_strId + "." + m_strContainerType; m_strOutContentFileName = m_strContentPath + "content-" + m_strId + ".cnv." + m_strContainerType;// m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -b 350k -acodec copy -"; m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -acodec copy -";// m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -"; LOG4CXX_DEBUG(logger, l_strFunction + "mkfifo " + m_strInpContentFileName);#if 1 if (mkfifo (m_strInpContentFileName.c_str(), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to mkfifo " + m_strInpContentFileName + "errno " << errno); goto SendContentToFFmpegExit0; }#else l_strSystemCommand = "mkfifo " + m_strInpContentFileName; system(l_strSystemCommand.c_str());#endif if (m_pfPipeFromFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + "popen " + m_strFFmpegCommand); m_pfPipeFromFFmpeg = popen (m_strFFmpegCommand.c_str(), "r"); if (!m_pfPipeFromFFmpeg) { LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe failed"); goto SendContentToFFmpegExit0; } LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe passed"); } LOG4CXX_DEBUG(logger, l_strFunction + "fopen " + m_strInpContentFileName); m_pfFIFOToFFmpeg = fopen(m_strInpContentFileName.c_str(), "w"); ////// THIS HANGS if (m_pfFIFOToFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to fopen " + m_strInpContentFileName); goto SendContentToFFmpegExit0; } m_bFFmpegReady = true; } LOG4CXX_DEBUG(logger, l_strFunction + "fwrite (" << a_iSize + ", " << a_iNumMembers + ")"); if (a_pvData && a_iSize && a_iNumMembers) { fwrite(a_pvData, a_iSize, a_iNumMembers, m_pfFIFOToFFmpeg); }SendContentToFFmpegExit0: LOG4CXX_DEBUG(logger, l_strFunction + "Exit"); return;}
I thought I'd also mention that, while this technique can work for "finite">video files of all types, this technique will really only work best for>"transport stream" types (input & output) like m2ts or other elementary>streams when doing real-time/constant encoding. I.e., if you take two m2ts>files and just concat them together, that's perfectly legit and they'll play>sequentially as a whole video, no problem. Those are the types of streams>you want to be working with, if you weren't already aware/considering this.>>Jarred
On Tue, Mar 2, 2010 at 3:23 PM, <robertk54 at aol.com> wrote:
>
> >On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls <
> jarred.nicholls at gmail.com>> wrote:>>> On Sun, Feb 28, 2010 at 4:05 PM, <
> robertk54 at aol.com> wrote:>>>>> Thanks Jarred, this is a big help and I
> believe this is the right>>> direction. And yes, I do want to run the media
> stream through ffmpeg in>>> real-time.>>>>>>>>> I looked into using pipes
> but this opens up more questions. I am familiar>>> with linux and pipes but
> I am far from expert. Took a look at a few>>> examples and seems there are
> two options, pipe and popen. If I use popen>>> and to create a write pipe,
> I can use "ffmpeg -i - ..." as the command. I>>> would then write the bytes
> to the handle. However, I am confused as to what>>> command to use for the
> read pipe. If I use pipe to create a pipe which is>>> written to and read
> from, how do I connect this to ffmpeg? Hope I am not>>> diverging too far
> from the main purpose of this mail list.>>>>>>> You're on the right track.
> What I would do is use "popen" to run
> the>> FFmpeg command, and read the stdout from ffmpeg to get the result
> encoding>> (remember to use a "-" as the output filename for ffmpeg, instead
> of an>> actual filename). For input, I would create a FIFO, i.e., "mkfifo>>
> video.m2ts". You would in turn specify "-i video.m2ts" as the input file>>
> for FFmpeg. Then, you can open up the FIFO *for writing* in your code and>>
> get a file pointer just as if you were opening up any other file on the
> file>> system. When you start writing data (your input video stream) to the
> FIFO,>> FFmpeg will get that data and start processing it as it retrieves
> it. When>> you are done writing all your video stream data (if ever), you
> can write an>> EOF and close the file pointer, which FFmpeg will see and
> thus will finish>> the encoding process. *In parallel to writing to the
> FIFO*, you can be>> capturing the stdout of FFmpeg using the pipe file
> pointer you received from>> the "popen" command and doing whatever you want
> with that data.>>>
> > For example, in pseudo-C code:>>>> *// Create FIFO*>> *system("mkfifo
> video.m2ts");*>> *>> *>> *// run ffmpeg and get a pipe file pointer to read
> from*>> *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k
> -acodec>> libmp3lame -ab 128k -ac 2 -", "r");*>> *>> *>> *// open the FIFO
> for writing*>> *FILE* in = fopen("video.m2ts", "w");*>> *>> *>> *// New
> async thread/loop to write incoming video stream to FIFO*>> *{*>> * //
> some binary/video data "data"*>> * fwrite(data, sizeof(data[0]),
> sizeof(data)/sizeof(data[0]), in);*>> *}*>> *>> *>> *// New async
> thread/loop to read output video stream from FFmpeg*>> *{*>> * // some
> allocated memory buffer "buffer"*>> * fread(buffer, sizeof(char),
> buffer_size, out);*>> *>> *>> * // do something with video data*>> *}*>>
> *>> *>> Hope that helps and makes sense. The important thing is the
> order...the>> FIFO should be opened for reading and "read from" prior to
> opened for>> writing and "written to", which is why you
> want to run ffmpeg prior to>> opening the FIFO for writing...just kind of
> how a FIFO works. I don't know>> if that's universally true but in the past
> for me it's been the case,>> otherwise ffmpeg would just hang.>>>> Jarred>>
> Well, I implemented my code based on the pseudo code provided by Jarred. I
> believe the code is generally correct but I am stuck. The code hangs at the
> call to fopen which opens the FIFO for writing. I assume this is because
> there is some issue with the popen call and the ffmpeg command such that the
> FIFO is not properly opened for reading prior to the open for writing.
> Unfortunately, I have tried a number of iterations and can't find the right
> solution. I am able to manually call ffmpeg using the same command line
> options to convert an existing file.My code . . .<<* m_strContentPath is set
> to "/mnt/tmpfs/" though I have tried other paths as well as "".*
> m_bFFmpegReady is initially false* m_strContainerType is set from the
> inbound media container type, in this case it's "flv"* I tried both methods
> for making the FIFO, both properly create the named pipe file.void
> HttpRequest::SendContentToFFmpeg(void* a_pvData, size_t a_iSize, size_t
> a_iNumMembers){ string l_strFunction =
> string(__FUNCTION__) + string("() "); LOG4CXX_DEBUG(logger,
> l_strFunction + "Enter"); string l_strSystemCommand; // First time through,
> create the FIFO and open in the proper order (read then write) if
> (!m_bFFmpegReady) { m_strInpContentFileName = m_strContentPath +
> "content-" + m_strId + "." + m_strContainerType;
> m_strOutContentFileName = m_strContentPath + "content-" + m_strId + ".cnv."
> + m_strContainerType;// m_strFFmpegCommand = "ffmpeg -i " +
> m_strInpContentFileName + " -vcodec copy -b 350k -acodec copy -";
> m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy
> -acodec copy -";// m_strFFmpegCommand = "ffmpeg -i " +
> m_strInpContentFileName + " -"; LOG4CXX_DEBUG(logger, l_strFunction +
> "mkfifo " + m_strInpContentFileName);#if 1 if (mkfifo
> (m_strInpContentFileName.c_str(), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0)
> { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to mkfifo " +
> m_strInpContentFil
> eName + "errno " << errno); goto SendContentToFFmpegExit0;
> }#else l_strSystemCommand = "mkfifo " + m_strInpContentFileName;
> system(l_strSystemCommand.c_str());#endif if (m_pfPipeFromFFmpeg ==
> NULL) { LOG4CXX_DEBUG(logger, l_strFunction + "popen " +
> m_strFFmpegCommand); m_pfPipeFromFFmpeg = popen
> (m_strFFmpegCommand.c_str(), "r"); if (!m_pfPipeFromFFmpeg)
> { LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg
> output pipe failed"); goto SendContentToFFmpegExit0;
> } LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe
> passed"); } LOG4CXX_DEBUG(logger, l_strFunction + "fopen " +
> m_strInpContentFileName); m_pfFIFOToFFmpeg =
> fopen(m_strInpContentFileName.c_str(), "w"); ////// THIS HANGS if
> (m_pfFIFOToFFmpeg == NULL) { LOG4CXX_DEBUG(logger,
> l_strFunction + " Failed to fopen " + m_strInpContentFileName);
> goto SendContentToFFmpegExit0; } m_bFFmpegReady = true; }
> LOG4CXX_DEBUG(logger, l_strFunction + "fwrite (" << a_iSize + ", " <<
> a_iNumMembers + ")"); if (a_pvData && a_iSize && a_iNumMembers) {
> fwrite(a_pvData, a_iSize, a_iNumMembers, m_pfFIFOToFFmpeg);
> }SendContentToFFmpegExit0: LOG4CXX_DEBUG(logger, l_strFunction + "Exit");
> return;}
> >>
> >>I thought I'd also mention that, while this technique can work for
> "finite">video files of all types, this technique will really only work best
> for>"transport stream" types (input & output) like m2ts or other
> elementary>streams when doing real-time/constant encoding. I.e., if you
> take two m2ts>files and just concat them together, that's perfectly legit
> and they'll play>sequentially as a whole video, no problem. Those are the
> types of streams>you want to be working with, if you weren't already
> aware/considering this.>>Jarred
>
>
Hey Robert, it may just be me but the formatting of your email went
completely whack, I'm having an aneurysm just trying to read it. Can you
clean it up and re-send?
Thanks,
Jarred
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>
On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls <jarred.nicholls at gmail.com
wrote:
On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:
Thanks Jarred, this is a big help and I believe this is the right direction. And yes, I do want to run the media stream through ffmpeg in real-time.
I looked into using pipes but this opens up more questions. I am familiar with linux and pipes but I am far from expert. Took a look at a few examples and seems there are two options, pipe and popen. If I use popen and to create a write pipe, I can use "ffmpeg -i - ..." as the command. I would then write the bytes to the handle. However, I am confused as to what command to use for the read pipe. If I use pipe to create a pipe which is written to and read from, how do I connect this to ffmpeg? Hope I am not diverging too far from the main purpose of this mail list.
You're on the right track. What I would do is use "popen" to run the FFmpeg command, and read the stdout from ffmpeg to get the result encoding (remember to use a "-" as the output filename for ffmpeg, instead of an actual filename). For input, I would create a FIFO, i.e., "mkfifo video.m2ts". You would in turn specify "-i video.m2ts" as the input file for FFmpeg. Then, you can open up the FIFO *for writing* in your code and get a file pointer just as if you were opening up any other file on the file system. When you start writing data (your input video stream) to the FIFO, FFmpeg will get that data and start processing it as it retrieves it. When you are done writing all your video stream data (if ever), you can write an EOF and close the file pointer, which FFmpeg will see and thus will finish the encoding process. *In parallel to writing to the FIFO*, you can be capturing the stdout of FFmpeg using the pipe file pointer you received from the "popen" command and doing whatever you want with that data.
For example, in pseudo-C code:
*// Create FIFO* *system("mkfifo video.m2ts");* * * *// run ffmpeg and get a pipe file pointer to read from* *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec libmp3lame -ab 128k -ac 2 -", "r");* * * *// open the FIFO for writing* *FILE* in = fopen("video.m2ts", "w");* * * *// New async thread/loop to write incoming video stream to FIFO* *{* * // some binary/video data "data"* * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), in);* *}* * * *// New async thread/loop to read output video stream from FFmpeg* *{* * // some allocated memory buffer "buffer"* * fread(buffer, sizeof(char), buffer_size, out);* * * * // do something with video data* *}* * * Hope that helps and makes sense. The important thing is the order...the FIFO should be opened for reading and "read from" prior to opened for writing and "written to", which is why you want to run ffmpeg prior to opening the FIFO for writing...just kind of how a FIFO works. I don't know if that's universally true but in the past for me it's been the case, otherwise ffmpeg would just hang.
Jarred
I thought I'd also mention that, while this technique can work for "finite" video files of all types, this technique will really only work best for "transport stream" types (input & output) like m2ts or other elementary streams when doing real-time/constant encoding. I.e., if you take two m2ts files and just concat them together, that's perfectly legit and
sequentially as a whole video, no problem. Those are the types of streams you want to be working with, if you weren't already aware/considering
Well, I implemented my code based on the pseudo code provided by Jarred. I believe the code is generally correct but I am stuck. The code hangs at the call to fopen which opens the FIFO for writing. I assume this is because there is some issue with the popen call and the ffmpeg command such that the FIFO is not properly opened for reading prior to the open for writing. Unfortunately, I have tried a number of iterations and can't find the right solution. I am able to manually call ffmpeg using the same command line options to convert an existing file. My code . . . * m_strContentPath is set to "/mnt/tmpfs/" though I have tried other paths as well as "". * m_bFFmpegReady is initially false * m_strContainerType is set from the inbound media container type, in this case it's "flv" * I tried both methods for making the FIFO, both properly create the named pipe file. << void HttpRequest::SendContentToFFmpeg(void* a_pvData, size_t a_iSize, size_t a_iNumMembers) { string l_strFunction = string(__FUNCTION__) + string("() "); LOG4CXX_DEBUG(logger, l_strFunction + "Enter"); string l_strSystemCommand; // First time through, create the FIFO and open in the proper order (read then write) if (!m_bFFmpegReady) { m_strInpContentFileName = m_strContentPath + "content-" + m_strId + "." + m_strContainerType; m_strOutContentFileName = m_strContentPath + "content-" + m_strId + ".cnv." + m_strContainerType; // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -b 350k -acodec copy -"; m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -acodec copy -"; // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -"; LOG4CXX_DEBUG(logger, l_strFunction + "mkfifo " + m_strInpContentFileName); #if 1 if (mkfifo (m_strInpContentFileName.c_str(), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to mkfifo " + m_strInpContentFileName + "errno " << errno); goto SendContentToFFmpegExit0; } #else l_strSystemCommand = "mkfifo " + m_strInpContentFileName; system(l_strSystemCommand.c_str()); #endif if (m_pfPipeFromFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + "popen " + m_strFFmpegCommand); m_pfPipeFromFFmpeg = popen (m_strFFmpegCommand.c_str(), "r"); if (!m_pfPipeFromFFmpeg) { LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe failed"); goto SendContentToFFmpegExit0; } LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe passed"); } LOG4CXX_DEBUG(logger, l_strFunction + "fopen " + m_strInpContentFileName); m_pfFIFOToFFmpeg = fopen(m_strInpContentFileName.c_str(), "w"); ////// THIS HANGS if (m_pfFIFOToFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to fopen " + m_strInpContentFileName); goto SendContentToFFmpegExit0; } m_bFFmpegReady = true; } LOG4CXX_DEBUG(logger, l_strFunction + "fwrite (" << a_iSize + ", " << a_iNumMembers + ")"); if (a_pvData && a_iSize && a_iNumMembers) { fwrite(a_pvData, a_iSize, a_iNumMembers, m_pfFIFOToFFmpeg); } SendContentToFFmpegExit0: LOG4CXX_DEBUG(logger, l_strFunction + "Exit"); return; } they'll play this.
Jarred
On Tue, Mar 2, 2010 at 3:36 PM, <robertk54 at aol.com> wrote:
On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls
<jarred.nicholls at gmail.com
wrote:
On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:
Thanks Jarred, this is a big help and I believe this is the right
direction. And yes, I do want to run the media stream through
ffmpeg in
real-time.
I looked into using pipes but this opens up more questions. I am
familiar
with linux and pipes but I am far from expert. Took a look at a few
examples and seems there are two options, pipe and popen. If I use
popen
and to create a write pipe, I can use "ffmpeg -i - ..." as the
command. I
would then write the bytes to the handle. However, I am confused as
to what
command to use for the read pipe. If I use pipe to create a pipe
which is
written to and read from, how do I connect this to ffmpeg? Hope I
am not
diverging too far from the main purpose of this mail list.
You're on the right track. What I would do is use "popen" to run the FFmpeg command, and read the stdout from ffmpeg to get the result
encoding
(remember to use a "-" as the output filename for ffmpeg, instead of
an
actual filename). For input, I would create a FIFO, i.e., "mkfifo
video.m2ts". You would in turn specify "-i video.m2ts" as the input
file
for FFmpeg. Then, you can open up the FIFO *for writing* in your
code and
get a file pointer just as if you were opening up any other file on
the file
system. When you start writing data (your input video stream) to
the FIFO,
FFmpeg will get that data and start processing it as it retrieves
it. When
you are done writing all your video stream data (if ever), you can
write an
EOF and close the file pointer, which FFmpeg will see and thus will
finish
the encoding process. *In parallel to writing to the FIFO*, you can
be
capturing the stdout of FFmpeg using the pipe file pointer you
received from
the "popen" command and doing whatever you want with that data.
For example, in pseudo-C code:
*// Create FIFO* *system("mkfifo video.m2ts");* * * *// run ffmpeg and get a pipe file pointer to read from* *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec libmp3lame -ab 128k -ac 2 -", "r");* * * *// open the FIFO for writing* *FILE* in = fopen("video.m2ts", "w");* * * *// New async thread/loop to write incoming video stream to FIFO* *{* * // some binary/video data "data"* * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]),
in);*
*}*
* * *// New async thread/loop to read output video stream from FFmpeg* *{* * // some allocated memory buffer "buffer"* * fread(buffer, sizeof(char), buffer_size, out);* * * * // do something with video data* *}* * * Hope that helps and makes sense. The important thing is the
order...the
FIFO should be opened for reading and "read from" prior to opened for
writing and "written to", which is why you want to run ffmpeg prior
to
opening the FIFO for writing...just kind of how a FIFO works. I
don't know
if that's universally true but in the past for me it's been the case,
otherwise ffmpeg would just hang.
Jarred
Well, I implemented my code based on the pseudo code provided by Jarred. I believe the code is generally correct but I am stuck. The code hangs at the call to fopen which opens the FIFO for writing. I assume this is because there is some issue with the popen call and the ffmpeg command such that the FIFO is not properly opened for reading prior to the open for writing. Unfortunately, I have tried a number of iterations and can't find the right solution. I am able to manually call ffmpeg using the same command line options to convert an existing file.
My code . . .
* m_strContentPath is set to "/mnt/tmpfs/" though I have tried other paths as well as "". * m_bFFmpegReady is initially false * m_strContainerType is set from the inbound media container type, in this case it's "flv" * I tried both methods for making the FIFO, both properly create the named pipe file.
<< void HttpRequest::SendContentToFFmpeg(void* a_pvData, size_t a_iSize, size_t a_iNumMembers) { string l_strFunction = string(__FUNCTION__) + string("() "); LOG4CXX_DEBUG(logger, l_strFunction + "Enter");
string l_strSystemCommand;
// First time through, create the FIFO and open in the proper order (read then write) if (!m_bFFmpegReady) { m_strInpContentFileName = m_strContentPath + "content-" + m_strId + "." + m_strContainerType; m_strOutContentFileName = m_strContentPath + "content-" + m_strId + ".cnv." + m_strContainerType; // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -b 350k -acodec copy -"; m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -acodec copy -"; // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -";
LOG4CXX_DEBUG(logger, l_strFunction + "mkfifo " + m_strInpContentFileName); #if 1 if (mkfifo (m_strInpContentFileName.c_str(), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to mkfifo " + m_strInpContentFileName + "errno " << errno);
goto SendContentToFFmpegExit0; } #else l_strSystemCommand = "mkfifo " + m_strInpContentFileName; system(l_strSystemCommand.c_str()); #endif if (m_pfPipeFromFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + "popen " + m_strFFmpegCommand); m_pfPipeFromFFmpeg = popen (m_strFFmpegCommand.c_str(), "r"); if (!m_pfPipeFromFFmpeg) { LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe failed"); goto SendContentToFFmpegExit0; } LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe passed"); } LOG4CXX_DEBUG(logger, l_strFunction + "fopen " + m_strInpContentFileName); m_pfFIFOToFFmpeg = fopen(m_strInpContentFileName.c_str(), "w"); ////// THIS HANGS if (m_pfFIFOToFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to fopen " + m_strInpContentFileName); goto SendContentToFFmpegExit0; } m_bFFmpegReady = true; } LOG4CXX_DEBUG(logger, l_strFunction + "fwrite (" << a_iSize + ", " << a_iNumMembers + ")");
if (a_pvData && a_iSize && a_iNumMembers) { fwrite(a_pvData, a_iSize, a_iNumMembers, m_pfFIFOToFFmpeg); }
SendContentToFFmpegExit0: LOG4CXX_DEBUG(logger, l_strFunction + "Exit"); return; }
Hi Robert, Try adding " &" to the end of the ffmpeg command so it's non-blocking in the underlying shell and thus on the returned file descriptor. If that doesn't work, have you tried opening the FIFO for writing prior to running the FFmpeg command (yep, that's right, exactly opposite of what I said)? My experience with this has been in a Ruby environment using IO.popen, which for all intents and purposes is the same thing, except Ruby takes care of the plumbing and hooking up the sub-process to the Ruby process via a pipe...so certain flags such as O_NONBLOCK might be occuring under the hood. Or in other words, I don't know if it's using the popen() system call or a combination of fork()/exec()/pipe() instead...my guess would be the latter. Jarred
I thought I'd also mention that, while this technique can work for
"finite"
video files of all types, this technique will really only work best for "transport stream" types (input & output) like m2ts or other elementary streams when doing real-time/constant encoding. I.e., if you take two
m2ts
files and just concat them together, that's perfectly legit and
they'll play
sequentially as a whole video, no problem. Those are the types of
streams
you want to be working with, if you weren't already aware/considering
this.
Jarred
_______________________________________________
ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Tue, Mar 2, 2010 at 4:10 PM, Jarred Nicholls <jarred.nicholls at gmail.com>wrote:
On Tue, Mar 2, 2010 at 3:36 PM, <robertk54 at aol.com> wrote:
On Sun, Feb 28, 2010 at 10:08 PM, Jarred Nicholls
<jarred.nicholls at gmail.com
wrote:
On Sun, Feb 28, 2010 at 4:05 PM, <robertk54 at aol.com> wrote:
Thanks Jarred, this is a big help and I believe this is the right
direction. And yes, I do want to run the media stream through
ffmpeg in
real-time.
I looked into using pipes but this opens up more questions. I am
familiar
with linux and pipes but I am far from expert. Took a look at a few
examples and seems there are two options, pipe and popen. If I use
popen
and to create a write pipe, I can use "ffmpeg -i - ..." as the
command. I
would then write the bytes to the handle. However, I am confused as
to what
command to use for the read pipe. If I use pipe to create a pipe
which is
written to and read from, how do I connect this to ffmpeg? Hope I
am not
diverging too far from the main purpose of this mail list.
You're on the right track. What I would do is use "popen" to run the FFmpeg command, and read the stdout from ffmpeg to get the result
encoding
(remember to use a "-" as the output filename for ffmpeg, instead of
an
actual filename). For input, I would create a FIFO, i.e., "mkfifo
video.m2ts". You would in turn specify "-i video.m2ts" as the input
file
for FFmpeg. Then, you can open up the FIFO *for writing* in your
code and
get a file pointer just as if you were opening up any other file on
the file
system. When you start writing data (your input video stream) to
the FIFO,
FFmpeg will get that data and start processing it as it retrieves
it. When
you are done writing all your video stream data (if ever), you can
write an
EOF and close the file pointer, which FFmpeg will see and thus will
finish
the encoding process. *In parallel to writing to the FIFO*, you can
be
capturing the stdout of FFmpeg using the pipe file pointer you
received from
the "popen" command and doing whatever you want with that data.
For example, in pseudo-C code:
*// Create FIFO* *system("mkfifo video.m2ts");* * * *// run ffmpeg and get a pipe file pointer to read from* *FILE* out = popen("ffmpeg -i video.m2ts -vcodec flv -b 500k -acodec libmp3lame -ab 128k -ac 2 -", "r");* * * *// open the FIFO for writing* *FILE* in = fopen("video.m2ts", "w");* * * *// New async thread/loop to write incoming video stream to FIFO* *{* * // some binary/video data "data"* * fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]),
in);*
*}*
* * *// New async thread/loop to read output video stream from FFmpeg* *{* * // some allocated memory buffer "buffer"* * fread(buffer, sizeof(char), buffer_size, out);* * * * // do something with video data* *}* * * Hope that helps and makes sense. The important thing is the
order...the
FIFO should be opened for reading and "read from" prior to opened for
writing and "written to", which is why you want to run ffmpeg prior
to
opening the FIFO for writing...just kind of how a FIFO works. I
don't know
if that's universally true but in the past for me it's been the case,
otherwise ffmpeg would just hang.
Jarred
Well, I implemented my code based on the pseudo code provided by Jarred. I believe the code is generally correct but I am stuck. The code hangs at the call to fopen which opens the FIFO for writing. I assume this is because there is some issue with the popen call and the ffmpeg command such that the FIFO is not properly opened for reading prior to the open for writing. Unfortunately, I have tried a number of iterations and can't find the right solution. I am able to manually call ffmpeg using the same command line options to convert an existing file.
My code . . .
* m_strContentPath is set to "/mnt/tmpfs/" though I have tried other paths as well as "". * m_bFFmpegReady is initially false * m_strContainerType is set from the inbound media container type, in this case it's "flv" * I tried both methods for making the FIFO, both properly create the named pipe file.
<< void HttpRequest::SendContentToFFmpeg(void* a_pvData, size_t a_iSize, size_t a_iNumMembers) { string l_strFunction = string(__FUNCTION__) + string("() "); LOG4CXX_DEBUG(logger, l_strFunction + "Enter");
string l_strSystemCommand;
// First time through, create the FIFO and open in the proper order (read then write) if (!m_bFFmpegReady) { m_strInpContentFileName = m_strContentPath + "content-" + m_strId + "." + m_strContainerType; m_strOutContentFileName = m_strContentPath + "content-" + m_strId + ".cnv." + m_strContainerType; // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -b 350k -acodec copy -"; m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -vcodec copy -acodec copy -"; // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName + " -";
LOG4CXX_DEBUG(logger, l_strFunction + "mkfifo " + m_strInpContentFileName); #if 1 if (mkfifo (m_strInpContentFileName.c_str(), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to mkfifo " + m_strInpContentFileName + "errno " << errno);
goto SendContentToFFmpegExit0; } #else l_strSystemCommand = "mkfifo " + m_strInpContentFileName; system(l_strSystemCommand.c_str()); #endif if (m_pfPipeFromFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + "popen " + m_strFFmpegCommand); m_pfPipeFromFFmpeg = popen (m_strFFmpegCommand.c_str(), "r"); if (!m_pfPipeFromFFmpeg) { LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe failed"); goto SendContentToFFmpegExit0; } LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg output pipe passed"); } LOG4CXX_DEBUG(logger, l_strFunction + "fopen " + m_strInpContentFileName); m_pfFIFOToFFmpeg = fopen(m_strInpContentFileName.c_str(), "w"); ////// THIS HANGS if (m_pfFIFOToFFmpeg == NULL) { LOG4CXX_DEBUG(logger, l_strFunction + " Failed to fopen " + m_strInpContentFileName); goto SendContentToFFmpegExit0; } m_bFFmpegReady = true; } LOG4CXX_DEBUG(logger, l_strFunction + "fwrite (" << a_iSize + ", " << a_iNumMembers + ")");
if (a_pvData && a_iSize && a_iNumMembers) { fwrite(a_pvData, a_iSize, a_iNumMembers, m_pfFIFOToFFmpeg); }
SendContentToFFmpegExit0: LOG4CXX_DEBUG(logger, l_strFunction + "Exit"); return; }
Hi Robert,
Try adding " &" to the end of the ffmpeg command so it's non-blocking in the underlying shell and thus on the returned file descriptor. If that doesn't work, have you tried opening the FIFO for writing prior to running the FFmpeg command (yep, that's right, exactly opposite of what I said)? My experience with this has been in a Ruby environment using IO.popen, which for all intents and purposes is the same thing, except Ruby takes care of the plumbing and hooking up the sub-process to the Ruby process via a pipe...so certain flags such as O_NONBLOCK might be occuring under the hood. Or in other words, I don't know if it's using the popen() system call or a combination of fork()/exec()/pipe() instead...my guess would be the latter.
Jarred
Yes, try both, adding " &" and/or opening the FIFO before FFmpeg. I ran the series of bash commands that simulate what you're doing (I had an existing video named test.flv): mkfifo input.flv cat test.flv > input.flv & ffmpeg -i input.flv -vcodec copy -acodec copy output.flv Which completes non-blocking. I swapped ffmpeg and cat (appending & to ffmpeg instead) and ffmpeg opened the file and read a portion of it, but then blocked/hung. Jarred
I thought I'd also mention that, while this technique can work for
"finite"
video files of all types, this technique will really only work best for "transport stream" types (input & output) like m2ts or other elementary streams when doing real-time/constant encoding. I.e., if you take two
m2ts
files and just concat them together, that's perfectly legit and
they'll play
sequentially as a whole video, no problem. Those are the types of
streams
you want to be working with, if you weren't already aware/considering
this.
Jarred
_______________________________________________
ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>>> Well, I implemented my code based on the pseudo code provided by
Jarred.
>>> I believe the code is generally correct but I am stuck. The code
hangs at
>>> the call to fopen which opens the FIFO for writing. I assume this
is
>>> because there is some issue with the popen call and the ffmpeg
command such
>>> that the FIFO is not properly opened for reading prior to the open
for
>>> writing. Unfortunately, I have tried a number of iterations and
can't find
>>> the right solution. I am able to manually call ffmpeg using the
same
>>> command line options to convert an existing file.
>>>
>>> My code . . .
>>>
>>> * m_strContentPath is set to "/mnt/tmpfs/" though I have tried
other paths
>>> as well as "".
>>> * m_bFFmpegReady is initially false
>>> * m_strContainerType is set from the inbound media container type,
in this
>>> case it's "flv"
>>> * I tried both methods for making the FIFO, both properly create
the named
>>> pipe file.
>>>
>>> <<
>>> void HttpRequest::SendContentToFFmpeg(void* a_pvData, size_t
a_iSize,
>>> size_t a_iNumMembers)
>>> {
>>> string l_strFunction = string(__FUNCTION__) + string("() ");
>>> LOG4CXX_DEBUG(logger, l_strFunction + "Enter");
>>>
>>> string l_strSystemCommand;
>>>
>>> // First time through, create the FIFO and open in the proper
order
>>> (read then write)
>>> if (!m_bFFmpegReady)
>>> {
>>> m_strInpContentFileName = m_strContentPath + "content-" +
m_strId +
>>> "." + m_strContainerType;
>>> m_strOutContentFileName = m_strContentPath + "content-" +
m_strId +
>>> ".cnv." + m_strContainerType;
>>> // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName
+ "
>>> -vcodec copy -b 350k -acodec copy -";
>>> m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName
+ "
>>> -vcodec copy -acodec copy -";
>>> // m_strFFmpegCommand = "ffmpeg -i " + m_strInpContentFileName
+ "
>>> -";
>>>
>>> LOG4CXX_DEBUG(logger, l_strFunction + "mkfifo " +
>>> m_strInpContentFileName);
>>> #if 1
>>> if (mkfifo (m_strInpContentFileName.c_str(),
>>> S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0)
>>> {
>>> LOG4CXX_DEBUG(logger, l_strFunction + " Failed to mkfifo
" +
>>> m_strInpContentFileName + "errno " << errno);
>>>
>>> goto SendContentToFFmpegExit0;
>>> }
>>> #else
>>> l_strSystemCommand = "mkfifo " + m_strInpContentFileName;
>>> system(l_strSystemCommand.c_str());
>>> #endif
>>> if (m_pfPipeFromFFmpeg == NULL)
>>> {
>>> LOG4CXX_DEBUG(logger, l_strFunction + "popen " +
>>> m_strFFmpegCommand);
>>> m_pfPipeFromFFmpeg = popen (m_strFFmpegCommand.c_str(),
"r");
>>> if (!m_pfPipeFromFFmpeg)
>>> {
>>> LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg
output
>>> pipe failed");
>>> goto SendContentToFFmpegExit0;
>>> }
>>> LOG4CXX_DEBUG(logger, l_strFunction + "popen ffmpeg
output pipe
>>> passed");
>>> }
>>> LOG4CXX_DEBUG(logger, l_strFunction + "fopen " +
>>> m_strInpContentFileName);
>>> m_pfFIFOToFFmpeg = fopen(m_strInpContentFileName.c_str(),
"w");
>>> ////// THIS HANGS
>>> if (m_pfFIFOToFFmpeg == NULL)
>>> {
>>> LOG4CXX_DEBUG(logger, l_strFunction + " Failed to fopen
" +
>>> m_strInpContentFileName);
>>> goto SendContentToFFmpegExit0;
>>> }
>>> m_bFFmpegReady = true;
>>> }
>>> LOG4CXX_DEBUG(logger, l_strFunction + "fwrite (" << a_iSize + ",
" <<
>>> a_iNumMembers + ")");
>>>
>>> if (a_pvData && a_iSize && a_iNumMembers)
>>> {
>>> fwrite(a_pvData, a_iSize, a_iNumMembers, m_pfFIFOToFFmpeg);
>>> }
>>>
>>> SendContentToFFmpegExit0:
>>> LOG4CXX_DEBUG(logger, l_strFunction + "Exit");
>>> return;
>>> }
>>>
>>
>> Hi Robert,
>>
>> Try adding " &" to the end of the ffmpeg command so it's
non-blocking in
>> the underlying shell and thus on the returned file descriptor. If
that
>> doesn't work, have you tried opening the FIFO for writing prior to
running
>> the FFmpeg command (yep, that's right, exactly opposite of what I
said)? My
>> experience with this has been in a Ruby environment using IO.popen,
which
>> for all intents and purposes is the same thing, except Ruby takes
care of
>> the plumbing and hooking up the sub-process to the Ruby process via a
>> pipe...so certain flags such as O_NONBLOCK might be occuring under
the hood.
>> Or in other words, I don't know if it's using the popen() system
call or a
>> combination of fork()/exec()/pipe() instead...my guess would be the
latter.
>>
>> Jarred
>>
>
>Yes, try both, adding " &" and/or opening the FIFO before FFmpeg.
>
>I ran the series of bash commands that simulate what you're doing (I
had an
>existing video named test.flv):
>
>mkfifo input.flv
>cat test.flv > input.flv &
>ffmpeg -i input.flv -vcodec copy -acodec copy output.flv
>
>Which completes non-blocking. I swapped ffmpeg and cat (appending & to
>ffmpeg instead) and ffmpeg opened the file and read a portion of it,
but
>then blocked/hung.
>
>Jarred
>
>
Tried both but the code still hangs at the same fopen. I suspect that
there is some disconnect
with how ffmpeg runs from the command line and the application via.
the popen. Is there any
way to debug the ffmpeg execution?
Bob
>>
>>
>>>
>>>>>
>>>> I thought I'd also mention that, while this technique can work for
>>>>>
>>> "finite"
>>>
>>>> video files of all types, this technique will really only work
best for
>>>> "transport stream" types (input & output) like m2ts or other
elementary
>>>> streams when doing real-time/constant encoding. I.e., if you take
two
>>> m2ts
>>>> files and just concat them together, that's perfectly legit and
>>> they'll play
>>>> sequentially as a whole video, no problem. Those are the types of
>>> streams
>>>> you want to be working with, if you weren't already
aware/considering
>>> this.
>>>>
>>>> Jarred
>>>>
>>> _______________________________________________
>>>
>>>> ffmpeg-user mailing list
>>> ffmpeg-user at mplayerhq.hu
>>> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>>>
>>
>>
Try adding " &" to the end of the ffmpeg command so it's non-blocking in the underlying shell and thus on the returned file descriptor. If that doesn't work, have you tried opening the FIFO for writing prior to running the FFmpeg command (yep, that's right, exactly opposite of what I said)? My experience with this has been in a Ruby environment using IO.popen, which for all intents and purposes is the same thing, except Ruby takes care of the plumbing and hooking up the sub-process to the Ruby process via a pipe...so certain flags such as O_NONBLOCK might be occuring under the hood. Or in other words, I don't know if it's using the popen() system call or a combination of fork()/exec()/pipe() instead...my guess would be the latter.
Jarred
Yes, try both, adding " &" and/or opening the FIFO before FFmpeg.
I ran the series of bash commands that simulate what you're doing (I had an existing video named test.flv):
mkfifo input.flv cat test.flv > input.flv & ffmpeg -i input.flv -vcodec copy -acodec copy output.flv
Which completes non-blocking. I swapped ffmpeg and cat (appending & to ffmpeg instead) and ffmpeg opened the file and read a portion of it, but then blocked/hung.
Jarred
Tried both but the code still hangs at the same fopen. I suspect that there is some disconnect with how ffmpeg runs from the command line and the application via. the popen. Is there any way to debug the ffmpeg execution?
Looks like my issue has to do with the execution environment for my application. Even though I am logged in as root, and even though my environemnt uses the default variables set up during the install, and even though I can execute ffmpeg from the command line, my application does not have the same access. The path to ffmpeg ('/usr/local/bin') is not available to the application. This is preventing the named pipe rom being opened as expected. I am confident that once this is resolved my application will function as expected. Also, I do not believe the '&' is needed for the popen call. Unlike the command shell invocation (without the '&'), popen is already spawning a child process. The popen call will never block though the spawned child process (sh invoking ffmpeg in my case) will. In addition, the order of opening is not a real issue. From what I read you can open either read or write first. Whichever is opened first will block until the second open is made. Jarred, thanks again for all the help!
On Thu, Mar 4, 2010 at 7:49 AM, <robertk54 at aol.com> wrote:
Try adding " &" to the end of the ffmpeg command so it's non-blocking in the underlying shell and thus on the returned file descriptor. If that doesn't work, have you tried opening the FIFO for writing prior to running the FFmpeg command (yep, that's right, exactly opposite of what I said)? My experience with this has been in a Ruby environment using IO.popen, which for all intents and purposes is the same thing, except Ruby takes care of the plumbing and hooking up the sub-process to the Ruby process via a pipe...so certain flags such as O_NONBLOCK might be occuring under the hood. Or in other words, I don't know if it's using the popen() system call or a combination of fork()/exec()/pipe() instead...my guess would be the latter.
Jarred
Yes, try both, adding " &" and/or opening the FIFO before FFmpeg.
I ran the series of bash commands that simulate what you're doing (I had an existing video named test.flv):
mkfifo input.flv cat test.flv > input.flv & ffmpeg -i input.flv -vcodec copy -acodec copy output.flv
Which completes non-blocking. I swapped ffmpeg and cat (appending & to ffmpeg instead) and ffmpeg opened the file and read a portion of it, but then blocked/hung.
Jarred
Tried both but the code still hangs at the same fopen. I suspect that there is some disconnect with how ffmpeg runs from the command line and the application via. the popen. Is there any way to debug the ffmpeg execution?
Looks like my issue has to do with the execution environment for my application. Even though I am logged in as root, and even though my environemnt uses the default variables set up during the install, and even though I can execute ffmpeg from the command line, my application does not have the same access. The path to ffmpeg ('/usr/local/bin') is not available to the application. This is preventing the named pipe rom being opened as expected. I am confident that once this is resolved my application will function as expected.
Also, I do not believe the '&' is needed for the popen call. Unlike the command shell invocation (without the '&'), popen is already spawning a child process. The popen call will never block though the spawned child process (sh invoking ffmpeg in my case) will. In addition, the order of opening is not a real issue. From what I read you can open either read or write first. Whichever is opened first will block until the second open is made.
Jarred, thanks again for all the help!
You bet, thanks for the update. Hope you get it working soon. Jarred
_______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
participants (3)
-
jarred.nicholls@gmail.com -
robertk54@aol.com -
victor@eurovip.es