I want encrypt & decrypt Video file With FFMPEG oflfine mode in hard disk.
I encrypt a Video File (mp4 Extention) by ffmpeg.exe Tools by this Command:
ffmpeg -i SampleVideo_1280x720_1mb.mp4 -vcodec copy -acodec copy
-encryption_scheme cenc-aes-ctr -encryption_key
76a6c65c5ea762046bd749a2e632ccbb -encryption_kid
a7e61c373e219033c21091fa607bf3b8 SampleVideo_1280x720_1mb_encrypted.mp4
for decryption :
i want decrypt and play video file (encrypted.mp4) in my player source c++
(ffmpeg base) and *now i dont wnat use decrypt file with command line with
ffplay.exe *like this :
ffplay SampleVideo_1280x720_1mb_encrypted.mp4 -decryption_key
76a6c65c5ea762046bd749a2e632ccbb
how i can do decrypt with Write programing code that use FFMPEG api?
thanks in advance.
Related
Hello everyone For almost a whole month now I have been trying to download a file from a specific site
This is the link to the video
https://www.karaoke.co.il/api_play.php?type=clip&id=58370&autoplay=undefined&referer=karaoketv
The M3u8 files are split into 2 parts.
Video file
https://www.video-cdn.com/video/encrypt/750802ea0bc2d02fac93adeaa1398ec2/750802ea0bc2d...2-57d9518fae69
And an audio file
https://www.video-cdn.com/video/encrypt/750802ea0bc2d02fac93adeaa1398ec2/750802ea0bc2d...2-57d9518fae69
As far as I know there is a Key that needs to be entered in order to download the file.
And when I run the command in ffmpeg
I encounter many errors like:
Unable to open key file
Anyone who can download it.
I would be very happy if he would write me a code that works and explain to me how to do it
These are all the codes I have already tried
ffmpeg -decryption_key https://www.video-cdn.com/video/key/750802ea0bc2d02fac93adeaa13cde64 -i https://www.video-cdn.com/video/encrypt/750802ea0bc2d02fac93adeaa1398ec2/750802ea0bc2d02fac93adeaa1398ec2/video_720p.m3u8?token=R915dD-72351a7c-3dd1-4e58-b6c2-9cc813eeb183 -vcodec libx264 {output_file}
ffmpeg -decryption_key {key} -i {file} -max_muxing_queue_size 9999 d.mp4
ffmpeg -allowed_extensions ALL -protocol_whitelist data, file, http, https, tcp, tls, crypto -i "https://www.video-cdn.com/video/encrypt/f242d2da41d03b3955fb866efc5dbd59/f242d2da41d03b3955fb866efc5dbd59/video_720p.m3u8?token=R915dD-a1430cfc-0bda-46a0-a7e9-b15308875dc7" c copy -bsf: a aac_adtstoasc test.mp4 -decryption_key C:\ ffmpeg\enc.key
hlsdl -K "1a9625fb34a4afe0d5446138e9543563" https://www.video-cdn.com/video/encrypt/f242d2da41d03b3955fb866efc5dbd59/f242d2da41d03b3955fb866efc5dbd59/video_720p.m3u8?token=R915dD-be07b7e6-08aa-441b-afbd-5c7876409878
enter image description here
key:
base64:zPfjh0/g09EKjPIS4w37Kg==
Hex:ccf7e3874fe0d3d10a8cf212e30dfb2a
ffmpeg -decryption_key "https://www.video-cdn.com/video/key/750802ea0bc2d02fac93adeaa13cde64" -i "https://www.video-cdn.com/video/encrypt/750802ea0bc2d02fac93adeaa1398ec2/750802ea0bc2d02fac93adeaa1398ec2/video_720p.m3u8?token=R915dD-72351a7c-3dd1-4e58-b6c2-9cc813eeb183" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 file.mp4
I have configured RTMP to work with Nginx on ubuntu server following the guide from https://www.youtube.com/watch?v=Js1OlvRNsdI
I have tested the setup and everything is working perfectly to the end but then I have a folder containing movies and I want them to be streamed or played independently via a web player, for example, JWPlayer and I have failed to get that implementation online. Is there anyone with an idea of how to go about it?
Do you get a folder contains a set of movies, and you want to stream them as a stream, or each file as a stream?
Whatever you could do this by FFmpeg:
for file in $(ls movies/*.mp4); do
ffmpeg -re -i $file -c copy -f flv rtmp://server/app/stream
done
If want to stream each file as a stream, try to start multiple ffmpeg to do this.
I use nginx and ffmpeg to restream video from my provider. Previously I use ffmpeg with arguments where I reencoding video and reencoding audio, because my server is to slow I resigned from reencoding.
So now, I use that command :
ffmpeg -re -i http://link.somelink.com:6565/21d12d1/17233 -map 0 -c copy -bsf:a aac_adtstoasc -f flv -flvflags no_duration_filesize rtmp://test_ip/canal/stream
This works only when my provider streaming with aac audio codec, but sometimes my provider change audio codec to ac3. And then this doesn't work. I try something like this :
ffmpeg -thread_queue_size 32768 -re -i http://link.somelink.com:6565/21d12d1/17233 -c:v copy -c:a aac -f flv -flvflags no_duration_filesize rtmp://test_ip/canal/stream
And it all looks like it's all right in console with ffmpeg, but my restreaming video doesn't work. Ngnix throws 304 exception sometime.
Any suggestions?
Please help,
It's very important for me...
Ac3 is not in supported codecs list. You should encode your stream accordingly.
RTMP supports only a limited number of codecs. The most popular RTMP video codecs are H264, Sorenson-H263 (aka flv) and audio codecs AAC, MP3, Nellymoser, Speex. If your video is encoded with these codecs (the most common pair is H264/AAC) then you do not need any conversion. Otherwise you need to convert video to one of supported codecs.
https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp
I'm trying to use the example here for Clearkey encryption for videos. As per the steps mentioned here I was able to download and build the encryption tool wemb_crypt but When I try to encrypt the file with
webm_crypt -i input.webm -o input-enc_bear1_0123456789012345.webm -video true -audio true -video_options content_id=0123456789012345,base_file=bear1.key -audio_options content_id=0123456789012345,base_file=bear1.key
I get this error
File: input.webm is not WebM file.Could not open WebM files.
Tried many different webm files with no luck.
Is there another way to encrypt clear key media with other tools? Any clue about the error above?
You can use ffmpeg and openssl to create an AES encrypted HLS stream - the ffmpeg documentation (http://ffmpeg.org/ffmpeg-all.html#Options-34) includes this example script:
#!/bin/sh
BASE_URL=${1:-'.'}
openssl rand 16 > file.key
echo $BASE_URL/file.key > file.keyinfo
echo file.key >> file.keyinfo
echo $(openssl rand -hex 16) >> file.keyinfo
ffmpeg -f lavfi -re -i testsrc -c:v h264 -hls_flags delete_segments \
-hls_key_info_file file.keyinfo out.m3u8
You can also use mp4Box (https://gpac.wp.imt.fr/mp4box/encryption/common-encryption/) to create basic clear DASH encryptions:
MP4Box -crypt drm_file.xml movie.mp4 -out movie_encrypted.mp4
The drm info is included in the drm_file.xml and is explained at the link above.
I am doing a project with encrypting
video and I have a few questions for the procedure.
I used a command to transcode mp4 to HLS with a ts segment duration of ~10 seconds.
First, I need to encrypt those videos with a key from database. However,
I have no idea for the encryption whether working with ffmpeg or not.
Second, if the encryption can work without ffmpeg, so what should I do? I have searched in google which includes something like openssl / aes but
there is no a detailed step for me to follow, even the ffmpeg link:
http://www.ffmpeg.org/ffmpeg-all.html#srtp
Could anyone give me a hand, teaching me how to encrypt a video? Thanks to you.
Yes, you can do it with ffmpeg. You need to write the key from the database to a file, let's say video.key.
You need a second file, let's name it key_info which is the key info file. It has the following format:
key URI
key file path
IV (optional)
Eg:
http://example.com/video.key
video.key
You tell ffmpeg to use it to encrypt your segments with the hls_key_info argument:
ffmpeg -i input.mp4 -c copy -bsf:v h264_mp4toannexb -hls_time 10 -hls_key_info_file key_info playlist.m3u8
This will encrypt your segments with AES-128 in CBC mode and add the relevant tags to your playlist:
#EXT-X-KEY:METHOD=AES-128,URI="http://example.com/video.key"
You can also manually encrypt the segments if you want with openssl. Here's an example script, where each IV is equal to the segment index:
#!/bin/bash
ts_dir=/path/to/ts/
key_file=video.key
openssl rand 16 > $key_file
enc_key=$(hexdump -v -e '16/1 "%02x"' $key_file)
pushd $ts_dir
ts_cnt=$(ls *.ts | wc -l)
((ts_cnt--))
i=0
for i in $(seq -f "%01g" 0 $ts_cnt); do
iv=$(printf '%032x' $i)
ts_file=segment-$i.ts
echo [$i] $ts_file
openssl aes-128-cbc -e -in $ts_file -out encrypted_${ts_file} -nosalt -iv $iv -K $enc_key
done
popd