eluv-io / elv-client-js

Eluvio JavaScript Client
MIT License
9 stars 12 forks source link

Download media object #296

Closed elv-preethi closed 3 months ago

elv-preethi commented 3 months ago

The script OfferingDownloadMedia performs the following:

Steps:

5 directories, 15 files


For instance, for `english_stereo` streamKey:
`english_stereo` folder => contains all the parts that fall within the start and end times.
`english_stereo.mp4` => the concatenated file
`english_stereo_trimeed.mp4` => this file has been both concatenated and trimmed to the specified time range.

### Command usage:

node ./testScripts/OfferingDownloadMedia --help Options: --help Show help [boolean] --debug Print debug logging for API calls [boolean] --configUrl, --config-url URL pointing to the Fabric configuration, enclosed in quotes. e.g. for Eluvio demo network: --configUrl "https://demov3.net955210.contentfabric.io/config" [string] --elvGeo, --elv-geo Geographic region for the fabric nodes. [string] [choices: "as-east", "au-east", "eu-east", "eu-west", "na-east", "na-west-north", "na-west-south"] --objectId, --object-id Object ID (should start with 'iq') [string] --versionHash, --version-hash Object Version Hash (should start with 'hq') [string] --offeringKey offering key [string] [default: "default"] --streamKey comma separated list of offerings stream key [string] [default: "video"] --startTime start time to retrieve parts in seconds [number] [required] --endTime end time to retrieve parts in seconds [number] [required] --out output directory

eponymous301 commented 3 months ago

For consistency with other scripts I recommend renaming objectHash to versionHash and offeringType to offeringKey

Note also that rather than using TestConfiguration.json to set demov3 network you should be able to use --configUrl https://demov3.net955210.contentfabric.io/config in command line, or alternate option is to set env var FABRIC_CONFIG_URL=https://demov3.net955210.contentfabric.io/config

elv-preethi commented 3 months ago

Looks good overall, I made some suggestions, the only ones that I feel strongly about are:

  • add a --streamKey argument (optionally defaulting to "video")
  • change --objectVersion to --versionHash and --offeringType to --offeringKey for consistency with other scripts
  • use default: ... in option() declarations instead of setting the value via || (this will make the default values show up automatically in help output when user is missing an option or specifies --help)

I also suggest renaming ObjectDownloadMedia.js to OfferingDownloadMedia.js to reflect the fact that it targets a single mez offering.

Thanks for reviewing. Made the changes as per comment. Also, changed the code to append all parts to single file and runs the ffmpeg at the end to concat all the parts and generate single mp4 file.

out_dir
├── parts_video.txt
├── video
│   ├── hqpe2NC2ojcbkPLrEbEKfFFSqroeST8Y2wgrJWRWtP61Lg7TfZ7nRT.mp4
│   └── hqpeKzJ5bBqKr38dEdNsX16epCwnqmwm5acnRcL13PvQkZhCnR9si.mp4
└── video.mp4
elv-preethi commented 3 months ago

@elv-serban When attempting to trim a video, I have observed that if the duration is 19.7s, it is rounded down to 19s on my system, instead of rounding to 20s. However, the ffmpeg @eponymous301 is using rounds the duration up to 20s. I am not sure how to fix this. @elv-haoyu, could you please try the script when you have a moment?

The ./out/video.mp4 has the untrimmed version comprising of all parts within duration and ./out/video_hh-mm-ss.ms_hh-mm-ss.ms.mp4 has the trimmed version.

elv-preethi commented 3 months ago

As per @elv-haoyu requests, Made following changes:

2. streamKey == "audio":

└── iq__2BbhsB7V3DBVoSYmhszCeUBBVzpY_00-00-10.500_00-00-43.500 ├── audio │   ├── 0001.hqpeDgq3121TLyBFf2NHiuv4kSvPbGiANyG1vGeN2cBxoo1J7oAu.mp4 │   └── 0002.hqpe4Yt7TBcceK1dau35nVWkbwDXBm8WNxXPwczKtXkRJ2xSP6Fx.mp4 ├── audio.mp4 ├── out_00-00-10.500_00-00-43.500.mp4 └── parts_audio.txt

3. streamKey == "video":

└── iq__2BbhsB7V3DBVoSYmhszCeUBBVzpY_00-00-10.500_00-00-43.500 ├── out_00-00-10.500_00-00-43.500.mp4 ├── parts_video.txt ├── video │   ├── 0001.hqpeKzJ5bBqKr38dEdNsX16epCwnqmwm5acnRcL13PvQkZhCnR9si.mp4 │   └── 0002.hqpe2NC2ojcbkPLrEbEKfFFSqroeST8Y2wgrJWRWtP61Lg7TfZ7nRT.mp4 └── video.mp4


* By default, if `steamKey` is not provided. Both audio and video files will be downloaded, concatenated and trimmed. 
* Final trimmed output is at `out_start-time_end-time.mp4`.
elv-preethi commented 3 months ago

@elv-haoyu @eponymous301 @elv-serban made the changes as discussed. The details are here. Also, @elv-haoyu all of the trimmed files will be under iq_XXX_start-time_end-time/trimmed folder.