omxplayer icon indicating copy to clipboard operation
omxplayer copied to clipboard

Add support for almost-seamless playback of multiple streams (optionally, in a loop)

Open pasky opened this issue 13 years ago • 38 comments

Hi! The code in pasky/omxplayer branch multiplestreams adds support for:

(i) Loop option (similar to another fork)

(ii) Multiple filenames on the command line

While running omxplayer in a shell loop causes gaps of about 2s between videos and dark screen with bunch of text in the meantime, with this patch the last frame of previous video is frozen for about 200ms (unless there is other load) before next video starts. The next video in the queue is opened and scanned by ffmpeg on the background while the current video is playing.

This is probably not ready for prime-time yet; at the very least, we should make some effort to gracefully handle (likely just by reinitializing OMX state) transitions between streams with different parameters.

Also, the current code contains not-so-few gotos and other ugly things. This is the main purpose of this pull request at this point, I would like to propose significant refactoring of the current main() function so that the above mentioned can be implemented much more sanely and maintainably. Basically, my idea is to create class OMXPlayer that will handle playback of a single file. Then, the main() function would just parse parameters (setting OMXPlayer attributes appropriately), take care of setting up OMXReader, call the OMXPlayer loop function, interpret keystrokes. All the stream-handling, feeding and synchronizing logic would be in the OMXPlayer class.

Does that sound sane? Would you accept a pull request containing such changes? Or would you prefer a different approach?

pasky avatar Mar 02 '13 16:03 pasky

Hi Paski, the seamless loop (of a unique file) is exactly what I need. So, thanks for your awesome collaboration. My question is how to generate the bin file from your code? Any link with instructions?

mlemos avatar Apr 03 '13 01:04 mlemos

Hi!

On Tue, Apr 02, 2013 at 06:23:31PM -0700, Manoel Lemos wrote:

Hi Paski, the seamless loop (of a unique file) is exactly what I need. So, thanks for your awesome collaboration. My question is how to generate the bin file from your code? Any link with instructions?

Set up a crosscompile environment (sorry, too complex to elaborate, there should be plenty of howtos; I use crosstools-ng), adjust Makefile.include to point at it and then simply follow compilation instructions bundled with omxplayer.

You can also try compiling it on your RPi. It will likely take several hours and you may run out of memory in case of some files - if that happens, you will need to set up a swap.

            Petr "Pasky" Baudis

pasky avatar Apr 03 '13 01:04 pasky

I compiled omxplayer on my pi, only took about 40 mins, I was pleasantly surprised.

I don't expect that your patch would push that out to several hours ;)

triffid avatar Apr 03 '13 03:04 triffid

Hmm, I admit that I was trying that on the 256M version and gave up after it got into memory trouble about 30min. after the start. The rest was a conservative extrapolation. :)

pasky avatar Apr 03 '13 10:04 pasky

Hi @triffid , how do you do that? Can you and/or @pasky also send me the binaries for omxplayer with seamless loop enabled? I'm having a really hard time to setup the crosscompile environment on my iMac with Mountain Lion.

And also, can you send me some links with instructions on how to compile it on the RasPi and also on my mac machine?

mlemos avatar Apr 07 '13 05:04 mlemos

@mlemos on the pi just do make ffmpeg; make like it says in README.md

no idea about the mac, everything I've ever tried to do on a mac has been hours of frustration so I avoid them at all costs now.

triffid avatar Apr 07 '13 06:04 triffid

Manos, you can download the binaries from http://pasky.or.cz/dev/omxplayer/omxplayer-loop-multifile-bin.tar.gz

pasky avatar Apr 07 '13 10:04 pasky

Hi @pasky , thansk for the bin. But one last "dumb" question. How do I make it loop a single movie file?

mlemos avatar Apr 07 '13 15:04 mlemos

Pass omxplayer the -L parameter.

pasky avatar Apr 07 '13 15:04 pasky

Hey @pasky, thansk a lot man!!! It's working just fine here. Do you know if the amount of GPU RAM affects the vide playback experience?

mlemos avatar Apr 07 '13 16:04 mlemos

Hi @pasky, looping with -L works a treat!!! I really appreciate your efforts with this feature. May I ask what is the syntax to play multiple files via the command line?

kelvin22 avatar Apr 28 '13 02:04 kelvin22

Hi! Glad you enjoy it. :) Simply list multiple files on the command line. Note that all the files must be encoded the same way, i.e. identical resolution, fps, etc.

pasky avatar Apr 28 '13 09:04 pasky

Hi @pasky, thanks for the reply :)

I've tried: omxplayer 01.mp4 02.mp4 -o hdmi

and also to ensure it's the same res, fps, etc.: omxplayer 01.mp4 01.mp4 -o hdmi

Both stop at the first video. Is that the correct syntax?

kelvin22 avatar Apr 28 '13 09:04 kelvin22

Hi, are you sure you are using the latest version I posted? This was an issue with the original, old version from February; the new version from beginning of April should work...

pasky avatar Apr 28 '13 09:04 pasky

I repeated the installation of the binary you posted, and it works now, I must have done something wrong. Thanks very much for the note about the videos needing to be the same encoding, that would have driven me crazy! Time to do some re-encoding...

Do you know of any clever way of storing the filenames in a playlist and having them load into the command using some sort of bash trickery?

kelvin22 avatar Apr 28 '13 10:04 kelvin22

Hi! If you have the filenames in a text file, one per line, try

cat playlist.txt | xargs omxplayer -o hdmi

pasky avatar Apr 28 '13 17:04 pasky

as long as there are no spaces in the filenames, omxplayer $(<list.pls)

If you might have spaces in filenames, we need a hair more complexity: ( IFS=$'\n'; omxplayer $(<list.pls); )

triffid avatar May 01 '13 08:05 triffid

Hi @pasky , it is working just fine for me for small videos. But for larger ones, it stops in the end of the first play (no loop). And it is not a huge video, the file is just 90MB.

Here is what I get on the output:

pi@raspberrypi /mnt/usbdisk1 $ omxplayer -L edit3-the-artist.mov thread nextreader 0x302470 (0) file : edit3-the-artist.mov result 1 format mov,mp4,m4a,3gp,3g2,mj2 audio streams 0 video streams 1 chapters 0 subtitles 0 length 738 thread opened 0x302470 (0) openok 1 Video codec omx-h264 width 1280 height 720 profile 77 fps 29.970030 Subtitle count: 0, state: off, index: 1, delay: 0 thread nextreader 0x80c1e0 (0) file : edit3-the-artist.mov result 1 format mov,mp4,m4a,3gp,3g2,mj2 audio streams 0 video streams 1 chapters 0 subtitles 0 length 738 thread opened 0x80c1e0 (0) openok 1

I waited a lot but nothing happened after that.

Another thing... do you know why videos being played from the usb disk plays better than videos played from the SD where the OS is installed?

mlemos avatar May 02 '13 02:05 mlemos

Thanks @pasky and @triffid, your suggestions for work great for creating a pseudo playlist to play filenames with and without spaces in them.

@pasky, I wanted to understand more details to what exactly the files need to have in similar for them to play. I've run about 20 videos through a Handbrake script to reencode them uniformly, however whenever I return after stepping away, omxplayer has stopped. This may have something to do with @mlemos' query too?

kelvin22 avatar May 08 '13 04:05 kelvin22

Hi! I'm sorry it doesn't work well for you; it worked fine in my scenario. Unfortunately, I don't have enough free time to look into the issue, especially if I can't reproduce it.

pasky avatar May 08 '13 10:05 pasky

@pasky thanks for your great work. Your binaries don't work for me too, so I want to set up my own RPi environment. I tried this RPi_Linaro_GCC_Compilation manual, but I had dozens of errors. Could you help me with some howtos of crosscompiling to RPi?

kramar42 avatar May 09 '13 07:05 kramar42

@pasky, no worries. I figured out the issue, the audio sample rate's were different, some at 44.1khz and some 48khz. Everything about the videos needs to be the same, including audio codec!

I found transcoding all vids through HandbrakeCLI useful for making this happen. Something like: HandBrakeCLI -e x264 -q 20 -r 25 -E faac -B 160 -6 dpl2 -R 44.1 -w 1920 -l 1080 -i filein.mp4 -o fileout.mp4

kelvin22 avatar May 09 '13 11:05 kelvin22

@pasky I have downloaded your binary dated April 2 2013, pasted into the /home directory, ran sudo tar -zxvf omxplayer-loop-multifile-bin.tar.gz, it unpacked, I then moved to the directory cd /omxplayer-dist/usr/bin, ran ./omxplayer file1.mp4 file2.mp4, and only one file runs then i get a have a nice day and it exits or stops.

I also tried ./omxplayer file1.mp4 file1.mp4, it plays the file 1 time and exits, same as above.

I could not get the command to take the -L option. Unless it was -l which is something else I suppose according to the documentation (start position, etc...)

What am I doing wrong? Any help would be greatly appreciated. Thanks

scollins15 avatar May 23 '13 19:05 scollins15

Hi! If you also have system-wide omxplayer installed, ./omxplayer wrapper script will execute that instead. You can either edit the script to remove /usr/bin/omxplayer.bin detection, or uninstall omxplayer system-wide. If that's not your case, I'm at a loss. :)

pasky avatar May 23 '13 20:05 pasky

thanks @pasky, I did edit the script, now the loop function command is accepted.

The issue now is... I enter ./omxplayer -L file1.mp4 file2.mp4 at command line

it returns thread nextreader 0x1821430 (0) file : file1.mp4 result 1 format mov,mp4,m4a,3gp,3g2,mj2 audio streams 0 video s thread opened 0x1821430 (0) openok 1 Video codec omx-h264 width 1280 height 720 profile 100 fps 23.976025 Subtitle count: 0, state: off, index: 1, delay: 0 thread nextreader 0x1d62c10 (0) file : file2.mp4 result 1 format mov,mp4,m4a,3gp,3g2,mj2 audio streams 0 video s thread opened 0x1d62c10 (0) openok 1

meanwhile the file1.mp4 plays, but file2.mp4 never plays and it freezes. I have to end process to exit. Any suggestions. This appears to the issue that was happening from your February patch, i downloaded the patch from April. If anyone has suggestions i would greatly appreciate them. Thanks

scollins15 avatar May 24 '13 12:05 scollins15

I have just evaluated your branch. Starting with the Big Bucks Bunny h264 to a youtube MP4. The first play stutters very badly on the logo scene (also with your master branch). It stutters less with the current huceke master. I don't see any transition between the two video's at all, it hangs after the first.

skinkie avatar May 29 '13 18:05 skinkie

This might be exactly what I'm looking for. However, being quite new in the Linux environment, I'm wondering how to install the new omxplayer replacing the one I already have in my Raspberry Pi?

paolovacirca avatar Jun 28 '13 16:06 paolovacirca

Has anyone successfully compiled from source code natively on the R-Pi? I am running Raspbian and would love to be able to accomplish this.

When running make ffmpeg I get errors - unable to create the executable arm-unknown-linux-gnueabi-gcc. I do not know how to set up a cross compiler. I would need to make some changes to parameters that are output to the console for a project I am working on, but need to be able to compile. Anybody have a solution that they are able to provide? Thanks in advance.

scollins15 avatar Jul 03 '13 14:07 scollins15

I have compiled it on Arch Linux without any hassles even on 256MB Pi.

skinkie avatar Jul 03 '13 14:07 skinkie

thanks for quick respnse @skinkie

You have cross compiled on Arch Linux? Have you compiled on pi itself with Raspbian?

I may be forced to cross compile, if so there is the headache of setting that up. Do you have the steps involved in this?

Thanks

scollins15 avatar Jul 03 '13 15:07 scollins15