Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moov atom placement for x264/mp4 #283

Closed
gnanet opened this issue Dec 30, 2016 · 14 comments
Closed

moov atom placement for x264/mp4 #283

gnanet opened this issue Dec 30, 2016 · 14 comments

Comments

@gnanet
Copy link

gnanet commented Dec 30, 2016

Since Motion-Project is capable of producing x264 / mp4 video i thought i would not need to transcode videos for playback in a web based event viewer i created.

BUT the produced mp4 does not have the moov atom right after ftyp atom:

# AtomicParsley 01-20161230235957.mp4 -T
Atom ftyp @ 0 of size: 32, ends @ 32
Atom free @ 32 of size: 8, ends @ 40
Atom mdat @ 40 of size: 930671, ends @ 930711
Atom moov @ 930711 of size: 2429, ends @ 933140

This way the video still has to be completely loaded in browser before playback can start.

Is it possible to change the encoder parameters to allow instant playback for x264/mp4 ?

@tosiara
Copy link
Member

tosiara commented Jan 2, 2017

I cannot compile "AtomicParsley". Is there an alternative command to get similar output?

@gnanet
Copy link
Author

gnanet commented Jan 2, 2017

I have looked here for solutions:
http://muzso.hu/2012/11/14/tools-to-fix-mp4-videos-so-players-can-start-playback-instantly-without-downloading-the-w

One python based tool:
https://github.com/danielgtaylor/qtfaststart

@gnanet
Copy link
Author

gnanet commented Jan 2, 2017

Some background information about the subject: http://www.adobe.com/devnet/video/articles/mp4_movie_atom.html

@Mr-Dave
Copy link
Member

Mr-Dave commented Jan 2, 2017

I did look into this and it does not look like we'll be able to do this. Motion uses ffmpeg in order to handle the encoding of the videos. While it is possible to move the atom with ffmpeg, it does not appear that the required libraries are part of the standard implementations. Meaning, it would need a custom ffmpeg build which would break other things. The particular component is within the movenc.h file which is not in the distributed libavformat-devl packages from apt. The alternative would be to use the mkv container which defaults to having the atom at the start and therefore can be started immediately.

@gnanet
Copy link
Author

gnanet commented Jan 2, 2017

Oh, slowly i understand why this will be not easy, or not in scope of the project itself:

  1. To place moov to the beginning, there is a second pass needed (taken from ffmpeg docs about movflags faststart)
  2. Even if this second pass would be triggered, something like this has to be coded using the libffmpeg
  3. the second pass could use a lot of time that would harm the main goal of storing the captured video

I think the solution for this could be an example script, that can be provided to the on_movie_end option for relocating the moov atom

I will have to create the example script.

Please only close this issue, if i am not able to provide the example script within 14 days.

Thank you.

@tosiara
Copy link
Member

tosiara commented Jan 9, 2017

@gnanet can you please investigate the following files using AtomicParsley? Which of them (if any) has correct "moov"?
https://dl.dropboxusercontent.com/u/1350713/01-20170109154258-ffmpeg.mp4
https://dl.dropboxusercontent.com/u/1350713/01-20170109154514-x264.mp4
Files have been created using extpipe
Thanks

@gnanet
Copy link
Author

gnanet commented Jan 10, 2017

AtomicParsley 01-20170109154514-x264.mp4 -T
Atom ftyp @ 0 of size: 24, ends @ 24
Atom mdat @ 24 of size: 29587573, ends @ 29587597
Atom free @ 29587597 of size: 96, ends @ 29587693
Atom moov @ 29587693 of size: 2005, ends @ 29589698

AtomicParsley 01-20170109154258-ffmpeg.mp4 -T
Atom ftyp @ 0 of size: 32, ends @ 32
Atom free @ 32 of size: 8, ends @ 40
Atom mdat @ 40 of size: 29508720, ends @ 29508760
Atom moov @ 29508760 of size: 2208, ends @ 29510968

Beacuse of the need for a second pass, i think the best solution will be anyway an on_movie_end script

@tosiara
Copy link
Member

tosiara commented Jan 11, 2017

Does it mean that my provided videos also require full download prior to play in browser?

@tosiara
Copy link
Member

tosiara commented Jan 11, 2017

I have checked with Firefox and Chrome - video starts playing in a second, while the entire movie buffers in about 15 seconds. So I'm not sure why your browser requires full download before playing

motion-mp4

@gnanet
Copy link
Author

gnanet commented Jan 12, 2017

Does it maybe the NGINX of dropbox create the "206 partial content" that enables seamless pre loading ?

@tosiara
Copy link
Member

tosiara commented Jan 13, 2017

Tested on a default installation of Apache - same sequence of requests, file plays in a seconds

@gnanet
Copy link
Author

gnanet commented Jan 13, 2017

that's good to read. what commandline was used with extpipe ?

@tosiara
Copy link
Member

tosiara commented Jan 14, 2017

I used an example from the default config:
https://github.com/Motion-Project/motion/blob/master/motion-dist.conf.in#L363

@Mr-Dave
Copy link
Member

Mr-Dave commented Jan 28, 2017

Closing per previous comments on timeline. If a method is found via a external script or the extpipe, trying finding a spot for it within the motion_guide.html. We can then see about doing a PR for the change to the guide to show others how to do it.

@Mr-Dave Mr-Dave closed this as completed Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants