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

how to transcode fragments? #12

Closed
nickdesaulniers opened this issue Jun 10, 2015 · 6 comments
Closed

how to transcode fragments? #12

nickdesaulniers opened this issue Jun 10, 2015 · 6 comments

Comments

@nickdesaulniers
Copy link
Contributor

So I was able to successfully try out a fragmented mp4 with 2 DASH clients. I produced the fragmented and segmented mp4 with mp4fragment and mp4-dash.py. This produced numerous .m4f files. For the adaptive part of adaptive bitrate streaming, I was wondering if there were any built in tools for performing the transcoding? Should the original source be transcoded into multiple transcodings first, then segmented, or segmented into multiple files then each transcoded? I'm more than happy to use ffmpeg, but I was just curious what the suggestion was.

@barbibulle
Copy link
Contributor

The typical encoding workflow is to configure an encoder/transcoder to produce one file per bitrate, in a way that guarantees the alignment of GOPs (Group Of Picture), so that a valid, aligned, set of DASH segments can be made. Some encoders can produce files that are already in fragmented-mp4 form, but some don't (in which case mp4fragment is used to fragment the encoder output).
It isn't always easy to constrain encoders/transcoders to produce outputs with fixed GOP sizes (encoders try to be smart, with features like automatic scene-cut detection, etc.), but it is necessary. Some encoders are sophisticated enough to know about multi-bitrate encoding right from the start, which is more efficient than doing multiple single-bitrate encodings.
The simple utility mp4-dash-encode.py included in the Bento4 distribution shows how this can be done with ffmpeg (both for h.264 and hevc).

@nickdesaulniers
Copy link
Contributor Author

when I run that tool, I get an error:

➜  builds git:(master) ✗ py ../Source/Python/utils/mp4-dash-encode.py -b 5 frag_bunny.mp4
ERROR: binary tool failed with error 1

I get the feeling that this has to do with me not installing the binary tools, or having them in my path. Or not having the option for --exec-dir=. like with Source/Python/utils/mp4-dash.py.

Anyways, I'm giving a talk next week on MSE that will be live streamed from air.mozilla.org, and I plan on plugging these great FOSS tools! https://air.mozilla.org/tech-talk-3/

@barbibulle
Copy link
Contributor

mp4-dash-encode.py needs to run ffmpeg, so you'll need that to be in your path.
You can see a detailed report on that the 'binary tool error' is exactly here by running the tool with the '-v -d' options (verbose and debug).
That tools hasn't received a lot of testing, it is something that I use myself regularly, but I always have the same settings/patterns, so there are probably a lot of unexplored combinations.

@nickdesaulniers
Copy link
Contributor Author

Data stream encoding not supported yet (only streamcopy)
https://pastebin.mozilla.org/8836681

ffmpeg and ffprobe are in my path. both are version 2.6.3.

hmm, I have libfdk_aac:

➜  builds git:(master) ✗ ffmpeg -codecs 2>/dev/null| grep aac
 DEA.L. aac                  AAC (Advanced Audio Coding) (decoders: aac libfdk_aac ) (encoders: aac libfdk_aac libvo_aacenc )
 D.A.L. aac_latm             AAC LATM (Advanced Audio Coding LATM syntax)

@nickdesaulniers
Copy link
Contributor Author

Looks like I have to play around with muxing. I was able to edit the first command that ran to:

➜  builds git:(master) ✗ ffmpeg -i "bunny.mp4" -strict experimental -codec:a libfdk_aac -ac 2 -ab 128k -preset slow -map_metadata -1 -codec:v libx264 -profile:v baseline -force_key_frames 'expr:eq(mod(n,72),0)' -bufsize 500k -maxrate 750k -x264opts rc-lookahead=72 -s 256x144 -f mp4 video_00500.mp4_ -map 0:0 -map 0:1

which worked. Ah, if I strip out the two unsupported streams:

➜  builds git:(master) ✗ ffmpeg -i bunny.mp4 -map 0:0 -map 0:1 -c copy bunny_clean.mp4
➜  builds git:(master) ✗ py ../Source/Python/utils/mp4-dash-encode.py -b 5 bunny_clean.mp4
➜  builds git:(master) ✗ py ../Source/Python/utils/mp4-dash-encode.py -b 5 bunny_clean.mp4
/bin/sh: mp4fragment: command not found
ERROR: binary tool failed with error 127
➜  builds git:(master) ✗ PATH=$PATH:. py ../Source/Python/utils/mp4-dash-encode.py -b 5 bunny_clean.mp4

ahoy mateys, were in business!

@barbibulle
Copy link
Contributor

the --select-streams option of mp4-dash-encode.py should allow you to ignore the data streams in your input video.
(I also forgot to mention that mp4fragment needs to be in your path, as the encoding script will fragment the video files after encoding)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants